Hello !
I am trying to understand pyparsing. Here is a little test program
to check Optional subclass:
from pyparsing import Word,nums,Liter al,Optional
lbrack=Literal( "[").suppress ()
rbrack=Literal( "]").suppress ()
ddot=Literal(": ").suppress ()
start = Word(nums+".")
step = Word(nums+".")
end = Word(nums+".")
sequence=lbrack +start+Optional (ddot+step)+ddo t+end+rbrack
tokens = sequence.parseS tring("[0:0.1:1]")
print tokens
tokens1 = sequence.parseS tring("[1:2]")
print tokens1
It works on tokens, but the error message is showed on
the second string ("[1:2]"). I don't get it. I did use
Optional for ddot and step so I guess they are optional.
Any hints what I am doing wrong?
The versions are pyparsing 1.1.2 and Python 2.3.3.
Thanks,
B.
I am trying to understand pyparsing. Here is a little test program
to check Optional subclass:
from pyparsing import Word,nums,Liter al,Optional
lbrack=Literal( "[").suppress ()
rbrack=Literal( "]").suppress ()
ddot=Literal(": ").suppress ()
start = Word(nums+".")
step = Word(nums+".")
end = Word(nums+".")
sequence=lbrack +start+Optional (ddot+step)+ddo t+end+rbrack
tokens = sequence.parseS tring("[0:0.1:1]")
print tokens
tokens1 = sequence.parseS tring("[1:2]")
print tokens1
It works on tokens, but the error message is showed on
the second string ("[1:2]"). I don't get it. I did use
Optional for ddot and step so I guess they are optional.
Any hints what I am doing wrong?
The versions are pyparsing 1.1.2 and Python 2.3.3.
Thanks,
B.
Comment