def _create_parser(cls): """ Need to check the specific symbol "/" in attr_value part as well. I checked some multipath configuraion files from the sosreport and got although there are some more specific symbols like "-%", it is enclosed in double quotes and will be accepted. Furthermore, I also checked the source code of "device-mapper-multipath" and got if the attr_value in "multipath.conf" include a "whitespace", it must be enclosed in double quotation marks. So, we could just add one more specific symbol "/" to check. ---------------------------------------------------------- udev_dir /dev getuid_callout "/sbin/scsi_id -g -u -s /block/%n" ---------------------------------------------------------- """ section_name = p.Word(p.alphas + "_") attr_name = attr_value = p.Word(p.alphanums + "_/") LBRACE, RBRACE = map(p.Suppress, "{}") attr = p.Group(attr_name + (attr_value | p.quotedString.setParseAction(p.removeQuotes))) attr_list = p.Dict(p.ZeroOrMore(attr)) simple_section = p.Group(section_name + LBRACE + attr_list + RBRACE) complex_section = p.Group(section_name + LBRACE + p.OneOrMore(simple_section) + RBRACE) simple_or_complex = p.Dict(simple_section | complex_section) my_conf = p.Group(p.ZeroOrMore(simple_or_complex)) my_conf.ignore("#" + p.restOfLine) return my_conf
def erlblock_parser(): COMMA = p.Suppress(',') LBRACE, RBRACE = map(p.Suppress, "{}") LBRACKET, RBRACKET = map(p.Suppress, "[]") key = p.Word(p.alphas + '_') value_tnum = p.Word(p.nums + '.') value_tword = p.Word(p.alphanums + '/"-[]:.()') value_tstr = p.OneOrMore(value_tword) value_tdoustrs = value_tstr + COMMA + value_tstr value_tnumstr = value_tnum + value_tstr value = value_tdoustrs | value_tnumstr | value_tstr | value_tnum attr = LBRACE + p.Group(key + COMMA + value) + RBRACE attr_list = p.Dict(p.ZeroOrMore(attr + COMMA) + p.ZeroOrMore(attr)) block = LBRACKET + attr_list + RBRACKET value_plus = block | attr | value attr = LBRACE + p.Group(key + COMMA + value_plus) + RBRACE attr_list = p.Dict(p.OneOrMore(attr + COMMA) + p.OneOrMore(attr)) block = LBRACKET + attr_list + RBRACKET return block