Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Unicode properties in regexes (new S05 syntax)
  • Loading branch information
diakopter committed Nov 27, 2011
1 parent 109e4aa commit d4a0667
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/QAST/Compiler.nqp 100644 → 100755
Expand Up @@ -415,6 +415,16 @@ class QAST::Compiler is HLL::Compiler {
$ops;
}

method uniprop($node) {
my $ops := self.post_new('Ops', :result(%*REG<cur>));
my $cmpop := $node.negate ?? 'ne' !! 'eq';
$ops.push_pirop('assign', '$S10', '"' ~ $node[0] ~ '"');
$ops.push_pirop('is_uprop', '$I11', '$S10', %*REG<tgt>, %*REG<pos>);
$ops.push_pirop($cmpop, '$I11', 0, %*REG<fail>);
$ops.push_pirop('inc', %*REG<pos>) unless $node.subtype eq 'zerowidth';
$ops;
}

# a :rxtype<ws> node is a normal subrule call
method ws($node) { self.subrule($node) }

Expand Down
5 changes: 5 additions & 0 deletions src/QRegex/P6Regex/Actions.nqp
Expand Up @@ -409,6 +409,11 @@ class QRegex::P6Regex::Actions is HLL::Actions {
$qast := QAST::Regex.new( PAST::Node.new($name), :rxtype<subrule>, :subtype<method>,
:negate( $<sign> eq '-' ), :node($/) );
}
elsif $<uniprop> {
my $uniprop := ~$<uniprop>;
$qast := QAST::Regex.new( $uniprop, :rxtype<uniprop>,
:negate( $<sign> eq '-' ), :node($/) );
}
else {
my @alts;
for $<charspec> {
Expand Down
3 changes: 2 additions & 1 deletion src/QRegex/P6Regex/Grammar.nqp
Expand Up @@ -193,7 +193,7 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
]?
}

token assertion:sym<[> { <?before '['|'+'|'-'> <cclass_elem>+ }
token assertion:sym<[> { <?before '['|'+'|'-'|':'> <cclass_elem>+ }

token cclass_elem {
$<sign>=['+'|'-'|<?>]
Expand All @@ -209,6 +209,7 @@ grammar QRegex::P6Regex::Grammar is HLL::Grammar {
)*
\s* ']'
| $<name>=[\w+]
| ':' $<uniprop>=[\w+]
]
<.normspace>?
}
Expand Down

0 comments on commit d4a0667

Please sign in to comment.