Re: [Pyparsing] Index operator
Brought to you by:
ptmcg
From: Paul M. <pt...@au...> - 2011-09-25 14:25:23
|
Are you using operatorPrecedence? If so, then expand the definition of the operand expression that you are passing in to handle the optional indexing. As Ralph Corderoy already pointed out, your index is probably going to be another arithmetic expression, so you will need to define operand in terms of the expression that will be defined using operand -> the arithmetic expression will have to be defined as a Forward. Something like this: arith_expr = Forward() operand = number | variable+Optional('[' + arith_expr + ']') arith_expr << operatorPrecedence(operand, [ ... operator definitions go here ... ]) If your evaluator does not use operatorPrecedence, but you have done your own grammar expansion, you'll have to reinterpret this suggestion in the context of your own grammar structure. -- Paul -----Original Message----- From: Will McGugan [mailto:wil...@gm...] Sent: Sunday, September 25, 2011 7:30 AM To: Pyp...@li... Subject: [Pyparsing] Index operator Hi, I have a custom expression evaluator that is working quite well, bit I'd like to implement an operator that works just like indexing a string or sequence in python. i.e. something[<expression>] I can't quite figure out how to do this. Can anyone give me any pointers? Thanks, Will McGugan -- Will McGugan http://www.willmcgugan.com ---------------------------------------------------------------------------- -- All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2dcopy2 _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users |