Skip to content

Commit

Permalink
Another round of fixes to OPP with QRegex; actually seems to work now.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Jan 7, 2012
1 parent c84aaf0 commit 999c0e4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
21 changes: 8 additions & 13 deletions src/QHLL/Grammar.pm
Original file line number Diff line number Diff line change
Expand Up @@ -653,21 +653,17 @@ An operator precedence parser.
.local pmc inO
$P0 = infix['OPER']
inO = $P0['O']
$P0 = inO['nextterm']
if null $P0 goto nonextterm
termishrx = $P0
termishrx = inO['nextterm']
if termishrx goto have_termishrx
nonextterm:
termishrx = 'termish'
have_termishrx:

.local string inprec, inassoc, opprec
$P0 = inO['prec']
inprec = $P0
inprec = inO['prec']
unless inprec goto err_inprec
if inprec <= preclim goto term_done
$P0 = inO['assoc']
inassoc = $P0
inassoc = inO['assoc']

$P0 = inO['sub']
if null $P0 goto subprec_done
Expand All @@ -679,8 +675,7 @@ An operator precedence parser.
$P0 = opstack[-1]
$P0 = $P0['OPER']
$P0 = $P0['O']
$P0 = $P0['prec']
opprec = $P0
opprec = $P0['prec']
unless opprec > inprec goto reduce_gt_done
self.'EXPR_reduce'(termstack, opstack)
goto reduce_loop
Expand Down Expand Up @@ -758,7 +753,7 @@ An operator precedence parser.
$S0 = $P0
self.$S0(op)
op_infix_1:
self.'!reduce'('EXPR', 'INFIX', op)
self.'!reduce_with_match'('EXPR', 'INFIX', op)
goto done

op_unary:
Expand All @@ -769,10 +764,10 @@ An operator precedence parser.
ofrom = op.'from'()
if afrom < ofrom goto op_postfix
op_prefix:
self.'!reduce'('EXPR', 'PREFIX', op)
self.'!reduce_with_match'('EXPR', 'PREFIX', op)
goto done
op_postfix:
self.'!reduce'('EXPR', 'POSTFIX', op)
self.'!reduce_with_match'('EXPR', 'POSTFIX', op)
goto done

op_list:
Expand Down Expand Up @@ -801,7 +796,7 @@ An operator precedence parser.
op_sym_done:
arg = pop termstack
unshift op, arg
self.'!reduce'('EXPR', 'LIST', op)
self.'!reduce_with_match'('EXPR', 'LIST', op)
goto done

done:
Expand Down
16 changes: 12 additions & 4 deletions src/QRegex/Cursor.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ role NQPCursorRole {
if pir::can__IPS($actions, $name);
}

method !reduce_with_match($name, $key, $match) {
my $actions := pir::find_dynamic_lex__Ps('$*ACTIONS');
pir::find_method__PPs($actions, $name)($actions, $match, $key)
if pir::can__IPS($actions, $name);
}

method !protoregex($name) {
my $nfa := self.HOW.cache(self, $name, { self.'!protoregex_nfa'($name) });
my @fatepos := $nfa.run($!target, $!pos);
Expand Down Expand Up @@ -244,7 +250,8 @@ role NQPCursorRole {
method ww() {
my $cur := self."!cursor_start"();
$cur."!cursor_pass"($!pos, "ww")
if $!pos >= 1
if $!pos > 0
&& $!pos != nqp::chars($!target)
&& nqp::iscclass(pir::const::CCLASS_WORD, $!target, $!pos)
&& nqp::iscclass(pir::const::CCLASS_WORD, $!target, $!pos-1);
$cur;
Expand Down Expand Up @@ -405,8 +412,9 @@ class NQPMatch is NQPCapture {

class NQPCursor does NQPCursorRole {
method MATCH() {
unless nqp::istype(nqp::getattr(self, NQPCursor, '$!match'), NQPMatch) {
my $match := NQPMatch.new();
my $match := nqp::getattr(self, NQPCursor, '$!match');
unless pir::isa($match, 'Hash') || nqp::istype($match, NQPMatch) {
$match := NQPMatch.new();
nqp::bindattr(self, NQPCursor, '$!match', $match);
nqp::bindattr($match, NQPMatch, '$!orig', nqp::getattr(self, NQPCursor, '$!orig'));
nqp::bindattr_i($match, NQPMatch, '$!from', nqp::getattr_i(self, NQPCursor, '$!from'));
Expand All @@ -420,7 +428,7 @@ class NQPCursor does NQPCursorRole {
!! nqp::bindkey($hash, $key, $_.value);
}
}
nqp::getattr(self, NQPCursor, '$!match');
$match
}

method Bool() {
Expand Down

0 comments on commit 999c0e4

Please sign in to comment.