Created
May 6, 2018 10:21
-
-
Save mryan/dc8c890de862876abc4f87f55d974070 to your computer and use it in GitHub Desktop.
first cut a contrived use of <foo ...> syntax
This file contains 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 | |
grammar G { | |
my $SOLpos = -1 ; | |
regex TOP { <line>+ } | |
method SOLscan($regex) { | |
# Print out the string we're matching against for kicks | |
say 'self.target: ' , self.target ; | |
my $cur = self."!cursor_start_cur"() ; | |
# Should now use $SOLpos to run the regex starting at | |
# the start of the current line, but here I've just | |
# fudged a successful parse. | |
$cur."!cursor_pass"(self.pos, 'SOLscan') ; | |
$cur | |
} | |
token line { | |
{ $SOLpos = self.pos ; say $SOLpos } | |
[<word> <space>? <SOLscan \d+>]+ \n | |
} | |
token word { \S+ } | |
} | |
my $mo = G.subparse: q:to/END/ ; | |
hello world | |
line two | |
END | |
dd $mo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment