Optimistic apply method hits wall and can't tell ignorant developer why his grammar is wrong
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
PyMeta |
New
|
Undecided
|
Unassigned |
Bug Description
I'm reporting this bug in a form that's very specific to my case, but part of the reason I need to is because the library isn't giving me any feedback about what I'm doing wrong.
This is an example of the syntax, grammar and fail case I'm experiencing:
# -------
# START of code
# -------
from pymeta.grammar import OMeta
#
# Dictionary object in this namspace that our parsing
# actions will be able to affect
d_store = {}
#
# allows us to create the commands we want access to in a dict.
def cmd_dict(d_store):
"""Declares a bunch of functions in d_store and then
returns it. Note that the functions may choose to
affect d_store as they run, also."""
def call(fn_name, **rest):
return fn_name
def log(msg):
print msg
d_store['log'] = log
def tok_chr(a):
print 'hi, %s!'%a
return a
d_store[
d_store[
def inc_count():
d_store[
return d_store
nspace = cmd_dict(d_store)
#
# Create the (likely flawed) grammar
grammar="""
begin ::= '[' <sketch_rest>
sketch_rest ::= ']' | ( ~(']') <sketch_entry> )*
sketch_entry ::= '(' <delimited_
delimited_string ::= (<dqstring> | <sqstring>)
dqstring ::= <token '"'> (<escapedChar> | ~('"') <anything>)* <token '"'>
sqstring ::= <token '\''> (<escapedChar> | ~('\'') <anything>)* <token '\''>
escapedChar ::= '\\' ('n' => "\n"
ws ::= ' ' | '\t' | '\n'
ws1 ::= <ws>+:s
ws0 ::= <ws>*:s
"""
g_ob = OMeta.makeGramm
#
# Feed in the sketch
sketch="[('p', 'Watch these'), ('q', 'And these')]"
g = g_ob(sketch)
#
# Fails here
res_apply = g.apply('begin')
# -------
# END of code
# -------
The error I get back is this:
$ python test.py
Traceback (most recent call last):
File "test.py", line 60, in <module>
g_ob = OMeta.makeGramm
File "/usr/lib/
return g.parseGrammar(
File "/usr/lib/
res = self.apply(
File "/usr/lib/
return self._apply(r, ruleName, args)
File "/usr/lib/
[rule(), self.input])
File "/pymeta_
File "<string>", line 1, in <module>
File "/usr/lib/
code = compile(source, filename, "exec")
File "/pymeta_
return self.locals[
SyntaxError: invalid syntax
$
I completely expect it's because I've done something wrong, but the break is very opaque because of the way pymeta dies.