[Pyparsing] parsing issue
Brought to you by:
ptmcg
From: mammar <ma...@gm...> - 2011-11-01 12:16:42
|
Hi All, I am a newbie to parsing and pyparsing. Here is my problem input string could be one of the following: - an integer number(could be negative) - an integer number(could be negative) and STR1 and STR2 whereas STR1 is a single word(alphas only) whereas STR2 is a string of alphas with spaces in between words i wrote the following pyparsing code but both print statements are printing -1 only, what is wrong? A general question related to parsing and pyparsing, what should be the output if 1. pattern matched 2. pattern not matched from pyparsing import * #exmple input strings str1 = "-1" str2 = "-1 ENOENT (No such file or directory)" neg = Word("-", exact=1) returnCodeNum = Combine(neg + Word(nums)) returnCodeSymbol = Word(alphas) returnInfo = OneOrMore(Word(alphas)) returnCodeInfo = Combine("(" + returnInfo + ")") rv2 = Combine( returnCodeNum + returnCodeSymbol + returnCodeInfo ) rv = returnCodeNum | rv2 print rv.parseString(str1) print rv.parseString(str2) |