3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-23 19:22:40 +01:00

CGrammar: Improve switch/case/break/label

This commit is contained in:
Pragmatic Software 2014-06-14 18:41:55 +00:00
parent c2b4d5cb19
commit 392cbfb5d1
2 changed files with 17 additions and 9 deletions

View File

@ -13,7 +13,7 @@ use warnings;
# These are set automatically by the build/commit script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 637,
BUILD_REVISION => 638,
BUILD_DATE => "2014-06-14",
};

View File

@ -239,7 +239,7 @@ compound_statement:
$return .= "End block.\n" if not $arg{context};
if ($arg{context}) {
$return .= "End $arg{context}.\n" unless $arg{context} eq 'do loop';
$return .= "End $arg{context}.\n" unless $arg{context} eq 'do loop' or $arg{context} eq 'case';
}
1;
}
@ -339,14 +339,22 @@ selection_statement:
)(?)
{ $return .= join('',@{$item[-1]}); }
| 'switch' '(' expression ')' statement[context => 'switch']
{ $return = "This section is controlled by a switch based on the expression \'$item{expression}\':\n$item{statement}"; }
{ $return = "Given the expression \'$item{expression}\',\n^L$item{statement}"; }
jump_statement:
<skip:'\s*'> 'break' ';'
{ $return = "Break from the current block.\n"; }
'break' ';'
{
if($arg{context} eq 'switch' or $arg{context} eq 'case') {
$return = "Break case.\n";
} elsif(length $arg{context}) {
$return = "Break from the $arg{context}.\n";
} else {
$return = "Break from the current block.\n";
}
}
| 'continue' ';'
{ $return = "Return to the top of the current loop and continue it.\n"; }
{ $return = "Return to the top of the current loop.\n"; }
| 'return' <commit> expression[context => 'return'](?) ';'
{
my $item_expression = join('', @{$item{'expression(?)'}});
@ -378,11 +386,11 @@ expression_statement:
labeled_statement:
identifier ':' statement
{ $return = "The following statement is preceded by the label $item{identifier}.\n$item{statement}"; }
{ $return = "Let there be a label $item{identifier}.\n$item{statement}"; }
| 'case' constant_expression ':' statement[context => 'case']
{ $return = "In the case it has the value $item{constant_expression}, do this:\n$item{statement}"; }
{ $return = "When it has the value $item{constant_expression}, ^L$item{statement}"; }
| 'default' ':' statement
{ $return = "In the default case, do this:\n$item{statement}"; }
{ $return = "In the default case, ^L$item{statement}"; }
expression:
<leftop: assignment_expression[context => $arg{context}] ',' assignment_expression[context => $arg{context}]>