[Pyparsing] Parsing object structure
Brought to you by:
ptmcg
From: Claus R. <cla...@ro...> - 2012-09-18 08:30:59
|
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 |