Ticket #34: var-is-ambig-wkround.patch

File var-is-ambig-wkround.patch, 4.3 kB (added by hopscc, 3 months ago)
  • Source/CobraParser.cobra

     
    681681                Example source: 
    682682                        # The | below is not literal--it's where this method starts parsing. 
    683683                        def compute 
    684                                 |is virtual, protected 
     684                                |{is,isdecl} virtual, protected 
    685685                Example return values: 
    686686                        [] 
    687687                        ['shared'] 
     
    693693                if _validIsNames is nil 
    694694                        _validIsNames = ['fake', 'shared', 'virtual', 'nonvirtual', 'override', 'new', 'public', 'protected', 'private', 'internal', 'abstract', 'partial'] 
    695695                names = List<of String>(_isNamesStack) 
    696                 if .optional('IS') is nil 
     696                if .optional('IS', 'ISDECL') is nil 
    697697                        return names 
    698698                while true 
    699699                        what = .grab.text 
     
    11521152                                type = .typeProvider.defaultType 
    11531153                docString = '' to ? 
    11541154                isNames = List<of String>(_isNamesStack) 
    1155                 if .peek.which=='IS' 
     1155                if .peek.which=='IS' or .peek.which=='ISDECL' 
    11561156                        isNames = .isDeclNames 
    11571157                        attribs = .hasAttribs 
    11581158                        assert .last.which=='EOL' 
  • Source/KeywordSpecs.cobra

     
    9292                                'body        | declarative: Declare the body of a method, indexer or property after blocked contracts or unit tests.', 
    9393                                'test        | declarative: Declare a unit test attached to the containing declaration.', 
    9494                                '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`.', 
    9697                                'event       | declarative: Declare an event.', 
    9798                                'of          | declarative: Specify the underlying type of an enumeration. Also, specify type arguments to a generic type.', 
    9899                                '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>] 
     4class 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...) 
     5class 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