[SimpleParse] How to do use "!" (Error on fail - cut)
Brought to you by:
mcfletch
|
From: Martin d'A. <Mar...@s2...> - 2003-07-16 18:58:41
|
Hi,
There is not much activity here, I hope there is someone watching! I am
really struggling with the "!" Error on fail (cut), I hope someone can
help me.
I keep getting an 'Expected syntax: builddecl' error when I run the
following. I know I am getting it because I introduced a "!" after
'builddecl', but I don't understand why it would be an error. Maybe my
EBNF is all wrong. I have supplied the shortest example I could create
that reproduces the problem below. Thanks in advance to anyone who can
help!
I have the following EBNF definition in a file called biz.def:
file := ts, section, ts, section*
<ts> := ( [ \011-\015]+ / hash_comment )*
<ws> := [ \t]
section := builddecl!,elementdecl!,elementdecl*
builddecl := ws*,'build',ws+,name,ws+,'on',ws+,planet,ts
elementdecl := ws*,'element',ws*,'=',ws*,item,ws+,'is',ws+,quality,ts
name := identifier
planet := identifier
item := identifier
quality := identifier
identifier := [a-zA-Z_],[a-zA-Z0-9_]*
I have the following text I try to parse with it:
# this is the file I try to parse
build cars on pluto
element = door is red
element = seats is leather
And here is the program to parse it:
import os
from sys import stdin, stdout, stderr
from simpleparse import generator
import simpleparse.common.comments
import simpleparse.common.numbers
from mx.TextTools import TextTools
import pprint
input = stdin.read()
decl = open('biz.def').read()
parser = generator.buildParser(decl).parserbyname('file')
taglist = TextTools.tag(input, parser)
pprint.pprint(taglist)
stderr.write('parsed %s chars of %s\n' % (taglist[-1], len(input)))
if taglist[-1] != len(input):
print "ERROR near line",input[:taglist[-1]].count('\n')
Thanks,
Martin d'Anjou
|