[Pyparsing] How to use StringEnd?
Brought to you by:
ptmcg
From: Robert P. <rob...@gm...> - 2005-04-10 09:13:22
|
pt...@au... wrote [Re: empty lines and restOfLine comments]: > Ok, here's an example using pyparsing's Dict. -- Paul [snip] > comment = Literal('/') + restOfLine > > lhs = Word( alphas, alphanums + "_" ) > rhs = Word( alphas, alphanums + "_." ) > EQUALS = Literal("=").suppress() > > assignment = LineStart() + lhs + EQUALS + rhs > > # use pyparsing Dict to create dict-like access to parsed results > grammar = Dict( OneOrMore( Group( assignment ) ) ) > grammar.ignore(comment) > > results = grammar.parseString( testdata ) [snip] Thank you! When I now append a nonsense line "xxx" to testdata, this is of course not consumed by the grammar. Since I need this case to be a parsing error, I tried to use grammar = Dict( OneOrMore( Group( assignment ) ) ) + StringEnd , but this gives me (in grammar.ignore(comment)): TypeError: unbound method ignore() must be called with StringEnd instance as first argument (got Suppress instance instead) . I have not found anything useful in the pyparsing examples, neither. So how can I ensure that the whole string is matched? -- Robert Pollak GPG Key ID: E66BE5B1 |