ยปCore Development>Code coverage>Parser/grammar1.c

Python code coverage for Parser/grammar1.c

#countcontent
1n/a
2n/a/* Grammar subroutines needed by parser */
3n/a
4n/a#include "Python.h"
5n/a#include "pgenheaders.h"
6n/a#include "grammar.h"
7n/a#include "token.h"
8n/a
9n/a/* Return the DFA for the given type */
10n/a
11n/adfa *
12n/aPyGrammar_FindDFA(grammar *g, int type)
13n/a{
14n/a dfa *d;
15n/a#if 1
16n/a /* Massive speed-up */
17n/a d = &g->g_dfa[type - NT_OFFSET];
18n/a assert(d->d_type == type);
19n/a return d;
20n/a#else
21n/a /* Old, slow version */
22n/a int i;
23n/a
24n/a for (i = g->g_ndfas, d = g->g_dfa; --i >= 0; d++) {
25n/a if (d->d_type == type)
26n/a return d;
27n/a }
28n/a assert(0);
29n/a /* NOTREACHED */
30n/a#endif
31n/a}
32n/a
33n/aconst char *
34n/aPyGrammar_LabelRepr(label *lb)
35n/a{
36n/a static char buf[100];
37n/a
38n/a if (lb->lb_type == ENDMARKER)
39n/a return "EMPTY";
40n/a else if (ISNONTERMINAL(lb->lb_type)) {
41n/a if (lb->lb_str == NULL) {
42n/a PyOS_snprintf(buf, sizeof(buf), "NT%d", lb->lb_type);
43n/a return buf;
44n/a }
45n/a else
46n/a return lb->lb_str;
47n/a }
48n/a else if (lb->lb_type < N_TOKENS) {
49n/a if (lb->lb_str == NULL)
50n/a return _PyParser_TokenNames[lb->lb_type];
51n/a else {
52n/a PyOS_snprintf(buf, sizeof(buf), "%.32s(%.32s)",
53n/a _PyParser_TokenNames[lb->lb_type], lb->lb_str);
54n/a return buf;
55n/a }
56n/a }
57n/a else {
58n/a Py_FatalError("invalid label");
59n/a return NULL;
60n/a }
61n/a}