## Re: [Pyparsing] Index operator

 Re: [Pyparsing] Index operator From: Ralph Corderoy - 2011-09-25 13:11:54 ```Hi Will, > i.e. something[] > > I can't quite figure out how to do this. Can anyone give me any > pointers? Do you know of Forward()? http://pyparsing.wikispaces.com/file/view/SimpleCalc.py may help. What you want to do is similar to allowing parenthesis in an expression? Cheers, Ralph. ```

 [Pyparsing] Index operator From: Will McGugan - 2011-09-25 12:29:52 ```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[] 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 ```
 Re: [Pyparsing] Index operator From: Ralph Corderoy - 2011-09-25 13:11:54 ```Hi Will, > i.e. something[] > > I can't quite figure out how to do this. Can anyone give me any > pointers? Do you know of Forward()? http://pyparsing.wikispaces.com/file/view/SimpleCalc.py may help. What you want to do is similar to allowing parenthesis in an expression? Cheers, Ralph. ```
 Re: [Pyparsing] Index operator From: Paul McGuire - 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:willmcgugan@...] Sent: Sunday, September 25, 2011 7:30 AM To: Pyparsing-users@... 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[] 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 Pyparsing-users@... https://lists.sourceforge.net/lists/listinfo/pyparsing-users ```