Skip to content

Commit

Permalink
Another crack at highexpect.
Browse files Browse the repository at this point in the history
This seems to give better results.
  • Loading branch information
jnthn committed Dec 8, 2012
1 parent 8d297b2 commit fb3f186
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/QAST/Compiler.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -1241,8 +1241,9 @@ class QAST::Compiler is HLL::Compiler {
}

method dba($node) {
# Doesn't compile into another; really just for the NFA.
self.post_new('Ops', :result(%*REG<cur>))
my $ops := self.post_new('Ops', :result(%*REG<cur>));
$ops.push_pirop('callmethod', '"!dba"', %*REG<cur>, %*REG<pos>, self.escape($node.name));
$ops
}

my %cclass_code;
Expand Down
22 changes: 22 additions & 0 deletions src/QRegex/Cursor.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ my class ParseShared {
has $!orig;
has str $!target;
has int $!highwater;
has @!highexpect;
}

role NQPCursorRole is export {
Expand Down Expand Up @@ -79,6 +80,7 @@ role NQPCursorRole is export {
nqp::bindattr_s($shared, ParseShared, '$!target',
pir::trans_encoding__Ssi($orig, pir::find_encoding__Is('ucs4')));
nqp::bindattr_i($shared, ParseShared, '$!highwater', 0);
nqp::bindattr($shared, ParseShared, '@!highexpect', nqp::list());
}
nqp::bindattr($new, $?CLASS, '$!shared', $shared);
if nqp::defined($c) {
Expand Down Expand Up @@ -308,11 +310,31 @@ role NQPCursorRole is export {
}
}

method !dba(int $pos, str $dba) {
my $shared := $!shared;
my int $highwater := nqp::getattr_i($shared, ParseShared, '$!highwater');
my $highexpect;
if $pos >= $highwater {
$highexpect := nqp::getattr($shared, ParseShared, '@!highexpect');
if $pos > $highwater {
pir::assign__0Pi($highexpect, 0);
nqp::bindattr_i($shared, ParseShared, '$!highwater', $pos);
}
nqp::push_s($highexpect, $dba);
}
}

method !highwater() {
nqp::getattr_i($!shared, ParseShared, '$!highwater')
}

method !highexpect() {
nqp::getattr($!shared, ParseShared, '@!highexpect')
}

method !clear_highwater() {
my $highexpect := nqp::getattr($!shared, ParseShared, '@!highexpect');
pir::assign__0Pi($highexpect, 0);
nqp::bindattr_i($!shared, ParseShared, '$!highwater', -1)
}

Expand Down
4 changes: 4 additions & 0 deletions src/QRegex/NFA.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class QRegex::NFA {
method anchor($node, int $from, int $to) {
self.addedge($from, $to, $EDGE_EPSILON, 0);
}

method dba($node, int $from, int $to) {
self.addedge($from, $to, $EDGE_EPSILON, 0);
}

my %cclass_code;
INIT {
Expand Down

0 comments on commit fb3f186

Please sign in to comment.