/src/Python-3.8.3/Parser/grammar1.c
Line | Count | Source (jump to first uncovered line) |
1 | | |
2 | | /* Grammar subroutines needed by parser */ |
3 | | |
4 | | #include "Python.h" |
5 | | #include "grammar.h" |
6 | | #include "token.h" |
7 | | |
8 | | /* Return the DFA for the given type */ |
9 | | |
10 | | const dfa * |
11 | | PyGrammar_FindDFA(grammar *g, int type) |
12 | 10.1k | { |
13 | | /* Massive speed-up */ |
14 | 10.1k | const dfa *d = &g->g_dfa[type - NT_OFFSET]; |
15 | 10.1k | assert(d->d_type == type); |
16 | 10.1k | return d; |
17 | 10.1k | } |
18 | | |
19 | | const char * |
20 | | PyGrammar_LabelRepr(label *lb) |
21 | 0 | { |
22 | 0 | static char buf[100]; |
23 | |
|
24 | 0 | if (lb->lb_type == ENDMARKER) |
25 | 0 | return "EMPTY"; |
26 | 0 | else if (ISNONTERMINAL(lb->lb_type)) { |
27 | 0 | if (lb->lb_str == NULL) { |
28 | 0 | PyOS_snprintf(buf, sizeof(buf), "NT%d", lb->lb_type); |
29 | 0 | return buf; |
30 | 0 | } |
31 | 0 | else |
32 | 0 | return lb->lb_str; |
33 | 0 | } |
34 | 0 | else if (lb->lb_type < N_TOKENS) { |
35 | 0 | if (lb->lb_str == NULL) |
36 | 0 | return _PyParser_TokenNames[lb->lb_type]; |
37 | 0 | else { |
38 | 0 | PyOS_snprintf(buf, sizeof(buf), "%.32s(%.32s)", |
39 | 0 | _PyParser_TokenNames[lb->lb_type], lb->lb_str); |
40 | 0 | return buf; |
41 | 0 | } |
42 | 0 | } |
43 | 0 | else { |
44 | 0 | Py_FatalError("invalid label"); |
45 | 0 | return NULL; |
46 | 0 | } |
47 | 0 | } |