Skip to content

Instantly share code, notes, and snippets.

@mryan
Created May 6, 2018 10:21
Show Gist options
  • Save mryan/dc8c890de862876abc4f87f55d974070 to your computer and use it in GitHub Desktop.
Save mryan/dc8c890de862876abc4f87f55d974070 to your computer and use it in GitHub Desktop.
first cut a contrived use of <foo ...> syntax
#!/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