Regex pattern to split verilog path in different instances using Python -
i have software parses verilog paths , in charge of mapping such paths sequence of objects. problem find regular expression split verilog paths in sequences of instance names.
verilog paths sequences of verilog identifiers concatenated dots. each identifier instance name. "." relationship in a.b.c means that, in module hierarchy, parent , b 1 of children of a. c 1 of children of b.
each verilog path identifies unique instance in module hierarchy.
pseudocode:
verilog identifier verilog identifier b verilog identifier c
path instance c of parent b child of a:
a.b.c
now, issue verilog identifiers can sequence of "letters, digits, underscores (_) , dollar signs ($). first character of identifier can letter or underscore" stated in page: http://verilog.renerta.com/source/vrg00018.htm
with situation python able split path writing:
>>> path = "a.verilog.path" >>> print path.split(".") ['a', 'verilog', 'path']
unfortunately identifiers can escaped identifiers.
escaped identifiers start backslash , end space. within backslash , space can have character (except space), dots!
\an_escaped_identifier_that_ends_with_space \another-identifier,withsome.dots)insideit_ending_withspace
so things more complicated , cannot rely on split anymore. here's example:
verilog identifier identifier1 verilog identifier \escaped.identifier_2 verilog identifier identifier3
path instance identifier3 of parent \escaped.identifier_2 child of identifier1:
identifier1.\escaped.identifier_2 .identifier3
so, how can use python's re
module address possible verilog paths composed of arbitrary number of identifiers and/or escaped identifiers?
([a-z_][a-z0-9$_]*|\\\s* )
should match both regular , escaped identifiers.
Comments
Post a Comment