Change annotations parsing in bodies of operators

This change only matters in cases of if/when/for/while having braceless
blocks

Annotations on them are parsed now as on block-level expressions, i.e.
they're attached to the whole expression
This commit is contained in:
Denis Zharkov
2016-10-06 16:05:38 +03:00
parent c01b4156d8
commit 9ff439e39e
7 changed files with 315 additions and 32 deletions
+9 -4
View File
@@ -4,8 +4,13 @@
See [Control structures](control-flow.html)
*/
controlStructureBody
: block
: blockLevelExpression
;
if
: "if" "(" expression ")" expression SEMI? ("else" expression)?
: "if" "(" expression ")" controlStructureBody SEMI? ("else" controlStructureBody)?
;
try
@@ -27,13 +32,13 @@ loop
;
for
: "for" "(" annotations (multipleVariableDeclarations | variableDeclarationEntry) "in" expression ")" expression
: "for" "(" annotations (multipleVariableDeclarations | variableDeclarationEntry) "in" expression ")" controlStructureBody
;
while
: "while" "(" expression ")" expression
: "while" "(" expression ")" controlStructureBody
;
doWhile
: "do" expression "while" "(" expression ")"
: "do" controlStructureBody "while" "(" expression ")"
;
+4
View File
@@ -172,6 +172,10 @@ declaration
statement
: declaration
: blockLevelExpression
;
blockLevelExpression
: annotations expression
;
+3 -3
View File
@@ -12,12 +12,12 @@ when
// TODO : consider empty after ->
whenEntry
: whenCondition{","} "->" expression SEMI
: "else" "->" expression SEMI
: whenCondition{","} "->" controlStructureBody SEMI
: "else" "->" controlStructureBody SEMI
;
whenCondition
: expression
: ("in" | "!in") expression
: ("is" | "!is") isRHS
;
;