From c43ea6e0eb4e6f7cd303f6efef477f433b50a3f1 Mon Sep 17 00:00:00 2001 From: pmichaud Date: Wed, 9 Dec 2009 09:38:55 -0600 Subject: [PATCH] Add enumerated character lists to ARE. --- src/ARE/Actions.pm | 15 +++++++++++++++ src/ARE/Grammar.pm | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/src/ARE/Actions.pm b/src/ARE/Actions.pm index 7ebfe67..de982c8 100644 --- a/src/ARE/Actions.pm +++ b/src/ARE/Actions.pm @@ -72,6 +72,21 @@ method metachar:sym<.>($/) { method metachar:sym($/) { make $.ast; } +method metachar:sym<[>($/) { + my $str := ''; + for $ { + if $_[1] { + my $a := pir::ord($_[0]); + my $b := pir::ord(~$_[1][0]); + while $a < $b { $str := $str ~ pir::chr($a); $a++; } + } + else { $str := $str ~ $_[0]; } + } + my $past := PAST::Regex.new( $str, :pasttype, :node($/) ); + $past.negate( $ gt '' ); + make $past; +} + method backslash:sym($/) { make PAST::Regex.new( :pasttype, :subtype(~$), :node($/)); } diff --git a/src/ARE/Grammar.pm b/src/ARE/Grammar.pm index d0497d8..fd616a9 100644 --- a/src/ARE/Grammar.pm +++ b/src/ARE/Grammar.pm @@ -32,6 +32,12 @@ token quantifier:sym { } proto token metachar { <...> } token metachar:sym<.> { } token metachar:sym { \\ } +token metachar:sym<[> { + '[' + $=['^'?] + $=( [ \\ (.) | (<-[\]\\]>) ] [ '-' (.) ]? )* + ']' +} proto token backslash { <...> } token backslash:sym { $=[<[dswDSW]>] }