pyparsing (errata)

Boštjan Jerko bostjan.jerko at mf.uni-lj.si
Fri May 14 00:06:27 EDT 2004


Paul, 

thanks for the explanation.

Boštjan

On Fri, 14 May 2004, ptmcg at austin.rr._bogus_.com spake:
>> Dang Griffith proposed one alternative construct, here's another, perhaps
>> more explicit:
>>     lbrack + ( ( ddot + step + ddot + end ) | (ddot + end) ) +
>>     rbrack
>>
> 
> should be:
>      lbrack + start + ( ( ddot + step + ddot + end ) | (ddot + end)
>      ) +
> rbrack
> 
>> Note that the order of the inner construct is important, so as to
>> not
> match
>> ddot+end before trying ddot+step+ddot+end; '|' is a greedy matching
>> operator, creating a MatchFirst object from pyparsing's class
>> library.
> You
>> could avoid this confusion by using '^', which generates an Or
>>     object: lbrack + ( (ddot + end) ^ ( ddot + step + ddot + end )
>>     ) + rbrack
> 
> should be:
>      lbrack + start + ( (ddot + end) ^ ( ddot + step + ddot + end )
>      ) +
> rbrack
> 
>> This will evaluate both subconstructs, and choose the longer of the
>> two.
>>
>> Or you can use another pyparsing helper, the delimited list
>>     lbrack + delimitedlist( Word(nums+"."), delim=":") + rbrack
> 
> at least this one is correct!  No, wait, I mis-cased delimitedList!
> should be:
>      lbrack + delimitedList( Word(nums+"."), delim=":") + rbrack
> 
>> This implicitly suppresses delimiters, so that all you will get
>> back are ["1","0.1","1"] in the first case and ["1","2"] in the
>> second.
>>
>> Happy pyparsing!
>> -- Paul
>>
>>
> Sorry for the sloppiness,
> -- Paul



More information about the Python-list mailing list