Skip to content

Instantly share code, notes, and snippets.

@tangentstorm
Last active December 16, 2015 04:19
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 tangentstorm/5375842 to your computer and use it in GitHub Desktop.
Save tangentstorm/5375842 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl6
=comment
Universal forth-style tokenizer (breaks on whitespace)
=cut
grammar Grammar {
token TOP { [ <whitespace> | <blackspace> ]+ }
token whitespace { \s+ }
token blackspace { $<token>=[\S+] }
}
class Actions {
method blackspace($/) { say ~$<token> }
}
my @tokens = Grammar.parse( slurp, :actions( Actions ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment