U AT^%c@s.ddlZddlmZmZGdddejZdS)N)grammartokenc@s,eZdZddZddZddZddZd S) ConvertercCs |||||dSN)parse_graminit_hparse_graminit_c finish_off)selfZ graminit_hZ graminit_cr */usr/lib64/python3.8/lib2to3/pgen2/conv.pyrun/s  z Converter.runc Csz t|}Wn8tk rD}ztd||fWYdSd}~XYnXi|_i|_d}|D]d}|d7}td|}|s|rtd|||fqZ|\}}t |}||j|<||j|<qZdS)NCan't open %s: %sFrz^#define\s+(\w+)\s+(\d+)$z%s(%s): can't parse %sT) openOSErrorprintZ symbol2numberZ number2symbolrematchZstripgroupsint) rfilenameferrlinenolinemosymbolnumberr r r r5s(       zConverter.parse_graminit_hc! Csz t|}Wn8tk rD}ztd||fWYdSd}~XYnXd}|dt|}}|dt|}}|dt|}}i}g}|dr|drJtd|}ttt | \} } } g} t | D]F} |dt|}}td|}ttt | \}}| ||fq|dt|}}| || | f<|dt|}}qtd|}ttt | \}}g}t |D]R} |dt|}}td |}ttt | \} } } || | f} | | qx| ||dt|}}|dt|}}q||_ i}td |}t |d}t |D]}|dt|}}td |}|d }ttt |dd dd\}}}}||}|dt|}}td|}i}t|d}t|D]@\}}t|}t dD]$}|d|>@rd||d|<qΐq||f||<q(|dt|}}||_g}|dt|}}td|}t |d}t |D]^}|dt|}}td|}| \}}t |}|dkrd}nt|}| ||fqX|dt|}}||_|dt|}}|dt|}}td|}t |d}|dt|}}|dt|}}td|}t |d}|dt|}}td|}t |d} | |_|dt|}}z|dt|}}Wntk rYnXdS)Nr Frr z static arc z)static arc arcs_(\d+)_(\d+)\[(\d+)\] = {$z\s+{(\d+), (\d+)},$z'static state states_(\d+)\[(\d+)\] = {$z\s+{(\d+), arcs_(\d+)_(\d+)},$zstatic dfa dfas\[(\d+)\] = {$z0\s+{(\d+), "(\w+)", (\d+), (\d+), states_(\d+),$iiiiz\s+("(?:\\\d\d\d)*")},$iz!static label labels\[(\d+)\] = {$z\s+{(\d+), (0|"\w+")},$Z0z \s+(\d+),$z\s+{(\d+), labels},$z \s+(\d+)$)rrrZnextZ startswithrrZlistZmaprrZrangeZappendstatesZgroupZeval enumerateZorddfaslabelsstartZ StopIteration)!rrrrrrZallarcsrrZnZmZkZarcsZ_ZiZjZsZtZstaterZndfasrrZxZyZzZfirstZ rawbitsetZcZbyter Znlabelsr!r r r rTs              "          zConverter.parse_graminit_ccCsXi|_i|_t|jD]<\}\}}|tjkr@|dk r@||j|<q|dkr||j|<qdSr)ZkeywordsZtokensrr rZNAME)rZilabelZtypeZvaluer r r rs zConverter.finish_offN)Z__name__Z __module__Z __qualname__r rrrr r r r r$s  &r)rZpgen2rrZGrammarrr r r r Zs