Created
December 6, 2015 16:02
-
-
Save awwaiid/e5bdc58ce76866cc8ba3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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