Skip to content

Instantly share code, notes, and snippets.

@jnthn
Created November 17, 2011 23:53
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 jnthn/1375006 to your computer and use it in GitHub Desktop.
Save jnthn/1375006 to your computer and use it in GitHub Desktop.
# Hopefully easy...
grammar Busted1 {
token TOP { <foo> }
proto token foo { <*> }
token foo:sym<a> {
:my $x := 42;
.+
}
token foo:sym<b> { aa }
}
say(~Busted1.parse('aaa')); # should be aaa; the :my ... gets in the way
# Potentially tricky; didn't think it through much.
grammar Busted2 {
token TOP { <foo> }
proto token foo { <*> }
token foo:sym<a> { <?[a]> .+ }
token foo:sym<b> { aa }
}
say(~Busted2.parse('aaa')); # should be aaa; zerowidth thingy gets in the way
# Hopefully quite easy
grammar Busted3 {
token TOP { <foo> }
proto token foo { <*> }
token foo:sym<a> { (.+) }
token foo:sym<b> { aa }
}
say(~Busted3.parse('aaa')); # this should be aaa too; capturing to blame this time
# Hopefully same as above, or easy after it
grammar Busted4 {
token TOP { <foo> }
proto token foo { <*> }
token foo:sym<a> { $<x>=[.+] }
token foo:sym<b> { aa }
}
say(~Busted4.parse('aaa')); # may well be same underlying cause as Busted3's issue
# Tricky-ish; straight from S05; actually about tie-breaking (longest
# literal prefix wins). Probably means keeping track of where literal
# end positions are, like we track fate end positions.
grammar Busted5 {
token TOP { <foo> }
proto token foo { <*> }
token foo:sym<a> { foo\w* { say(1) } }
token foo:sym<b> { food\w* { say(2) } }
}
say(~Busted5.parse('foods')); # will parse either way but should "say 2"
# May we horrid...probably only so important, but S05 calls out & (but NOT
# &&) as declarative.
grammar Busted6 {
token TOP { <foo> }
proto token foo { <*> }
token foo:sym<a> { \w+ & aaa }
token foo:sym<b> { aa }
}
say(~Busted6.parse('aaa')); # & isn't handled by NFA builder
# Shouldn't be too bad. Note that we don't run the assertion from the NFA;
# if we can rule out the matching beyond it with the NFA there's no point
# even trying it since we'd be doomed anyway.
grammar Busted7 {
token TOP { <foo> }
proto token foo { <*> }
token foo:sym<a> { a <?{ 1 }> .+ }
token foo:sym<b> { aa }
}
say(~Busted7.parse('aaa')); # assertions are declarative
# Same as above, just the negative assertion.
grammar Busted8 {
token TOP { <foo> }
proto token foo { <*> }
token foo:sym<a> { a <!{ 0 }> .+ }
token foo:sym<b> { aa }
}
say(~Busted8.parse('aaa')); # assertions are declarative
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment