summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorGravatar Rustan Leino <unknown>2014-08-19 23:52:30 -0700
committerGravatar Rustan Leino <unknown>2014-08-19 23:52:30 -0700
commitbc5ba2bcd7fb7de092898100e08edecf9f0a00e1 (patch)
tree4e1991ffcb18e0f95d3ea4a0bbf1cf5a155c0247 /Source
parentfeedce5021404af3f08dfc23944196d2ad8ed7fc (diff)
parent3b51d9251d78bd3de763c951102677eecd764984 (diff)
Merge
Diffstat (limited to 'Source')
-rw-r--r--Source/Dafny/Dafny.atg23
-rw-r--r--Source/Dafny/Parser.cs23
2 files changed, 28 insertions, 18 deletions
diff --git a/Source/Dafny/Dafny.atg b/Source/Dafny/Dafny.atg
index 711fadf0..1d282d67 100644
--- a/Source/Dafny/Dafny.atg
+++ b/Source/Dafny/Dafny.atg
@@ -120,6 +120,17 @@ bool IsParenStar() {
return la.kind == _openparen && x.kind == _star;
}
+string UnwildIdent(string x, bool allowWildcardId) {
+ if (x.StartsWith("_")) {
+ if (allowWildcardId && x.Length == 1) {
+ return "_v" + anonymousIds++;
+ } else {
+ SemErr("cannot declare identifier beginning with underscore");
+ }
+ }
+ return x;
+}
+
bool IsLambda(bool allowLambda)
{
return allowLambda &&
@@ -2032,7 +2043,7 @@ ParensExpression<out Expression e, bool allowSemi, bool allowLambda>
if (ise.Arguments != null) {
SemErr(ise.OpenParen, "Expected variable binding.");
}
- bvs.Add(new BoundVar(id, id.val, tt ?? new InferredTypeProxy()));
+ bvs.Add(new BoundVar(id, UnwildIdent(id.val, true), tt ?? new InferredTypeProxy()));
} else {
SemErr(ee.tok, "Expected variable binding.");
}
@@ -2308,7 +2319,7 @@ DottedIdentifiersAndFunction<out Expression e, bool allowSemi, bool allowLambda>
if (args != null) {
SemErr(openParen, "Expected variable binding.");
}
- BoundVar bv = new BoundVar(id, id.val, new InferredTypeProxy());
+ BoundVar bv = new BoundVar(id, UnwildIdent(id.val, true), new InferredTypeProxy());
e = new LambdaExpr(id, oneShot, new List<BoundVar>{ bv }, req, reads, body);
.)
]
@@ -2576,13 +2587,7 @@ NoUSIdent<out IToken/*!*/ x>
WildIdent<out IToken/*!*/ x, bool allowWildcardId>
= (. Contract.Ensures(Contract.ValueAtReturn(out x) != null); .)
ident (. x = t;
- if (x.val.StartsWith("_")) {
- if (allowWildcardId && x.val.Length == 1) {
- t.val = "_v" + anonymousIds++;
- } else {
- SemErr("cannot declare identifier beginning with underscore");
- }
- }
+ t.val = UnwildIdent(x.val, allowWildcardId);
.)
.
diff --git a/Source/Dafny/Parser.cs b/Source/Dafny/Parser.cs
index 740a7189..bd4b7a16 100644
--- a/Source/Dafny/Parser.cs
+++ b/Source/Dafny/Parser.cs
@@ -151,6 +151,17 @@ bool IsParenStar() {
return la.kind == _openparen && x.kind == _star;
}
+string UnwildIdent(string x, bool allowWildcardId) {
+ if (x.StartsWith("_")) {
+ if (allowWildcardId && x.Length == 1) {
+ return "_v" + anonymousIds++;
+ } else {
+ SemErr("cannot declare identifier beginning with underscore");
+ }
+ }
+ return x;
+}
+
bool IsLambda(bool allowLambda)
{
return allowLambda &&
@@ -1126,13 +1137,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
Contract.Ensures(Contract.ValueAtReturn(out x) != null);
Expect(1);
x = t;
- if (x.val.StartsWith("_")) {
- if (allowWildcardId && x.val.Length == 1) {
- t.val = "_v" + anonymousIds++;
- } else {
- SemErr("cannot declare identifier beginning with underscore");
- }
- }
+ t.val = UnwildIdent(x.val, allowWildcardId);
}
@@ -3229,7 +3234,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (args != null) {
SemErr(openParen, "Expected variable binding.");
}
- BoundVar bv = new BoundVar(id, id.val, new InferredTypeProxy());
+ BoundVar bv = new BoundVar(id, UnwildIdent(id.val, true), new InferredTypeProxy());
e = new LambdaExpr(id, oneShot, new List<BoundVar>{ bv }, req, reads, body);
}
@@ -3633,7 +3638,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (ise.Arguments != null) {
SemErr(ise.OpenParen, "Expected variable binding.");
}
- bvs.Add(new BoundVar(id, id.val, tt ?? new InferredTypeProxy()));
+ bvs.Add(new BoundVar(id, UnwildIdent(id.val, true), tt ?? new InferredTypeProxy()));
} else {
SemErr(ee.tok, "Expected variable binding.");
}