Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Parse regex modifiers and complain about NYI ones
  • Loading branch information
sorear committed Apr 15, 2011
1 parent a31f8f4 commit bdcd777
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions src/niecza
Expand Up @@ -27,6 +27,82 @@ use Operator;
use OptRxSimple;
use Sig;

augment class NieczaActions {
method quote:rx ($/) {
self.extract_rx_adverbs(False, False, $<quibble>);
make self.op_for_regex($/, $<quibble>.ast);
}
method quote:m ($/) {
make ::Op::CallMethod.new(|node($/), name => 'ACCEPTS',
receiver => self.op_for_regex($/, $<quibble>.ast),
args => [ mklex($/, '$_'),
self.extract_rx_adverbs(True, False, $<quibble>) ]);
}
method regex_block($/) {
if $<onlystar> {
return Nil;
}
self.extract_rx_adverbs(False, False, $<quotepair>);
make $<nibble>.ast;
}
method sibble($/) {
my $regex = self.op_for_regex($/, $<left>.ast);
my $repl;
if $<infixish> {
if $<infixish> eq '=' {
$repl = $<right>.ast;
} elsif $<infixish>.ast ~~ ::Operator::CompoundAssign {
$repl = $<infixish>.ast.base.with_args($/,
mkcall($/, '&prefix:<~>', ::Op::ContextVar.new(name => '$*/')),
$<right>.ast);
} else {
$/.CURSOR.sorry("Unhandled operator in substitution");
$repl = mklex($/, 'Any');
}
} else {
$repl = $<right>.ast;
}
$repl = self.transparent($/, $repl);
make ::Op::CallSub.new(|node($/), invocant => mklex($/,'&_substitute'),
args => [ mklex($/, '$_'), $regex, $repl,
self.extract_rx_adverbs(True, True, $/) ]);
}

method extract_rx_adverbs($ismatch, $issubst, $match) {
my $qps = ($match ~~ List) ?? $match !! $match<babble><quotepair>;
return () if !$qps;

my @ok;
my @nyi;
my @args;
my @internal = < sigspace s ratchet r ignorecase i >;

push @nyi, < ignoreaccent a bytes codes graphs chars Perl5 P5 >;

if $issubst {
push @nyi, < sameaccent aa samecase ii th st nd rd nth x >;
}

if $ismatch {
push @nyi, < overlap ov exhaustive ex continue c pos p global g rw >;
}

for @$qps -> $qp {
if @internal.grep($qp<k>) {
# handled by rx compiler
} elsif @ok.grep($qp<k>) {
push @args, $qp.ast
} elsif @nyi.grep($qp<k>) {
$qp.CURSOR.sorry("Regex modifier $qp<k> not yet implemented");
} else {
$qp.CURSOR.sorry("Regex modifier $qp<k> not valid on { $issubst ?? "substitution" !! $ismatch ?? "match" !! "regex literal" }");
}
}

@args
}
}

augment class Op::Labelled { #OK exist
method statement_level() {
self.new(name => $.name, stmt => $.stmt.statement_level);
Expand Down

0 comments on commit bdcd777

Please sign in to comment.