Skip to content

Instantly share code, notes, and snippets.

@patrickbkr
Created February 26, 2015 18:00
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 patrickbkr/5fd2380e8bbe140b22f3 to your computer and use it in GitHub Desktop.
Save patrickbkr/5fd2380e8bbe140b22f3 to your computer and use it in GitHub Desktop.
State and backtracking
#!/usr/bin/env perl6
grammar Tracker {
regex TOP {
:my %*QUOTE_TRACKER;
Beginning
[ <quote> || .*! ]
End { say "failure" if %*QUOTE_TRACKER<inQuote> == True }
}
regex quote {
\" { say "enter quote"; %*QUOTE_TRACKER<inQuote> = True }
.*?
\" { say "exit quote"; %*QUOTE_TRACKER<inQuote> = False }
}
}
Tracker.parse("Beginning\"stuff\@End");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment