| 1 | # Copyright 2004-2005 Elemental Security, Inc. All Rights Reserved. |
| 2 | # Licensed to PSF under a Contributor Agreement. |
| 3 | """Convert graminit.[ch] spit out by pgen to Python code. |
| 4 | |
| 5 | Pgen is the Python parser generator. It is useful to quickly create a |
| 6 | parser from a grammar file in Python's grammar notation. But I don't |
| 7 | want my parsers to be written in C (yet), so I'm translating the |
| 8 | parsing tables to Python data structures and writing a Python parse |
| 9 | engine. |
| 10 | |
| 11 | Note that the token numbers are constants determined by the standard |
| 12 | Python tokenizer. The standard token module defines these numbers and |
| 13 | their names (the names are not used much). The token numbers are |
| 14 | hardcoded into the Python tokenizer and into pgen. A Python |
| 15 | implementation of the Python tokenizer is also available, in the |
| 16 | standard tokenize module. |
| 17 | |
| 18 | On the other hand, symbol numbers (representing the grammar's |
| 19 | non-terminals) are assigned by pgen based on the actual grammar |
| 20 | input. |
| 21 | |
| 22 | Note: this module is pretty much obsolete; the pgen module generates |
| 23 | equivalent grammar tables directly from the Grammar.txt input file |
| 24 | without having to invoke the Python pgen C program. |
| 25 | |
| 26 | """ |
| 27 | |
| 28 | # Python imports |
| 29 | import rescip-python python python-stdlib 3.11 re/__init__: |
| 30 | |
| 31 | # Local imports |
| 32 | from pgen2scip-python python yapf 0.43.0 pgen2/__init__: import grammarscip-python python yapf 0.43.0 `pgen2.grammar`/__init__: |
| 33 | from pgen2scip-python python yapf 0.43.0 pgen2/__init__: import tokenscip-python python yapf 0.43.0 `pgen2.token`/__init__: |
| 34 | |
| 35 | |
| 36 | class Converterscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#(grammarscip-python python yapf 0.43.0 `pgen2.grammar`/__init__:.Grammarscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.grammar`/Grammar#): |
| 37 | """Grammar subclass that reads classic pgen output files. |
| 38 | |
| 39 | The run() method reads the tables as produced by the pgen parser |
| 40 | generator, typically contained in two C files, graminit.h and |
| 41 | graminit.c. The other methods are for internal use only. |
| 42 | |
| 43 | See the base class for more documentation. |
| 44 | |
| 45 | """ |
| 46 | |
| 47 | def runscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#run().(selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#run().(self), graminit_hscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#run().(graminit_h), graminit_cscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#run().(graminit_c)): |
| 48 | """Load the grammar tables from the text files written by pgen.""" |
| 49 | selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#run().(self).parse_graminit_hscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_h().(graminit_hscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#run().(graminit_h)) |
| 50 | selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#run().(self).parse_graminit_cscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_c().(graminit_cscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#run().(graminit_c)) |
| 51 | selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#run().(self).finish_offscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#finish_off().() |
| 52 | |
| 53 | def parse_graminit_hscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_h().(selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_h().(self), filenamescip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_h().(filename)): |
| 54 | """Parse the .h file written by pgen. (Internal) |
| 55 | |
| 56 | This file is a sequence of #define statements defining the |
| 57 | nonterminals of the grammar as numbers. We build two tables |
| 58 | mapping the numbers to names and back. |
| 59 | |
| 60 | """ |
| 61 | try: |
| 62 | f = openscip-python python python-stdlib 3.11 builtins/open().(filenamescip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_h().(filename)) |
| 63 | except OSErrorscip-python python python-stdlib 3.11 builtins/OSError# as err: |
| 64 | printscip-python python python-stdlib 3.11 builtins/print().("Can't open %s: %s" % (filenamescip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_h().(filename), err)) |
| 65 | return False |
| 66 | selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_h().(self).symbol2numberscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#symbol2number. = {} |
| 67 | selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_h().(self).number2symbolscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#number2symbol. = {} |
| 68 | lineno = 0 |
| 69 | for line in f: |
| 70 | lineno += 1 |
| 71 | mo = rescip-python python python-stdlib 3.11 re/__init__:.matchscip-python python python-stdlib 3.11 re/match().(r'^#define\s+(\w+)\s+(\d+)$', line) |
| 72 | if not mo and line.stripscip-python python python-stdlib 3.11 builtins/str#strip().(): |
| 73 | printscip-python python python-stdlib 3.11 builtins/print().("%s(%s): can't parse %s" % (filenamescip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_h().(filename), lineno, line.stripscip-python python python-stdlib 3.11 builtins/str#strip().())) |
| 74 | else: |
| 75 | symbol, number = mo.groupsscip-python python python-stdlib 3.11 re/Match#groups().() |
| 76 | number = intscip-python python python-stdlib 3.11 builtins/int#(number) |
| 77 | assert symbol not in selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_h().(self).symbol2numberscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#symbol2number. |
| 78 | assert number not in selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_h().(self).number2symbolscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#number2symbol. |
| 79 | selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_h().(self).symbol2numberscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#symbol2number.[symbol] = number |
| 80 | selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_h().(self).number2symbolscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#number2symbol.[number] = symbol |
| 81 | return True |
| 82 | |
| 83 | def parse_graminit_cscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_c().(selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_c().(self), filenamescip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_c().(filename)): |
| 84 | """Parse the .c file written by pgen. (Internal) |
| 85 | |
| 86 | The file looks as follows. The first two lines are always this: |
| 87 | |
| 88 | #include "pgenheaders.h" |
| 89 | #include "grammar.h" |
| 90 | |
| 91 | After that come four blocks: |
| 92 | |
| 93 | 1) one or more state definitions |
| 94 | 2) a table defining dfas |
| 95 | 3) a table defining labels |
| 96 | 4) a struct defining the grammar |
| 97 | |
| 98 | A state definition has the following form: |
| 99 | - one or more arc arrays, each of the form: |
| 100 | static arc arcs_<n>_<m>[<k>] = { |
| 101 | {<i>, <j>}, |
| 102 | ... |
| 103 | }; |
| 104 | - followed by a state array, of the form: |
| 105 | static state states_<s>[<t>] = { |
| 106 | {<k>, arcs_<n>_<m>}, |
| 107 | ... |
| 108 | }; |
| 109 | |
| 110 | """ |
| 111 | try: |
| 112 | f = openscip-python python python-stdlib 3.11 builtins/open().(filenamescip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_c().(filename)) |
| 113 | except OSErrorscip-python python python-stdlib 3.11 builtins/OSError# as err: |
| 114 | printscip-python python python-stdlib 3.11 builtins/print().("Can't open %s: %s" % (filenamescip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_c().(filename), err)) |
| 115 | return False |
| 116 | # The code below essentially uses f's iterator-ness! |
| 117 | lineno = 0 |
| 118 | |
| 119 | # Expect the two #include lines |
| 120 | lineno, line = lineno + 1, nextscip-python python python-stdlib 3.11 builtins/next().(f) |
| 121 | assert line == '#include "pgenheaders.h"\n', (lineno, line) |
| 122 | lineno, line = lineno + 1, nextscip-python python python-stdlib 3.11 builtins/next().(f) |
| 123 | assert line == '#include "grammar.h"\n', (lineno, line) |
| 124 | |
| 125 | # Parse the state definitions |
| 126 | lineno, line = lineno + 1, nextscip-python python python-stdlib 3.11 builtins/next().(f) |
| 127 | allarcs = {} |
| 128 | states = [] |
| 129 | while line.startswithscip-python python python-stdlib 3.11 builtins/str#startswith().('static arc '): |
| 130 | while line.startswithscip-python python python-stdlib 3.11 builtins/str#startswith().('static arc '): |
| 131 | mo = rescip-python python python-stdlib 3.11 re/__init__:.matchscip-python python python-stdlib 3.11 re/match().(r'static arc arcs_(\d+)_(\d+)\[(\d+)\] = {$', line) |
| 132 | assert mo, (lineno, line) |
| 133 | n, m, k = listscip-python python python-stdlib 3.11 builtins/list#(mapscip-python python python-stdlib 3.11 builtins/map#(intscip-python python python-stdlib 3.11 builtins/int#, mo.groupsscip-python python python-stdlib 3.11 re/Match#groups().())) |
| 134 | arcs = [] |
| 135 | for _ in rangescip-python python python-stdlib 3.11 builtins/range#(k): |
| 136 | lineno, line = lineno + 1, nextscip-python python python-stdlib 3.11 builtins/next().(f) |
| 137 | mo = rescip-python python python-stdlib 3.11 re/__init__:.matchscip-python python python-stdlib 3.11 re/match().(r'\s+{(\d+), (\d+)},$', line) |
| 138 | assert mo, (lineno, line) |
| 139 | i, j = listscip-python python python-stdlib 3.11 builtins/list#(mapscip-python python python-stdlib 3.11 builtins/map#(intscip-python python python-stdlib 3.11 builtins/int#, mo.groupsscip-python python python-stdlib 3.11 re/Match#groups().())) |
| 140 | arcs.appendscip-python python python-stdlib 3.11 builtins/list#append().((i, j)) |
| 141 | lineno, line = lineno + 1, nextscip-python python python-stdlib 3.11 builtins/next().(f) |
| 142 | assert line == '};\n', (lineno, line) |
| 143 | allarcs[(n, m)] = arcs |
| 144 | lineno, line = lineno + 1, nextscip-python python python-stdlib 3.11 builtins/next().(f) |
| 145 | mo = rescip-python python python-stdlib 3.11 re/__init__:.matchscip-python python python-stdlib 3.11 re/match().(r'static state states_(\d+)\[(\d+)\] = {$', line) |
| 146 | assert mo, (lineno, line) |
| 147 | s, t = listscip-python python python-stdlib 3.11 builtins/list#(mapscip-python python python-stdlib 3.11 builtins/map#(intscip-python python python-stdlib 3.11 builtins/int#, mo.groupsscip-python python python-stdlib 3.11 re/Match#groups().())) |
| 148 | assert s == len(states), (lineno, line) |
| 149 | state = [] |
| 150 | for _ in rangescip-python python python-stdlib 3.11 builtins/range#(t): |
| 151 | lineno, line = lineno + 1, nextscip-python python python-stdlib 3.11 builtins/next().(f) |
| 152 | mo = rescip-python python python-stdlib 3.11 re/__init__:.matchscip-python python python-stdlib 3.11 re/match().(r'\s+{(\d+), arcs_(\d+)_(\d+)},$', line) |
| 153 | assert mo, (lineno, line) |
| 154 | k, n, m = listscip-python python python-stdlib 3.11 builtins/list#(mapscip-python python python-stdlib 3.11 builtins/map#(intscip-python python python-stdlib 3.11 builtins/int#, mo.groupsscip-python python python-stdlib 3.11 re/Match#groups().())) |
| 155 | arcs = allarcs[n, m] |
| 156 | assert k == len(arcs), (lineno, line) |
| 157 | state.appendscip-python python python-stdlib 3.11 builtins/list#append().(arcs) |
| 158 | states.appendscip-python python python-stdlib 3.11 builtins/list#append().(state) |
| 159 | lineno, line = lineno + 1, nextscip-python python python-stdlib 3.11 builtins/next().(f) |
| 160 | assert line == '};\n', (lineno, line) |
| 161 | lineno, line = lineno + 1, nextscip-python python python-stdlib 3.11 builtins/next().(f) |
| 162 | selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_c().(self).statesscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#states. = states |
| 163 | |
| 164 | # Parse the dfas |
| 165 | dfas = {} |
| 166 | mo = rescip-python python python-stdlib 3.11 re/__init__:.matchscip-python python python-stdlib 3.11 re/match().(r'static dfa dfas\[(\d+)\] = {$', line) |
| 167 | assert mo, (lineno, line) |
| 168 | ndfas = intscip-python python python-stdlib 3.11 builtins/int#(mo.groupscip-python python python-stdlib 3.11 re/Match#group().(1)) |
| 169 | for i in rangescip-python python python-stdlib 3.11 builtins/range#(ndfas): |
| 170 | lineno, line = lineno + 1, nextscip-python python python-stdlib 3.11 builtins/next().(f) |
| 171 | mo = rescip-python python python-stdlib 3.11 re/__init__:.matchscip-python python python-stdlib 3.11 re/match().(r'\s+{(\d+), "(\w+)", (\d+), (\d+), states_(\d+),$', line) |
| 172 | assert mo, (lineno, line) |
| 173 | symbol = mo.groupscip-python python python-stdlib 3.11 re/Match#group().(2) |
| 174 | number, x, y, z = listscip-python python python-stdlib 3.11 builtins/list#(mapscip-python python python-stdlib 3.11 builtins/map#(intscip-python python python-stdlib 3.11 builtins/int#, mo.groupscip-python python python-stdlib 3.11 re/Match#group().(1, 3, 4, 5))) |
| 175 | assert selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_c().(self).symbol2numberscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#symbol2number.[symbol] == number, (lineno, line) |
| 176 | assert selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_c().(self).number2symbolscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#number2symbol.[number] == symbol, (lineno, line) |
| 177 | assert x == 0, (lineno, line) |
| 178 | state = states[z] |
| 179 | assert y == len(state), (lineno, line) |
| 180 | lineno, line = lineno + 1, nextscip-python python python-stdlib 3.11 builtins/next().(f) |
| 181 | mo = rescip-python python python-stdlib 3.11 re/__init__:.matchscip-python python python-stdlib 3.11 re/match().(r'\s+("(?:\\\d\d\d)*")},$', line) |
| 182 | assert mo, (lineno, line) |
| 183 | first = {} |
| 184 | rawbitset = eval(mo.groupscip-python python python-stdlib 3.11 re/Match#group().(1)) |
| 185 | for i, c in enumeratescip-python python python-stdlib 3.11 builtins/enumerate#(rawbitset): |
| 186 | byte = ord(c) |
| 187 | for j in rangescip-python python python-stdlib 3.11 builtins/range#(8): |
| 188 | if byte & (1 << j): |
| 189 | first[i * 8 + j] = 1 |
| 190 | dfas[number] = (state, first) |
| 191 | lineno, line = lineno + 1, nextscip-python python python-stdlib 3.11 builtins/next().(f) |
| 192 | assert line == '};\n', (lineno, line) |
| 193 | selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_c().(self).dfasscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#dfas. = dfas |
| 194 | |
| 195 | # Parse the labels |
| 196 | labels = [] |
| 197 | lineno, line = lineno + 1, nextscip-python python python-stdlib 3.11 builtins/next().(f) |
| 198 | mo = rescip-python python python-stdlib 3.11 re/__init__:.matchscip-python python python-stdlib 3.11 re/match().(r'static label labels\[(\d+)\] = {$', line) |
| 199 | assert mo, (lineno, line) |
| 200 | nlabels = intscip-python python python-stdlib 3.11 builtins/int#(mo.groupscip-python python python-stdlib 3.11 re/Match#group().(1)) |
| 201 | for i in rangescip-python python python-stdlib 3.11 builtins/range#(nlabels): |
| 202 | lineno, line = lineno + 1, nextscip-python python python-stdlib 3.11 builtins/next().(f) |
| 203 | mo = rescip-python python python-stdlib 3.11 re/__init__:.matchscip-python python python-stdlib 3.11 re/match().(r'\s+{(\d+), (0|"\w+")},$', line) |
| 204 | assert mo, (lineno, line) |
| 205 | x, y = mo.groupsscip-python python python-stdlib 3.11 re/Match#groups().() |
| 206 | x = intscip-python python python-stdlib 3.11 builtins/int#(x) |
| 207 | if y == '0': |
| 208 | y = None |
| 209 | else: |
| 210 | y = eval(y) |
| 211 | labels.appendscip-python python python-stdlib 3.11 builtins/list#append().((x, y)) |
| 212 | lineno, line = lineno + 1, nextscip-python python python-stdlib 3.11 builtins/next().(f) |
| 213 | assert line == '};\n', (lineno, line) |
| 214 | selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_c().(self).labelsscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#labels. = labels |
| 215 | |
| 216 | # Parse the grammar struct |
| 217 | lineno, line = lineno + 1, nextscip-python python python-stdlib 3.11 builtins/next().(f) |
| 218 | assert line == 'grammar _PyParser_Grammar = {\n', (lineno, line) |
| 219 | lineno, line = lineno + 1, nextscip-python python python-stdlib 3.11 builtins/next().(f) |
| 220 | mo = rescip-python python python-stdlib 3.11 re/__init__:.matchscip-python python python-stdlib 3.11 re/match().(r'\s+(\d+),$', line) |
| 221 | assert mo, (lineno, line) |
| 222 | ndfas = intscip-python python python-stdlib 3.11 builtins/int#(mo.groupscip-python python python-stdlib 3.11 re/Match#group().(1)) |
| 223 | assert ndfas == len(selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_c().(self).dfasscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#dfas.) |
| 224 | lineno, line = lineno + 1, nextscip-python python python-stdlib 3.11 builtins/next().(f) |
| 225 | assert line == '\tdfas,\n', (lineno, line) |
| 226 | lineno, line = lineno + 1, nextscip-python python python-stdlib 3.11 builtins/next().(f) |
| 227 | mo = rescip-python python python-stdlib 3.11 re/__init__:.matchscip-python python python-stdlib 3.11 re/match().(r'\s+{(\d+), labels},$', line) |
| 228 | assert mo, (lineno, line) |
| 229 | nlabels = intscip-python python python-stdlib 3.11 builtins/int#(mo.groupscip-python python python-stdlib 3.11 re/Match#group().(1)) |
| 230 | assert nlabels == len(selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_c().(self).labelsscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#labels.), (lineno, line) |
| 231 | lineno, line = lineno + 1, nextscip-python python python-stdlib 3.11 builtins/next().(f) |
| 232 | mo = rescip-python python python-stdlib 3.11 re/__init__:.matchscip-python python python-stdlib 3.11 re/match().(r'\s+(\d+)$', line) |
| 233 | assert mo, (lineno, line) |
| 234 | start = intscip-python python python-stdlib 3.11 builtins/int#(mo.groupscip-python python python-stdlib 3.11 re/Match#group().(1)) |
| 235 | assert start in selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_c().(self).number2symbolscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#number2symbol., (lineno, line) |
| 236 | selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#parse_graminit_c().(self).startscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#start. = start |
| 237 | lineno, line = lineno + 1, nextscip-python python python-stdlib 3.11 builtins/next().(f) |
| 238 | assert line == '};\n', (lineno, line) |
| 239 | try: |
| 240 | lineno, line = lineno + 1, nextscip-python python python-stdlib 3.11 builtins/next().(f) |
| 241 | except StopIterationscip-python python python-stdlib 3.11 builtins/StopIteration#: |
| 242 | pass |
| 243 | else: |
| 244 | assert 0, (lineno, line) |
| 245 | |
| 246 | def finish_offscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#finish_off().(selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#finish_off().(self)): |
| 247 | """Create additional useful structures. (Internal).""" |
| 248 | selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#finish_off().(self).keywordsscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#keywords. = {} # map from keyword strings to arc labels |
| 249 | selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#finish_off().(self).tokensscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#tokens. = {} # map from numeric token values to arc labels |
| 250 | for ilabel, (typescip-python python python-stdlib 3.11 builtins/type#, value) in enumeratescip-python python python-stdlib 3.11 builtins/enumerate#(selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#finish_off().(self).labelsscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#labels.): |
| 251 | if typescip-python python python-stdlib 3.11 builtins/type# == tokenscip-python python yapf 0.43.0 `pgen2.token`/__init__:.NAMEscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.token`/NAME. and value is not None: |
| 252 | selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#finish_off().(self).keywordsscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#keywords.[value] = ilabel |
| 253 | elif value is None: |
| 254 | selfscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#finish_off().(self).tokensscip-python python yapf 0.43.0 `third_party.yapf_third_party._ylib2to3.pgen2.conv`/Converter#tokens.[typescip-python python python-stdlib 3.11 builtins/type#] = ilabel |