Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[P5Regex] added \r, \R, \t and \x
  • Loading branch information
FROGGS committed Aug 19, 2013
1 parent 210cd15 commit 725cfa8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
42 changes: 35 additions & 7 deletions src/QRegex/P5Regex/Actions.nqp
Expand Up @@ -190,21 +190,49 @@ class QRegex::P5Regex::Actions is HLL::Actions {
}

method p5backslash:sym<A>($/) {
make QAST::Regex.new( :rxtype<anchor>, :subtype<bos>, :node($/) );
make QAST::Regex.new( :rxtype<anchor>, :subtype<bos>, :node($/) );
}

method p5backslash:sym<b>($/) {
make QAST::Regex.new(:rxtype<subrule>, :subtype<zerowidth>,
:node($/), :negate($<sym> eq 'B'), :name(''),
QAST::Node.new( QAST::SVal.new( :value('wb') ) ));
}


method p5backslash:sym<h>($/) {
make QAST::Regex.new( "\x[09,20,a0,1680,180e,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,200a,202f,205f,3000]", :rxtype('enumcharlist'),
:negate($<sym> eq 'H'), :node($/) );
}

method p5backslash:sym<r>($/) {
make QAST::Regex.new( "\r", :rxtype('enumcharlist'), :node($/) );
}

method p5backslash:sym<R>($/) {
make QAST::Regex.new( :rxtype<cclass>, :name( 'n' ), :node($/) );
}

method p5backslash:sym<s>($/) {
make QAST::Regex.new(:rxtype<cclass>, :name( nqp::lc(~$<sym>) ),
:negate($<sym> le 'Z'), :node($/));
}

method p5backslash:sym<b>($/) {
make QAST::Regex.new(:rxtype<subrule>, :subtype<zerowidth>,
:node($/), :negate($<sym> eq 'B'), :name(''),
QAST::Node.new( QAST::SVal.new( :value('wb') ) ));
method p5backslash:sym<t>($/) {
make QAST::Regex.new( "\t", :rxtype('enumcharlist'),
:negate($<sym> eq 'T'), :node($/) );
}


method p5backslash:sym<v>($/) {
make QAST::Regex.new( "\x[0a,0b,0c,0d,85,2028,2029]",
:rxtype('enumcharlist'),
:negate($<sym> eq 'V'), :node($/) );
}

method p5backslash:sym<x>($/) {
my $hexlit := HLL::Actions.ints_to_string( $<hexint> );
make QAST::Regex.new( $hexlit, :rxtype('literal'), :node($/) );
}

method p5backslash:sym<z>($/) {
make QAST::Regex.new( :rxtype<anchor>, :subtype<eos>, :node($/) );
}
Expand Down
8 changes: 6 additions & 2 deletions src/QRegex/P5Regex/Grammar.nqp
Expand Up @@ -130,10 +130,14 @@ grammar QRegex::P5Regex::Grammar is HLL::Grammar {
proto token p5backslash { <...> }

token p5backslash:sym<A> { <sym> }
token p5backslash:sym<z> { <sym> }
token p5backslash:sym<Z> { <sym> }
token p5backslash:sym<b> { $<sym>=[<[bB]>] }
token p5backslash:sym<r> { <sym> }
token p5backslash:sym<R> { <sym> }
token p5backslash:sym<s> { $<sym>=[<[dDnNsSwW]>] }
token p5backslash:sym<t> { <sym> }
token p5backslash:sym<x> { <sym> <hexint> }
token p5backslash:sym<z> { <sym> }
token p5backslash:sym<Z> { <sym> }
token p5backslash:sym<misc> { $<litchar>=(\W) | $<number>=(\d+) }
token p5backslash:sym<oops> { <.panic: "Unrecognized Perl 5 regex backslash sequence"> }

Expand Down

0 comments on commit 725cfa8

Please sign in to comment.