From 4f2f785d121651c62cf0a7da7c7bcaef13ee14b4 Mon Sep 17 00:00:00 2001 From: Jason Koenig Date: Tue, 19 Jun 2012 14:35:22 -0700 Subject: Dafny: disallow declare identifiers starting with underscore (_) It is still possible to reference names containing an underscore, but it is not possible to make a variable, method, class, bound variable, type, or module name beginning with one. --- Dafny/Dafny.atg | 40 +++++++++++++++++++++++++--------------- Dafny/Parser.cs | 40 +++++++++++++++++++++++++--------------- 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/Dafny/Dafny.atg b/Dafny/Dafny.atg index 7ffdcbbc..4b76f9b4 100644 --- a/Dafny/Dafny.atg +++ b/Dafny/Dafny.atg @@ -175,7 +175,7 @@ SubModuleDecl } - Ident (. .) + NoUSIdent (. .) [ "refines" Ident ] [ "imports" Idents ] (. module = new ModuleDecl(id, id.val, isOverallModuleGhost, idRefined == null ? null : idRefined.val, theImports, attrs); parent.Dependencies.Add(module); .) @@ -209,7 +209,7 @@ ClassDecl SYNC "class" { Attribute } - Ident + NoUSIdent [ GenericParameters ] "{" (. bodyStart = t; .) { ClassMemberDecl @@ -250,7 +250,7 @@ DatatypeDecl | "codatatype" (. co = true; .) ) { Attribute } - Ident + NoUSIdent [ GenericParameters ] "=" (. bodyStart = t; .) DatatypeMemberDecl @@ -272,7 +272,7 @@ DatatypeMemberDecl<.List/*!*/ ctors.> List formals = new List(); .) { Attribute } - Ident + NoUSIdent [ FormalsOptionalIds ] (. ctors.Add(new DatatypeCtor(id, id.val, formals, attrs)); .) . @@ -297,7 +297,7 @@ ArbitraryTypeDecl .) "type" { Attribute } - Ident (. at = new ArbitraryTypeDecl(id, id.val, module, attrs); .) + NoUSIdent (. at = new ArbitraryTypeDecl(id, id.val, module, attrs); .) SYNC ";" . GIdentType @@ -311,14 +311,14 @@ GIdentType = (.Contract.Ensures(Contract.ValueAtReturn(out id) != null); Contract.Ensures(Contract.ValueAtReturn(out ty) != null);.) - Ident + NoUSIdent ":" Type . LocalIdentTypeOptional = (. IToken/*!*/ id; Type/*!*/ ty; Type optType = null; .) - Ident + NoUSIdent [ ":" Type (. optType = ty; .) ] (. var = new VarDecl(id, id.val, optType == null ? new InferredTypeProxy() : optType, isGhost); .) @@ -326,7 +326,7 @@ LocalIdentTypeOptional IdentTypeOptional = (. Contract.Ensures(Contract.ValueAtReturn(out var)!=null); IToken/*!*/ id; Type/*!*/ ty; Type optType = null; .) - Ident + NoUSIdent [ ":" Type (. optType = ty; .) ] (. var = new BoundVar(id, id.val, optType == null ? new InferredTypeProxy() : optType); .) @@ -362,8 +362,8 @@ GenericParameters<.List/*!*/ typeArgs.> = (. Contract.Requires(cce.NonNullElements(typeArgs)); IToken/*!*/ id; .) "<" - Ident (. typeArgs.Add(new TypeParameter(id, id.val)); .) - { "," Ident (. typeArgs.Add(new TypeParameter(id, id.val)); .) + NoUSIdent (. typeArgs.Add(new TypeParameter(id, id.val)); .) + { "," NoUSIdent (. typeArgs.Add(new TypeParameter(id, id.val)); .) } ">" . @@ -407,7 +407,7 @@ MethodDecl } .) { Attribute } - Ident + NoUSIdent ( [ GenericParameters ] Formals @@ -567,7 +567,7 @@ FunctionDecl (. if (mmod.IsGhost) { SemErr(t, "functions cannot be declared 'ghost' (they are ghost by default)"); } .) { Attribute } - Ident + NoUSIdent ( [ GenericParameters ] Formals @@ -584,7 +584,7 @@ FunctionDecl (. if (mmod.IsGhost) { SemErr(t, "predicates cannot be declared 'ghost' (they are ghost by default)"); } .) { Attribute } - Ident + NoUSIdent ( [ GenericParameters ] [ Formals @@ -694,10 +694,10 @@ OneStmt | MatchStmt | ParallelStmt | "label" (. x = t; .) - Ident ":" + NoUSIdent ":" OneStmt (. s.Labels = new LList