: . , , . , , Parcon:
from pprint import pprint
from parcon import (Forward, SignificantLiteral, Word, alphanum_chars, Exact,
ZeroOrMore, CharNotIn, concat, OneOrMore)
block = Forward()
hyphen = SignificantLiteral('"')
word = Word(alphanum_chars + '/_.)')
value = word | Exact(hyphen + ZeroOrMore(CharNotIn('"')) + hyphen)[concat]
pair = word + '=' + value
flag = word
attribute = pair | flag | block
head = word
body = ZeroOrMore(attribute)
block << '{' + head + body + '}'
blocks = OneOrMore(block)
with open('<your file name>.txt') as infile:
pprint(blocks.parse_string(infile.read()))
:
[('NETLIST',
['topblock',
('VERSION', ['2', '0', '0']),
('CELL',
['topblock',
('PORT',
['gearshift_h',
'vpsf',
'vphreg',
'pwron_h',
'vinp',
'vref_out',
'vcntrl_out',
'gd',
'meas_vref',
'vb',
'vout',
'meas_vcntrl',
'reset_h',
'vinm']),
('INST',
[('XI21/Mdummy1', 'pch_18_mac'),
('TYPE', ['MOS']),
('PROP',
[('n', '"sctg_inv1x/pch_18_mac"'),
('Length', '0.152'),
('NFIN', '8')]),
('PIN',
[('vpsf', 'SRC'),
('gs_h', 'DRN'),
('vpsf', 'GATE'),
('vpsf', 'BULK')])]),
('INST',
...