Python Pyparsing Optional field -
i using pyparsing module create own interpreter. current code
import pyparsing pp # parse packet srcip,dstip,srcmac,dstmac identifier = pp.word(pp.alphas,pp.alphanums+'_') ipfield = pp.word(pp.nums,max=3) ipaddr = pp.combine(ipfield+"."+ipfield+"."+ipfield+"."+ipfield) hexint = pp.word(pp.hexnums,exact=2) macaddr = pp.combine(hexint+(":"+hexint)*5) ip = pp.combine(identifier+"="+ipaddr) mac = pp.combine(identifier+"="+macaddr) pkt = ip & ip & mac & mac arg = "createpacket<" + pp.optional(pkt) + ">" arg.parsestring("createpacket<srcip=192.168.1.3dstip=192.168.1.4srcmac=00:ff:ff:ff:ff:00>")
while run last line of code parse example string error follows:
file "<stdin>", line 1, in <module> file "/usr/lib/python2.7/dist-packages/pyparsing.py", line 1041, in parsestring raise exc pyparsing.parseexception: expected ">" (at char 13), (line:1, col:14)
can explain reason error?
Comments
Post a Comment