Skip to content

Instantly share code, notes, and snippets.

@patrickbkr
Last active August 29, 2015 14:16
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/361b80a01e3217ad9073 to your computer and use it in GitHub Desktop.
Save patrickbkr/361b80a01e3217ad9073 to your computer and use it in GitHub Desktop.
Propagating Cursor state
#!/usr/bin/env perl6
grammar Tracker {
regex TOP {
{ make {:!inQuote} }
Beginning
<quoteStart>
.*
<laterRule>
End
}
regex quoteStart {
\" { make {:inQuote} }
<subRule>?
}
regex subRule {
{ say "sub rule fails" if not $/.made<inQuote> }
#{ fail if not $/.made<inQuote> }
\" #{ make {:!inQuote} }
}
regex laterRule {
{ say "later rule fails" if not $/.made<inQuote> }
{ fail if not $/.made<inQuote> }
\" { make {:!inQuote} }
}
}
say so Tracker.parse("Beginning\"xy\"End");
# vim: expandtab shiftwidth=4 ft=perl6
@patrickbkr
Copy link
Author

Outputs:
sub rule fails
later rule fails
False

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment