Created
March 7, 2023 13:33
-
-
Save lizmat/d1c090e8dcf618cdd2bea1b1263f38d7 to your computer and use it in GitHub Desktop.
Proof of concept of enumeration from a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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