Skip to content

Instantly share code, notes, and snippets.

@lucs
Last active December 19, 2015 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucs/c062e3b8e0d72b54f395 to your computer and use it in GitHub Desktop.
Save lucs/c062e3b8e0d72b54f395 to your computer and use it in GitHub Desktop.
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