Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
[p6regex]: Add \xNN, \XNN, and \x[NN,NN,...] to p6regexes.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 29, 2009
1 parent 063d6a1 commit d49ead9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/HLL/Actions.pm
@@ -1,6 +1,6 @@
class HLL::Actions;

sub string_to_int($src, $base) {
our sub string_to_int($src, $base) {
Q:PIR {
.local pmc src
.local string src_s
Expand Down Expand Up @@ -34,7 +34,7 @@ sub string_to_int($src, $base) {
};
}

sub ints_to_string($ints) {
our sub ints_to_string($ints) {
Q:PIR {
.local string result
result = ''
Expand All @@ -58,7 +58,7 @@ sub ints_to_string($ints) {
};
}

sub isaPAST($x) {
our sub isaPAST($x) {
Q:PIR {
$P0 = find_lex '$x'
$I0 = isa $P0, ['PAST';'Node']
Expand Down
13 changes: 11 additions & 2 deletions src/Regex/P6Regex/Actions.pm
@@ -1,4 +1,4 @@
class Regex::P6Regex::Actions;
class Regex::P6Regex::Actions is HLL::Actions;

## this will eventually be handled using contextuals
our @MODIFIERS;
Expand Down Expand Up @@ -286,11 +286,20 @@ method backslash:sym<t>($/) {
}

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

method backslash:sym<x>($/) {
my $hexlit :=
HLL::Actions::ints_to_string( $<hexint> || $<hexints><hexint> );
make $<sym> eq 'X'
?? PAST::Regex.new( $hexlit, :pasttype('enumcharlist'),
:negate(1), :node($/) )
!! PAST::Regex.new( $hexlit, :pasttype('literal'), :node($/) );
}

method backslash:sym<misc>($/) {
my $past := PAST::Regex.new( ~$/ , :pasttype('literal'), :node($/) );
Expand Down
1 change: 1 addition & 0 deletions src/Regex/P6Regex/Grammar.pm
Expand Up @@ -119,6 +119,7 @@ grammar Regex::P6Regex::Grammar is HLL::Grammar;
token backslash:sym<r> { $<sym>=[<[rR]>] }
token backslash:sym<t> { $<sym>=[<[tT]>] }
token backslash:sym<v> { $<sym>=[<[vV]>] }
token backslash:sym<x> { $<sym>=[<[xX]>] [ <hexint> | '[' <hexints> ']' ] }
token backslash:sym<A> { 'A' <.obs: '\\A as beginning-of-string matcher', '^'> }
token backslash:sym<z> { 'z' <.obs: '\\z as end-of-string matcher', '$'> }
token backslash:sym<Z> { 'Z' <.obs: '\\Z as end-of-string matcher', '\\n?$'> }
Expand Down
46 changes: 23 additions & 23 deletions t/p6regex/rx_metachars
Expand Up @@ -206,29 +206,29 @@ a \X[0021] c abc y not hex (\X[])
c \X[0021] d abc!def n not hex (\X[])
c \X[0021]+ d abc!!def n not hex (\X[])
a \X[0021]+ f abcdef y not hex (\X[])
c \c33 d abc!def y hex (\x)
c \c33+ d abc!!def y hex (\x)
a \c33+ f abcdef n hex (\x)
b \c33 c abc!def n hex (\x)
c \c[33] d abc!def y hex (\x[])
c \c[33]+ d abc!!def y hex (\x[])
c \c[33,33] d abc!!def y hex (\x[])
c \c[ 33, 33] d abc!!def y hex (\x[])
c \c[ 33 , 33 ] d abc!!def y hex (\x[])
a \c[33]+ f abcdef n hex (\x[])
b \c[33] c abc!def n hex (\x[])
\C33 a y not hex (\X)
a \C33 c abc y not hex (\X)
\C33 '' n not hex (\X)
c \C33 d abc!def n not hex (\X)
c \C33+ d abc!!def n not hex (\X)
a \C33+ f abcdef y not hex (\X)
\C[33] a y not hex (\X[])
a \C[33] c abc y not hex (\X[])
\C[33] '' n not hex (\X[])
c \C[33] d abc!def n not hex (\X[])
c \C[33]+ d abc!!def n not hex (\X[])
a \C[33]+ f abcdef y not hex (\X[])
c \c33 d abc!def y hex (\c)
c \c33+ d abc!!def y hex (\c)
a \c33+ f abcdef n hex (\c)
b \c33 c abc!def n hex (\c)
c \c[33] d abc!def y hex (\c[])
c \c[33]+ d abc!!def y hex (\c[])
c \c[33,33] d abc!!def y hex (\c[])
c \c[ 33, 33] d abc!!def y hex (\c[])
c \c[ 33 , 33 ] d abc!!def y hex (\c[])
a \c[33]+ f abcdef n hex (\c[])
b \c[33] c abc!def n hex (\c[])
\C33 a y not hex (\C)
a \C33 c abc y not hex (\C)
\C33 '' n not hex (\C)
c \C33 d abc!def n not hex (\C)
c \C33+ d abc!!def n not hex (\C)
a \C33+ f abcdef y not hex (\C)
\C[33] a y not hex (\C[])
a \C[33] c abc y not hex (\C[])
\C[33] '' n not hex (\C[])
c \C[33] d abc!def n not hex (\C[])
c \C[33]+ d abc!!def n not hex (\C[])
a \C[33]+ f abcdef y not hex (\C[])
c \o041 d abc!def y octal (\o)
c \o41+ d abc!!def y octal (\o)
a \o41+ f abcdef n octal (\o)
Expand Down

0 comments on commit d49ead9

Please sign in to comment.