Skip to content

Instantly share code, notes, and snippets.

@lizmat
Created March 7, 2023 13:33
Show Gist options
  • Save lizmat/d1c090e8dcf618cdd2bea1b1263f38d7 to your computer and use it in GitHub Desktop.
Save lizmat/d1c090e8dcf618cdd2bea1b1263f38d7 to your computer and use it in GitHub Desktop.
Proof of concept of enumeration from a string
use v6.*;
sub char-classify(Str:D $string) {
my @elements = $string.comb.map: {
RakuAST::Regex::CharClassEnumerationElement::Character.new($_)
}
RakuAST::QuotedRegex.new(
body => RakuAST::Regex::Assertion::CharClass.new(
RakuAST::Regex::CharClassElement::Enumeration.new(:@elements)
)
).EVAL
}
my $foo = char-classify("abcd");
say "a" ~~ $foo; # 「a」
say "e" ~~ $foo; # Nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment