Skip to content

Instantly share code, notes, and snippets.

@zoffixznet

zoffixznet/p6.p6 Secret

Created June 18, 2018 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zoffixznet/0431129fd9a5af319cff81a9fdbf4f06 to your computer and use it in GitHub Desktop.
Save zoffixznet/0431129fd9a5af319cff81a9fdbf4f06 to your computer and use it in GitHub Desktop.
grammar GrammarAdvice {
rule TOP {
:my $*USE-WS = 0;
"use" <type> "for" <significance> "whitespace"
}
token type {
| "tokens" { $*USE-WS = 0 }
| "regex" { $*USE-WS = 0 }
| "rules" { $*USE-WS = 1 }
}
token significance {
| <?{ $*USE-WS == 0 }> "insignificant"
| <?{ $*USE-WS == 1 }> "significant"
}
}
say GrammarAdvice.parse("use rules for insignificant whitespace");
say GrammarAdvice.parse("use tokens for insignificant whitespace");
say GrammarAdvice.parse("use regex for insignificant whitespace");
say GrammarAdvice.parse("use rules for significant whitespace");
say GrammarAdvice.parse("use tokens for significant whitespace");
say GrammarAdvice.parse("use regex for significant whitespace");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment