[Pyparsing] Parsing multiple items into the same Dict
Brought to you by:
ptmcg
From: George P. <ge...@ga...> - 2006-10-24 04:31:06
|
Hi all, Given the following: s = \ """ a.clk = "----____----____" a.rst = "--------________" b.clk = "____----____----" b.x = "________--------" """ TIMING_SPEC = OneOrMore(Regex('[-_]')) GROUPNAME = Word(alphanums) + Suppress('.') SIGNAME = Word(alphanums) + Suppress('=') GRAMMAR = ??? # -------- What would the grammar have to look like so I can get the following kind of parse results? In particular, I'm stuck on how to parse multiple items into the same dict. In this case, I want to have a dict containing GROUPNAMEs as keys. Each GROUPNAME dict contains one or more 'SIGNAME':TIMINGSPEC key/value pairs: >>>d = GRAMMAR.parseString(s).asDict() >>>d['a'].keys() ['clk', 'rst'] >>>d['b'].keys() ['clk', 'x'] >>>d['a']['clk'] ----____----____ >>>d['a']['rst'] --------________ >>>d['b']['clk'] ____----____---- >>>d['b']['x'] ________-------- Thanks, George |