[Pyparsing] Forward() causing odd behaviour
Brought to you by:
ptmcg
From: cathal c. <cof...@gm...> - 2011-06-22 21:14:12
|
Hi everyone, I have found something very weird. When I type the below into my python console I get the following error: ParseException: Expected ")" (at char 3), (line:1, col:4) from pyparsing import * function = Forward() function = '#' + Word(nums) + Group(Literal('(') + Optional(function)) + Literal(')') function.parseString('#0(#1())', True) However, if I then re-enter everything accept the line: function = Forward() it works as I initially expected it to. from pyparsing import * function = '#' + Word(nums) + Group(Literal('(') + Optional(function)) + Literal(')') function.parseString('#0(#1())', True) Out[6]: (['#', '0', (['(', '#', '1', (['('], {}), ')'], {}), ')'], {}) How do I make this work without having to enter the first sequence and then the second sequence of modified statements? Kind regards, Cathal |