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

@ -507,10 +507,7 @@
})
],
IfBlock: [
o('IF INDENT GuardBlock OUTDENT', function() {
$3.type = $1;
return $3;
}), o('IF Expression Block', function() {
o('IF Expression Block', function() {
return new If($2, $3, {
type: $1
});
@ -518,6 +515,13 @@
return $1.addElse(new If($4, $5, {
type: $3
}));
}), o('IF INDENT GuardBlock OUTDENT', function() {
$3.type = $1;
return $3;
}), o('IF INDENT GuardBlock ELSE Block OUTDENT', function() {
$3.type = $1;
$3.addElse($5);
return $3;
})
],
GuardBlock: [
@ -525,8 +529,6 @@
return new If($1, $2);
}), o('GuardBlock TERMINATOR Expression Block', function() {
return $1.addElse(new If($3, $4));
}), o('GuardBlock ELSE Block', function() {
return $1.addElse($3);
})
],
If: [

File diff suppressed because one or more lines are too long

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