Skip to content

Instantly share code, notes, and snippets.

@awwaiid
Created December 6, 2015 16:02
Show Gist options
  • Save awwaiid/e5bdc58ce76866cc8ba3 to your computer and use it in GitHub Desktop.
Save awwaiid/e5bdc58ce76866cc8ba3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl6
use Grammar::Tracer;
# use Grammar::Debugger;
grammar Offsides {
token TOP {
<tree>*
}
token tree {
$<indent>=(\s*) <text>
<subtree($<indent>)>*
}
token subtree($current-indent) {
# PROBLEM: This never has anything in it!
{ say "Current indent: [$current-indent]" }
$current-indent $<more-indent>=(\s+) <text>
# Might have some sub-trees with more indent
<tree($current-indent ~ ~$<more-indent>)>*
}
token text {
\S .*? $$
}
}
my $test-input = q|
hello
this is
a
test to see
if this
can calculate
the offside
rule
|;
my $match = Offsides.parse($test-input);
say $match;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment