Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
implement \x{} for P5 regexes
  • Loading branch information
FROGGS committed Jan 16, 2014
1 parent ea681df commit 8688e89
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/QRegex/P5Regex/Actions.nqp
Expand Up @@ -229,7 +229,9 @@ class QRegex::P5Regex::Actions is HLL::Actions {
}

method p5backslash:sym<x>($/) {
my $hexlit := HLL::Actions.ints_to_string( $<hexint> );
my $hexlit := nqp::chars($<hexint>)
?? nqp::chr( self.string_to_int($<hexint>, 16) )
!! nqp::chr(0);
make QAST::Regex.new( $hexlit, :rxtype('literal'), :node($/) );
}

Expand Down
8 changes: 7 additions & 1 deletion src/QRegex/P5Regex/Grammar.nqp
Expand Up @@ -136,7 +136,13 @@ grammar QRegex::P5Regex::Grammar is HLL::Grammar {
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<x> {
<sym>
[
| $<hexint>=[ <[ 0..9 a..f A..F ]>**0..2 ]
| '{' ~ '}' $<hexint>=[ <[ 0..9 a..f A..F ]>**0..2 ]
]
}
token p5backslash:sym<z> { <sym> }
token p5backslash:sym<Z> { <sym> }
token p5backslash:sym<Q> { <sym> <!!{ $*INTERPOLATE := 0; 1 }> }
Expand Down
2 changes: 2 additions & 0 deletions t/p5regex/rx_metachars
Expand Up @@ -54,3 +54,5 @@ a\Z a\nb n basic \Z - (2)
a\z a y basic \z +
a\z a\n n basic \z - (1)
a\z a\nb n basic \z - (2)
a\x6565 ae65 y \x
a\x{65} ae y \x{}

0 comments on commit 8688e89

Please sign in to comment.