Ticket #34: var-is-ambig-wkround.patch
File var-is-ambig-wkround.patch, 4.3 KB (added by hopscc, 16 years ago) |
---|
-
Source/CobraParser.cobra
681 681 Example source: 682 682 # The | below is not literal--it's where this method starts parsing. 683 683 def compute 684 | isvirtual, protected684 |{is,isdecl} virtual, protected 685 685 Example return values: 686 686 [] 687 687 ['shared'] … … 693 693 if _validIsNames is nil 694 694 _validIsNames = ['fake', 'shared', 'virtual', 'nonvirtual', 'override', 'new', 'public', 'protected', 'private', 'internal', 'abstract', 'partial'] 695 695 names = List<of String>(_isNamesStack) 696 if .optional('IS' ) is nil696 if .optional('IS', 'ISDECL') is nil 697 697 return names 698 698 while true 699 699 what = .grab.text … … 1152 1152 type = .typeProvider.defaultType 1153 1153 docString = '' to ? 1154 1154 isNames = List<of String>(_isNamesStack) 1155 if .peek.which=='IS' 1155 if .peek.which=='IS' or .peek.which=='ISDECL' 1156 1156 isNames = .isDeclNames 1157 1157 attribs = .hasAttribs 1158 1158 assert .last.which=='EOL' -
Source/KeywordSpecs.cobra
92 92 'body | declarative: Declare the body of a method, indexer or property after blocked contracts or unit tests.', 93 93 'test | declarative: Declare a unit test attached to the containing declaration.', 94 94 'shared | declarative: Specify that a member is shared among all instances. (Called `static` in some languages.)', 95 'is | declarative: Specify modifies on a member such as `override` and `shared`.', 95 'is | declarative: synonym for isdecl for modifiers, keyword for testing item equivalence', 96 'isdecl | declarative: Specify modifiers on a member such as `private` and `shared`.', 96 97 'event | declarative: Declare an event.', 97 98 'of | declarative: Specify the underlying type of an enumeration. Also, specify type arguments to a generic type.', 98 99 'inlined (r) | declarative: ', -
Tests/400-misc-bugs/221-is-ambig-wkround.cobra
1 # test for workaround for grammar ambiguity with 'is' expression and 'is' for typing in boxVar 2 # use 'isdecl' for keyword for typing instead of 'is' 3 # grammar: var name [= <assignExpr>] [isdecl <declTypes>] 4 class VarIsNameAssign 5 var myVal0 is shared,private 6 var myVal1 = 'works' 7 var myValNotBroke = "now not broke" isdecl shared, private 8 # working synonym for 9 # var myValNotBroke = "now not broke" is shared, private 10 var xisy = 'xx' is 'yy' isdecl shared 11 var isStr = 'xx'.getType is String isdecl shared 12 13 def main is shared 14 assert not .myVal0 15 v = VarIsNameAssign() 16 assert v.myVal1 == 'works' 17 a = v 18 b = VarIsNameAssign() 19 assert a is v 20 assert .myValNotBroke == 'now not broke' 21 assert a is v 22 assert a is not b 23 assert not .xisy 24 assert .isStr -
Tests/400-misc-bugs/220-is-ambig.cobra
1 # Show broken compile for grammar ambiguity with 'is' expression and 'is' 2 # used for typing in boxVar in single line decl with both assignment and typing 3 # grammar: var name [= <assignExpr>] [is <declTypes>] 4 # ( 'is' is a keyword in expression as well as keyword for typing...) 5 class VarIsNameAssign 6 var myVal0 is shared,private 7 var myVal1 = 'works' 8 var myValBroke = "this is broke" is shared,private # .error. Expecting an expression. "shared" is a reserved keyword that is not expected here. 9 # <<- compile error here when broken 10 11 def main is shared 12 assert not .myVal0 13 v = VarIsNameAssign() 14 assert v.myVal1 == 'works' 15 a = v 16 b = VarIsNameAssign() 17 assert a is v 18 assert .myValBroke == 'this is broke' 19 assert a is v 20 assert a is not b 21