[Pyparsing] Newby question about ignore
Brought to you by:
ptmcg
From: Kees B. <kee...@al...> - 2007-12-12 13:45:54
|
Hi, Here is a simple example. Maybe I'm doing something silly. There are two attempts to catch and ignore certain lines with '='. In the example goal1.ignore I want to ignore lines with just equal-sign. The result is: Expected W:(abcd...) (at char 0), (line:1, col:1) Another attempt is goal2.ignore to ignore lines that start with '=' and then ignore the rest. The result is: Expected W:(abcd...) (at char 33), (line:2, col:1) Can anyone tell me what's wrong with these two examples? TIA, Kees #! /usr/bin/env python # -*- coding: utf-8 -*- from pyparsing import * goal1 = OneOrMore( Word(alphanums) ) goal1.ignore( OneOrMore( Literal('=') ) + lineEnd ) goal2 = OneOrMore( Word(alphanums) ) goal2.ignore( lineStart + Literal('==') + restOfLine ) dump_txt = '''\ ================================ == .debug_info section index 61 ================================ DWCHECK REMARK bla bla ''' def parse_it(): # Make this goal1 or goal2 result = goal1.parseString(dump_txt) if result: from pprint import pprint pprint( result.asList() ) def main(): parse_it() if __name__ == "__main__": try: main() except SystemExit, e: print e except Exception, e: print e |