Ticket #34: var-assign-is-has-augmented.patch
File var-assign-is-has-augmented.patch, 4.2 KB (added by hopscc, 11 years ago) |
---|
-
Source/CobraParser.cobra
1313 1313 peek = .peek 1314 1314 if peek.isEOF, .throwError('Unexpected end of source.') 1315 1315 1316 branch peek.which 1316 branch peek.which # oneliner: order here must have HAS/IS before ASSIGN 1317 1317 on 'ASSIGN' 1318 1318 .grab 1319 initExpr = .expression to ? 1319 try 1320 initExpr = .expression to ? 1321 catch pe as ParserException 1322 if pe.message.contains('is a reserved keyword') and .last(1).which == 'IS' 1323 .ungrab 1324 .ungrab # backup to 'is' keyword so next loop cycle throws error below 1325 else, throw pe 1320 1326 didAssign = true 1321 1327 on 'HAS' 1322 1328 lineNumHas = peek.lineNum … … 1332 1338 # .hasAttribs and .isDeclNames consume the EOL but we need it for later 1333 1339 .ungrab 1334 1340 done = true 1335 1336 1341 if .optionalIndent 1337 while .peek.which in ['IS', 'HAS' ]1342 while .peek.which in ['IS', 'HAS', 'ASSIGN'] 1338 1343 if .peek.which == 'IS' 1339 if lineNumIs > 0, .throwError(.grab, '"is" modifiers were already specified earlier on line [lineNumIs] for the field declaration: [name]')1344 if lineNumIs, .throwError(.grab, '"is" modifiers were already specified earlier on line [lineNumIs] for the field declaration: [name]') 1340 1345 isNames = .isDeclNames 1341 1346 if .peek.which == 'HAS' 1342 if lineNumHas > 0, .throwError(.grab, '"has" attributes were already specified earlier on line [lineNumHas] for the field declaration: [name]')1347 if lineNumHas, .throwError(.grab, '"has" attributes were already specified earlier on line [lineNumHas] for the field declaration: [name]') 1343 1348 attribs = .hasAttribs 1349 if .peek.which == 'ASSIGN' 1350 if didAssign, .throwError(.grab, 'initialiser expression was already specified earlier for the field declaration: [name]') 1351 .grab 1352 initExpr = .expression to ? 1353 .expect('EOL') 1344 1354 docString = .docString 1345 1355 .dedent 1346 1356 -
Tests/120-classes/228-fields-init-before-is-clause.cobra
1 # .error. "is" keyword and modifiers 2 # Trap error from ticket34: 3 # old bug in using isnames and initialAssign on field decl (var) in wrong order 4 # isclause must precede any initialiser clause 5 class FieldIsNameAssign 6 7 var myValBroke = "now not broke" is shared # fail here 8 9 # orig error: Expecting an expression. "shared" is a reserved keyword that is not expected here. -
Tests/120-classes/228-fields-multiple-syntax-variants.cobra
66 66 var avar1 as int = 100 67 67 68 68 # Multiliners 69 var myValMod3 = "new Mod 3" 69 # Multiliner - isnames before assign 70 # This looks a bit funny with all the clauses used (initialExpr buried in lines) but 71 # it has the advantage of being ordered consistently with the original single line form 72 var myValMod3 73 is shared 74 has System.Obsolete('NoUse') 75 = "new Mod 3" 76 """docstr newMod3""" 77 78 var myValMod3a = "new Mod 3" 70 79 is shared 71 80 """docstrMod3""" 72 81 82 var myValMod4o #[as String] 83 is shared 84 = "new Mod 4" 85 """docstrMod4o""" 86 73 87 var myValMod4 = "new Mod 4" 74 88 is shared, readonly 75 89 has Diagnostics.DebuggerDisplay('anAttribute') … … 96 110 var myValMod5b has System.Obsolete = 5 97 111 is shared 98 112 """docString""" 99 113 114 var myValMod5c 115 is shared 116 = "new Mod 5" 117 """docString""" 118 119 # mixed form - has-clause but no is-clause - this one for use in IDE (code) 120 var myValMod5d = 6 121 has Diagnostics.DebuggerDisplayAttribute('LongForm') 122 100 123 # long form one-liners 101 124 var myValMod6 is shared has Diagnostics.DebuggerDisplayAttribute('LongForm') = 6 102 125 """docString"""