Skip to content

Commit

Permalink
Compile regex sequences, alterations, conjunctions
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Jul 7, 2020
1 parent b93f28a commit 1cf5223
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Raku/ast/regex.rakumod
Expand Up @@ -33,6 +33,14 @@ class RakuAST::Regex::Branching is RakuAST::Regex {
self.IMPL-WRAP-LIST($!branches)
}

method IMPL-REGEX-QAST(RakuAST::IMPL::QASTContext $context, %mods) {
my $qast := QAST::Regex.new(:rxtype(self.IMPL-QAST-REGEX-TYPE));
for $!branches {
$qast.push($_.IMPL-REGEX-QAST($context, $_));
}
$qast
}

method visit-children(Code $visitor) {
for $!branches {
$visitor($_);
Expand All @@ -42,18 +50,22 @@ class RakuAST::Regex::Branching is RakuAST::Regex {

# Sequential alternation (||).
class RakuAST::Regex::SequentialAlternation is RakuAST::Regex::Branching {
method IMPL-QAST-REGEX-TYPE() { 'altseq' }
}

# Sequential conjunction (&&).
class RakuAST::Regex::SequentialConjunction is RakuAST::Regex::Branching {
method IMPL-QAST-REGEX-TYPE() { 'conjseq' }
}

# Alternation (|).
class RakuAST::Regex::Alternation is RakuAST::Regex::Branching {
method IMPL-QAST-REGEX-TYPE() { 'alt' }
}

# Conjunction (|).
class RakuAST::Regex::Conjunction is RakuAST::Regex::Branching {
method IMPL-QAST-REGEX-TYPE() { 'conj' }
}

# A sequence of terms to match, one after the other.
Expand All @@ -71,6 +83,14 @@ class RakuAST::Regex::Sequence is RakuAST::Regex {
self.IMPL-WRAP-LIST($!terms)
}

method IMPL-REGEX-QAST(RakuAST::IMPL::QASTContext $context, %mods) {
my $concat := QAST::Regex.new(:rxtype<concat>);
for $!terms {
$concat.push($_.IMPL-REGEX-QAST($context, $_));
}
$concat
}

method visit-children(Code $visitor) {
for $!terms {
$visitor($_);
Expand Down

0 comments on commit 1cf5223

Please sign in to comment.