3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-24 11:42:35 +01:00

CGrammar: Fix ordering of statement vs conditional/expression due to concatenated context

This commit is contained in:
Pragmatic Software 2014-07-01 17:03:07 +00:00
parent d6c20bc051
commit 34def4f9ad
2 changed files with 56 additions and 48 deletions

View File

@ -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 => 688, BUILD_REVISION => 689,
BUILD_DATE => "2014-07-01", BUILD_DATE => "2014-07-01",
}; };

View File

@ -424,110 +424,110 @@ conditional_ternary_expression:
assignment_operator: assignment_operator:
'=' '='
{ {
if ($arg{context} =~ /statement$/) { if ($arg{context} =~ /for init/) {
$return = ['Assign to^L', 'the value^L' ];
} elsif ($arg{context} eq 'for init') {
$return = ['assigning to^L', 'the value^L' ]; $return = ['assigning to^L', 'the value^L' ];
} elsif ($arg{context} =~ /statement$/) {
$return = ['Assign to^L', 'the value^L' ];
} else { } else {
$return = 'which is assigned to be^L'; $return = 'which is assigned to be^L';
} }
} }
| '+=' | '+='
{ {
if ($arg{context} =~ /statement$/) { if ($arg{context} =~ /for init/) {
$return = ['Increment^L','by^L'];
} elsif ($arg{context} eq 'for init') {
$return = ['incrementing^L','by^L']; $return = ['incrementing^L','by^L'];
} elsif ($arg{context} =~ /statement$/) {
$return = ['Increment^L','by^L'];
} else { } else {
$return = 'which is incremented by^L'; $return = 'which is incremented by^L';
} }
} }
| '-=' | '-='
{ {
if ($arg{context} =~ /statement$/) { if ($arg{context} =~ /for init/) {
$return = ['Decrement^L', 'by^L'];
} elsif ($arg{context} eq 'for init') {
$return = ['decrementing^L' , 'by^L']; $return = ['decrementing^L' , 'by^L'];
} elsif ($arg{context} =~ /statement$/) {
$return = ['Decrement^L', 'by^L'];
} else { } else {
$return = 'which is decremented by^L'; $return = 'which is decremented by^L';
} }
} }
| '*=' | '*='
{ {
if ($arg{context} =~ /statement$/) { if ($arg{context} =~ /for init/) {
$return = ['Multiply^L' , 'by^L'];
} elsif ($arg{context} eq 'for init') {
$return = ['multiplying^L' , 'by^L']; $return = ['multiplying^L' , 'by^L'];
} elsif ($arg{context} =~ /statement$/) {
$return = ['Multiply^L' , 'by^L'];
} else { } else {
$return = 'which is multiplied by^L'; $return = 'which is multiplied by^L';
} }
} }
| '/=' | '/='
{ {
if ($arg{context} =~ /statement$/) { if ($arg{context} =~ /for init/) {
$return = ['Divide^L' , 'by^L' ];
} elsif ($arg{context} eq 'for init') {
$return = ['dividing^L' , 'by^L' ]; $return = ['dividing^L' , 'by^L' ];
} elsif ($arg{context} =~ /statement$/) {
$return = ['Divide^L' , 'by^L' ];
} else { } else {
$return = 'which is divided by^L'; $return = 'which is divided by^L';
} }
} }
| '%=' | '%='
{ {
if ($arg{context} =~ /statement$/) { if ($arg{context} =~ /for init/) {
$return = ['Reduce^L', 'to modulo ^L'] ;
} elsif ($arg{context} eq 'for init') {
$return = ['reducing^L', 'to modulo ^L'] ; $return = ['reducing^L', 'to modulo ^L'] ;
} elsif ($arg{context} =~ /statement$/) {
$return = ['Reduce^L', 'to modulo ^L'] ;
} else { } else {
$return = 'which is reduced to modulo^L'; $return = 'which is reduced to modulo^L';
} }
} }
| '<<=' | '<<='
{ {
if ($arg{context} =~ /statement$/) { if ($arg{context} =~ /for init/) {
$return = ['Bit-shift^L', 'left by^L'];
} elsif ($arg{context} eq 'for init') {
$return = ['bit-shifting^L', 'left by^L']; $return = ['bit-shifting^L', 'left by^L'];
} elsif ($arg{context} =~ /statement$/) {
$return = ['Bit-shift^L', 'left by^L'];
} else { } else {
$return = 'which is bit-shifted left by^L'; $return = 'which is bit-shifted left by^L';
} }
} }
| '>>=' | '>>='
{ {
if ($arg{context} =~ /statement$/) { if ($arg{context} =~ /for init/) {
$return = ['Bit-shift^L', 'right by^L'];
} elsif ($arg{context} eq 'for init') {
$return = ['bit-shifting^L', 'right by^L']; $return = ['bit-shifting^L', 'right by^L'];
} elsif ($arg{context} =~ /statement$/) {
$return = ['Bit-shift^L', 'right by^L'];
} else { } else {
$return = 'which is bit-shifted right by^L'; $return = 'which is bit-shifted right by^L';
} }
} }
| '&=' | '&='
{ {
if ($arg{context} =~ /statement$/) { if ($arg{context} =~ /for init/) {
$return = ['Bit-wise ANDed^L', 'by^L' ];
} elsif ($arg{context} eq 'for init') {
$return = ['bit-wise ANDing^L', 'by^L' ]; $return = ['bit-wise ANDing^L', 'by^L' ];
} elsif ($arg{context} =~ /statement$/) {
$return = ['Bit-wise ANDed^L', 'by^L' ];
} else { } else {
$return = 'which is bit-wise ANDed by^L'; $return = 'which is bit-wise ANDed by^L';
} }
} }
| '^=' | '^='
{ {
if ($arg{context} =~ /statement$/) { if ($arg{context} =~ /for init/) {
$return = ['Exclusive-OR^L','by^L'];
} elsif ($arg{context} eq 'for init') {
$return = ['exclusive-ORing^L','by^L']; $return = ['exclusive-ORing^L','by^L'];
} elsif ($arg{context} =~ /statement$/) {
$return = ['Exclusive-OR^L','by^L'];
} else { } else {
$return = 'which is exclusive-ORed by^L'; $return = 'which is exclusive-ORed by^L';
} }
} }
| '|=' | '|='
{ {
if ($arg{context} =~ /statement$/) { if ($arg{context} =~ /for init/) {
$return = ['Bit-wise ORed^L', 'by^L'];
} elsif ($arg{context} eq 'for init') {
$return = ['bit-wise ORing^L', 'by^L']; $return = ['bit-wise ORing^L', 'by^L'];
} elsif ($arg{context} =~ /statement$/) {
$return = ['Bit-wise ORed^L', 'by^L'];
} else { } else {
$return = 'which is bit-wise ORed by^L'; $return = 'which is bit-wise ORed by^L';
} }
@ -839,26 +839,30 @@ unary_expression:
{ $return = $item{postfix_expression}; } { $return = $item{postfix_expression}; }
| '++' unary_expression | '++' unary_expression
{ {
if ($arg{context} =~ /statement$/ ) { if ($arg{context} =~ /for init/) {
$return = "pre-increment $item{unary_expression}"; $return = "pre-incrementing $item{unary_expression}";
} else { } elsif ($arg{context} =~ /(conditional|expression)/) {
if ($item{unary_expression} =~ s/^the member//) { if ($item{unary_expression} =~ s/^the member//) {
$return = "the pre-incremented member $item{unary_expression}"; $return = "the pre-incremented member $item{unary_expression}";
} else { } else {
$return = "pre-incremented $item{unary_expression}"; $return = "pre-incremented $item{unary_expression}";
} }
} else {
$return = "pre-increment $item{unary_expression}";
} }
} }
| '--' unary_expression | '--' unary_expression
{ {
if ($arg{context} =~ /statement$/ ) { if ($arg{context} =~ /for init/) {
$return = "Pre-decrement $item{unary_expression}"; $return = "pre-decrementing $item{unary_expression}";
} else { } elsif ($arg{context} =~ /(conditional|expression)/) {
if ($item{unary_expression} =~ s/^the member//) { if ($item{unary_expression} =~ s/^the member//) {
$return = "the pre-decremented member $item{unary_expression}"; $return = "the pre-decremented member $item{unary_expression}";
} else { } else {
$return = "pre-decremented $item{unary_expression}"; $return = "pre-decremented $item{unary_expression}";
} }
} else {
$return = "Pre-decrement $item{unary_expression}";
} }
} }
| unary_operator cast_expression | unary_operator cast_expression
@ -1025,10 +1029,12 @@ postfix_productions:
} else { } else {
$return = "post-increment"; $return = "post-increment";
} }
} elsif ($arg{context} =~ /statement/) { } elsif ($arg{context} =~ /for init/) {
$return = ['increment', 'by one']; $return = ['incrementing', 'by one'];
} else { } elsif ($arg{context} =~ /(conditional|expression)/) {
$return = "post-incremented $arg{primary_expression}"; $return = "post-incremented $arg{primary_expression}";
} else {
$return = ['increment', 'by one'];
} }
} }
} }
@ -1042,10 +1048,12 @@ postfix_productions:
} else { } else {
$return = "post-decrement"; $return = "post-decrement";
} }
} elsif ($arg{context} =~ /statement/) { } elsif ($arg{context} =~ /for init/) {
$return = ['decrement', 'by one']; $return = ['decrementing', 'by one'];
} else { } elsif ($arg{context} =~ /(conditional|expression)/) {
$return = "post-decremented $arg{primary_expression}"; $return = "post-decremented $arg{primary_expression}";
} else {
$return = ['decrement', 'by one'];
} }
} }
} }
@ -1103,7 +1111,7 @@ narrow_closure:
';' | ',' | '->' ';' | ',' | '->'
primary_expression: primary_expression:
'(' expression ')' (...narrow_closure)(?) '(' expression[context => "$arg{context}|expression"] ')' (...narrow_closure)(?)
{ {
my $expression = $item{expression} ; my $expression = $item{expression} ;
my $repeats = 1; my $repeats = 1;