[Pyparsing] [Fwd: 1. .suppress() does not work; 2. a new API call suggestion]
Brought to you by:
ptmcg
From: Victor P. <po...@na...> - 2015-07-27 21:46:28
|
Probably it is a bug in pyparsing, but most probably is my misunderstanding. Note that it uses modified pyparsing with new method .addCondition() (attached). When I run my script (attached): $ ./DuplicateRefs.py chap-filt.lyx it produces output like: ['name "chap-filt"'] In my opinion, it should instead produce ['chap-filt'] because I use .suppress() in my code. Sorry, that I package the data in a separate file, not in a string, but the real example file is long. What is wrong? How to make it to produce only label name (like 'chap -filt'), not like ['name "chap-filt"']? Additional issue: Because of peculiarity of the syntax of the .lyx file (attached) I analyze, I first split it into tokens and then parse the tokens themselves (with another parser). See for example: LabelNameLineParser = \ pyparsing.Keyword("name").suppress() + pyparsing.White(" ").suppress() + \ pyparsing.Literal('"').suppress() + pyparsing.CharsNotIn('"') + pyparsing.Literal('"').suppress() LabelNameLine = Line.copy().addCondition(lambda self, loc, toks: LabelNameLineParser.parseString(toks[0], True)) Maybe, we should introduce a shorter API for tasks like this? (I am unsure whether this situation is often enough to deserve a special API.) What is your opinion? What if I will write a patch which does this? will you use it? -- Victor Porton - http://portonvictor.org |