-
-
Save lucs/c062e3b8e0d72b54f395 to your computer and use it in GitHub Desktop.
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; | |
# This fails. | |
#→ 「Method 'bar' not found for invocant of class 'Cursor'」: | |
#my regex bar { <[\w]> }; | |
#my regex foo { ^ <+ bar - [0..9]> <bar>* $ }; | |
# Using the character class directly of course works. | |
#→ 1: Nil | |
#→ 2: 「asdf」 | |
#→ foo => 「asdf」 | |
my regex foo { ^ <+ [\w] - [0..9]> <[\w]>* $ }; | |
say "1: ", "0sdf" ~~ /<foo>/; | |
say "2: ", "asdf" ~~ /<foo>/; | |
# Using a grammar works too. | |
#→ 3: Nil | |
#→ 4: 「asdf」 | |
#→ bar => 「s」 | |
#→ bar => 「d」 | |
#→ bar => 「f」 | |
grammar Goo { | |
token bar { <[\w]> } | |
token foo { <+ bar - [0..9]> <bar>* } | |
} | |
say "3: ", Goo.parse("0sdf", :rule('foo')); | |
say "4: ", Goo.parse("asdf", :rule('foo')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment