Skip to content

Commit

Permalink
[GGE::OPTable] fixed a few bugs
Browse files Browse the repository at this point in the history
A static code analyzer would have caught this one -- I was comparing an
array element without first checking that there was one.
  • Loading branch information
Carl Masak committed Dec 26, 2009
1 parent c55180e commit ff844f0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/GGE/OPTable.pm
Expand Up @@ -137,6 +137,7 @@ class GGE::OPTable {
$oper.push( @temp[$_] );
}
if $top<assoc> eq 'list'
&& @temp[1]
&& $oper.hash-access('type')
eq @temp[1].hash-access('type') {
@temp[1].push($oper.llist[1]);
Expand Down Expand Up @@ -253,6 +254,12 @@ class GGE::OPTable {
++$circumnest;
# go directly to shift
}
elsif $topcat == GGE_OPTABLE_POSTFIX()
&& $token<syncat> == GGE_OPTABLE_INFIX()
| GGE_OPTABLE_POSTFIX() {
reduce;
next;
}
elsif $topcat == $token<syncat>
== GGE_OPTABLE_INFIX() {
# XXX: You guessed it -- the addition of
Expand All @@ -268,10 +275,10 @@ class GGE::OPTable {
next;
}
}
elsif all($topcat, $token<syncat>)
== GGE_OPTABLE_PREFIX()
| GGE_OPTABLE_INFIX()
| GGE_OPTABLE_POSTFIX() {
elsif $topcat == GGE_OPTABLE_PREFIX()
| GGE_OPTABLE_INFIX()
&& $token<syncat> == GGE_OPTABLE_INFIX()
| GGE_OPTABLE_POSTFIX() {
# XXX: You guessed it -- the addition of
# a hundred equals signs is kind of
# a hack.
Expand Down
11 changes: 11 additions & 0 deletions t/03-optable.t
Expand Up @@ -139,6 +139,17 @@ for ['term:', precedence => '=', :parsed($ident) ],
optable_output_is( '^ abc', 'infix:(term:^(), term:abc)',
'whitespace and infix:' );

$optable .= new;

for ['term:', precedence => '=', :parsed($ident) ],
['infix:', looser => 'term:', :assoc<list>, :nows ],
['infix:&', looser => 'infix:', :assoc<list>, :nows ],
['prefix:|', looser => 'infix:&', :assoc<list>, :nows ]
-> @args { my ($name, %opts) = @args; $optable.newtok($name, |%opts) }

optable_output_is( 'a&|b', 'infix:&(term:a, prefix:|(term:b))',
'infix, prefix and precedence' );

sub optable_output_is($test, $expected, $msg) {
my $output;
if $optable.parse($test, :stop(' ;')) -> $match {
Expand Down

0 comments on commit ff844f0

Please sign in to comment.