Cut operator "error on fail"
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
PyMeta |
New
|
Undecided
|
Unassigned |
Bug Description
Given the following grammar, I need a way to mark that beginning a block without ending it is an error. In http://
from pymeta.grammar import OMeta
g = """
brace1 ::= <token '{'>
brace2 ::= <token '}'>
bracket1 ::= <token '['>
bracket2 ::= <token ']'>
braceBlock ::= <brace1> <blockContent "}">:x <brace2> => x
bracketBlock ::= <bracket1> <blockContent "]">:x <bracket2> => x
block ::= (<braceBlock>
junk :closer ::= (~<exactly closer> <anything>)+:t => ''.join(t)
blockContent :closer ::= (<block>|<junk closer>)*
file ::= <block>+:b
"""
testOK = "{ asdf { blah [ blah [ blah ] {whatever} ] } } [ etc. ]"
testImproper = "{ one [ two } { etc. }"
Blocks = OMeta.makeGramm
print Blocks(
print Blocks(
Run the above. The second test contains an improperly closed block. Notice that the second print statement prints out: [[' one [ two '], [' etc. ']]
The first parsed token contains an opening "[". But I want this to be an error.
The <cut> concept provides an easy way to do that. If I could do something like this:
bracketBlock ::= <bracket1> <cut> <blockContent "]">:x <bracket2> => x
then an opening bracket that is not eventually followed by a matching closing bracket (before its enclosing syntax ends) is an error.
Well this test isn't set up quite right because testOK doesn't produce the right output. I can fix this up if you need a better test to get the idea.