Skip to content

Instantly share code, notes, and snippets.

@littlebenlittle
Last active March 7, 2020 18:00
Show Gist options
  • Save littlebenlittle/4c6891f084de260dcc4d2b1258f8cb46 to your computer and use it in GitHub Desktop.
Save littlebenlittle/4c6891f084de260dcc4d2b1258f8cb46 to your computer and use it in GitHub Desktop.
How can the proto token match the B sym rather than the A sym?
use v6;
grammar Test {
token TOP { <x>+ % \h+ $<rest>=(.*) }
proto token x {*}
token x:sym<A> { \S+ [\h \S+]* }
token x:sym<B> {
"[" <special-token> "]" <.ws> <important-message>
}
token special-token { "SPECIAL TOKEN" }
token important-message { \S+ }
}
my $dat = q (59.5 Some Term [SPECIAL TOKEN] Important!! Yet another term);
say Test.parse($dat);
# 「59.5 Some Term [SPECIAL TOKEN] Important!! Yet another term」
# x => 「59.5」
# x => 「Some Term」
# x => 「[SPECIAL TOKEN] Important!!」
# x => 「Yet another term」
# rest => 「」
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment