Re: [Pyparsing] Parsing object structure
Brought to you by:
ptmcg
From: Paul M. <pt...@au...> - 2012-09-18 12:22:58
|
In your definition of 'text', you only match a single word - "name={LAN SIDE}" contains a text value with whitespace, more than one word. Also, beware of making 'text' match too much, you may end up including your trailing '}' as part of the text (as you will with your current definition of text as "Word(printables)"). -- Paul -----Original Message----- From: Claus Rosenberger [mailto:cla...@ro...] Sent: Tuesday, September 18, 2012 3:13 AM To: pyp...@li... Subject: [Pyparsing] Parsing object structure Hi, i try to parse an object structure which is using open and close tags and containing lists of another objects. Example: NetSet{ name={LAN SIDE} oid={123998333,723663,2625521122} readOnly={0} origin={} global={0} comment={Voice Server UC} list={ NetEntry{ name={} readOnly={0} origin={} global={0} comment={} addr={192.169.0.0/24} } } neglist={ } } I tried to start with following code structure and don't know if it makes sense or not. from pyparsing import * LBRACE,RBRACE,SEMI,EQ,PCT = map(Suppress,"{};=%") comment = SEMI + restOfLine keyName = Word(alphas) text = Word( alphanums, "-", ",") text = Word(printables) num = Word(nums) ip = Combine(Word(nums) + ('.' + Word(nums))*3) v_text = keyName + EQ + LBRACE + Optional(text) + RBRACE v_num = keyName + EQ + LBRACE + Optional(num) + RBRACE v_ip = keyName + EQ + LBRACE + Optional(ip) + RBRACE NETENTRY = ( "NetEntry" + LBRACE + ZeroOrMore(Group(v_text | v_num | v_ip)) + RBRACE ) NETSET_PLIST = ( "list" + EQ + LBRACE + ZeroOrMore(NETENTRY) + RBRACE ) NETSET_NLIST = "neglist" + EQ + LBRACE + ZeroOrMore(Group(NETENTRY)) + RBRACE NETSET = "NetSet" + LBRACE + ZeroOrMore(Group(v_text | v_num | NETSET_PLIST | NETSET_NLIST)) + RBRACE rule_ref = NETSET for mr in rule_ref.parseFile("sample"): print mr I get following result: pyparsing.ParseException: Expected "}" (at char 48), (line:2, col:25) It seems NETSET_PLIST does not work, perhaps my code is the wrong approach. Thanks a lot Claus ---------------------------------------------------------------------------- -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users |