disallow multiple else blocks in if/guard syntax

This commit is contained in:
Jeremy Ashkenas
2013-03-09 15:44:45 +08:00
parent 13fae12f69
commit c53df12ec1
3 changed files with 28 additions and 22 deletions

View File

@@ -510,9 +510,10 @@ grammar =
# if-related rules are broken up along these lines in order to avoid
# ambiguity.
IfBlock: [
o 'IF INDENT GuardBlock OUTDENT', -> $3.type = $1; $3
o 'IF Expression Block', -> new If $2, $3, type: $1
o 'IfBlock ELSE IF Expression Block', -> $1.addElse new If $4, $5, type: $3
o 'IF INDENT GuardBlock OUTDENT', -> $3.type = $1; $3
o 'IF INDENT GuardBlock ELSE Block OUTDENT',-> $3.type = $1; $3.addElse $5; $3
]
# The guard-style form of *if*, where each expression serves as the truthy
@@ -520,7 +521,6 @@ grammar =
GuardBlock: [
o 'Expression Block', -> new If $1, $2
o 'GuardBlock TERMINATOR Expression Block', -> $1.addElse new If $3, $4
o 'GuardBlock ELSE Block', -> $1.addElse $3
]
# The full complement of *if* expressions, including postfix one-liner