mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-19 10:29:30 +01:00
CGrammar: Improve switch/case/break/label
This commit is contained in:
parent
c2b4d5cb19
commit
392cbfb5d1
@ -13,7 +13,7 @@ use warnings;
|
|||||||
# These are set automatically by the build/commit script
|
# These are set automatically by the build/commit script
|
||||||
use constant {
|
use constant {
|
||||||
BUILD_NAME => "PBot",
|
BUILD_NAME => "PBot",
|
||||||
BUILD_REVISION => 637,
|
BUILD_REVISION => 638,
|
||||||
BUILD_DATE => "2014-06-14",
|
BUILD_DATE => "2014-06-14",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ compound_statement:
|
|||||||
$return .= "End block.\n" if not $arg{context};
|
$return .= "End block.\n" if not $arg{context};
|
||||||
|
|
||||||
if ($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;
|
1;
|
||||||
}
|
}
|
||||||
@ -339,14 +339,22 @@ selection_statement:
|
|||||||
)(?)
|
)(?)
|
||||||
{ $return .= join('',@{$item[-1]}); }
|
{ $return .= join('',@{$item[-1]}); }
|
||||||
| 'switch' '(' expression ')' statement[context => 'switch']
|
| '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:
|
jump_statement:
|
||||||
<skip:'\s*'> 'break' ';'
|
'break' ';'
|
||||||
{ $return = "Break from the current block.\n"; }
|
{
|
||||||
|
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' ';'
|
| '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'](?) ';'
|
| 'return' <commit> expression[context => 'return'](?) ';'
|
||||||
{
|
{
|
||||||
my $item_expression = join('', @{$item{'expression(?)'}});
|
my $item_expression = join('', @{$item{'expression(?)'}});
|
||||||
@ -378,11 +386,11 @@ expression_statement:
|
|||||||
|
|
||||||
labeled_statement:
|
labeled_statement:
|
||||||
identifier ':' 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']
|
| '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
|
| 'default' ':' statement
|
||||||
{ $return = "In the default case, do this:\n$item{statement}"; }
|
{ $return = "In the default case, ^L$item{statement}"; }
|
||||||
|
|
||||||
expression:
|
expression:
|
||||||
<leftop: assignment_expression[context => $arg{context}] ',' assignment_expression[context => $arg{context}]>
|
<leftop: assignment_expression[context => $arg{context}] ',' assignment_expression[context => $arg{context}]>
|
||||||
|
Loading…
Reference in New Issue
Block a user