Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(99)

Unified Diff: Modules/parsermodule.c

Issue 3353: make built-in tokenizer available via Python C API
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Makefile.pre.in ('k') | Parser/acceler.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -33,7 +33,7 @@
#include "token.h" /* token definitions */
#include "grammar.h"
#include "parsetok.h"
- /* ISTERMINAL() / ISNONTERMINAL() */
+ /* PYTOK_ISTERMINAL() / PYTOK_ISNONTERMINAL() */
#undef Yield
#include "ast.h"
@@ -90,7 +90,7 @@ node2tuple(node *n,
return Py_None;
}
- if (ISNONTERMINAL(TYPE(n))) {
+ if (PYTOK_ISNONTERMINAL(TYPE(n))) {
int i;
result = mkseq(1 + NCH(n) + (TYPE(n) == encoding_decl));
@@ -116,7 +116,7 @@ node2tuple(node *n,
(void) addelem(result, i+1, w);
}
}
- else if (ISTERMINAL(TYPE(n))) {
+ else if (PYTOK_ISTERMINAL(TYPE(n))) {
result = mkseq(2 + lineno + col_offset);
if (result == NULL)
goto error;
@@ -269,7 +269,7 @@ parser_compare_nodes(node *left, node *r
if (TYPE(right) < TYPE(left))
return (1);
- if (ISTERMINAL(TYPE(left)))
+ if (PYTOK_ISTERMINAL(TYPE(left)))
return (strcmp(STR(left), STR(right)));
if (NCH(left) < NCH(right))
@@ -792,7 +792,7 @@ build_node_children(PyObject *tuple, nod
Py_XDECREF(elem);
return (0);
}
- if (ISTERMINAL(type)) {
+ if (PYTOK_ISTERMINAL(type)) {
Py_ssize_t len = PyObject_Size(elem);
PyObject *temp;
const char *temp_str;
@@ -855,7 +855,7 @@ build_node_children(PyObject *tuple, nod
(void) memcpy(strn, temp_str, len + 1);
Py_DECREF(temp);
}
- else if (!ISNONTERMINAL(type)) {
+ else if (!PYTOK_ISNONTERMINAL(type)) {
/*
* It has to be one or the other; this is an error.
* Raise an exception.
@@ -880,7 +880,7 @@ build_node_children(PyObject *tuple, nod
return NULL;
}
- if (ISNONTERMINAL(type)) {
+ if (PYTOK_ISNONTERMINAL(type)) {
node* new_child = CHILD(root, i - 1);
if (new_child != build_node_children(elem, new_child, line_num)) {
@@ -888,7 +888,7 @@ build_node_children(PyObject *tuple, nod
return (0);
}
}
- else if (type == NEWLINE) { /* It's true: we increment the */
+ else if (type == PYTOK_NEWLINE) { /* It's true: we increment the */
++(*line_num); /* line number *after* the newline! */
}
Py_XDECREF(elem);
@@ -907,7 +907,7 @@ build_node_tree(PyObject *tuple)
if (temp != NULL)
num = PyLong_AsLong(temp);
Py_XDECREF(temp);
- if (ISTERMINAL(num)) {
+ if (PYTOK_ISTERMINAL(num)) {
/*
* The tuple is simple, but it doesn't start with a start symbol.
* Raise an exception now and be done with it.
@@ -917,7 +917,7 @@ build_node_tree(PyObject *tuple)
PyErr_SetObject(parser_error, tuple);
Py_XDECREF(tuple);
}
- else if (ISNONTERMINAL(num)) {
+ else if (PYTOK_ISNONTERMINAL(num)) {
/*
* Not efficient, but that can be handled later.
*/
@@ -981,24 +981,24 @@ build_node_tree(PyObject *tuple)
*/
static int validate_terminal(node *terminal, int type, char *string);
-#define validate_ampersand(ch) validate_terminal(ch, AMPER, "&")
-#define validate_circumflex(ch) validate_terminal(ch, CIRCUMFLEX, "^")
-#define validate_colon(ch) validate_terminal(ch, COLON, ":")
-#define validate_comma(ch) validate_terminal(ch, COMMA, ",")
-#define validate_dedent(ch) validate_terminal(ch, DEDENT, "")
-#define validate_equal(ch) validate_terminal(ch, EQUAL, "=")
-#define validate_indent(ch) validate_terminal(ch, INDENT, (char*)NULL)
-#define validate_lparen(ch) validate_terminal(ch, LPAR, "(")
-#define validate_newline(ch) validate_terminal(ch, NEWLINE, (char*)NULL)
-#define validate_rparen(ch) validate_terminal(ch, RPAR, ")")
-#define validate_semi(ch) validate_terminal(ch, SEMI, ";")
-#define validate_star(ch) validate_terminal(ch, STAR, "*")
-#define validate_vbar(ch) validate_terminal(ch, VBAR, "|")
-#define validate_doublestar(ch) validate_terminal(ch, DOUBLESTAR, "**")
-#define validate_dot(ch) validate_terminal(ch, DOT, ".")
-#define validate_at(ch) validate_terminal(ch, AT, "@")
-#define validate_rarrow(ch) validate_terminal(ch, RARROW, "->")
-#define validate_name(ch, str) validate_terminal(ch, NAME, str)
+#define validate_ampersand(ch) validate_terminal(ch, PYTOK_AMPER, "&")
+#define validate_circumflex(ch) validate_terminal(ch, PYTOK_CIRCUMFLEX, "^")
+#define validate_colon(ch) validate_terminal(ch, PYTOK_COLON, ":")
+#define validate_comma(ch) validate_terminal(ch, PYTOK_COMMA, ",")
+#define validate_dedent(ch) validate_terminal(ch, PYTOK_DEDENT, "")
+#define validate_equal(ch) validate_terminal(ch, PYTOK_EQUAL, "=")
+#define validate_indent(ch) validate_terminal(ch, PYTOK_INDENT, (char*)NULL)
+#define validate_lparen(ch) validate_terminal(ch, PYTOK_LPAR, "(")
+#define validate_newline(ch) validate_terminal(ch, PYTOK_NEWLINE, (char*)NULL)
+#define validate_rparen(ch) validate_terminal(ch, PYTOK_RPAR, ")")
+#define validate_semi(ch) validate_terminal(ch, PYTOK_SEMI, ";")
+#define validate_star(ch) validate_terminal(ch, PYTOK_STAR, "*")
+#define validate_vbar(ch) validate_terminal(ch, PYTOK_VBAR, "|")
+#define validate_doublestar(ch) validate_terminal(ch, PYTOK_DOUBLESTAR, "**")
+#define validate_dot(ch) validate_terminal(ch, PYTOK_DOT, ".")
+#define validate_at(ch) validate_terminal(ch, PYTOK_AT, "@")
+#define validate_rarrow(ch) validate_terminal(ch, PYTOK_RARROW, "->")
+#define validate_name(ch, str) validate_terminal(ch, PYTOK_NAME, str)
#define VALIDATER(n) static int validate_##n(node *tree)
@@ -1117,7 +1117,7 @@ validate_repeating_list(node *tree, int
/* validate_class()
*
* classdef:
- * 'class' NAME ['(' testlist ')'] ':' suite
+ * 'class' PYTOK_NAME ['(' testlist ')'] ':' suite
*/
static int
validate_class(node *tree)
@@ -1128,7 +1128,7 @@ validate_class(node *tree)
if (res) {
res = (validate_name(CHILD(tree, 0), "class")
- && validate_ntype(CHILD(tree, 1), NAME)
+ && validate_ntype(CHILD(tree, 1), PYTOK_NAME)
&& validate_colon(CHILD(tree, nch - 2))
&& validate_suite(CHILD(tree, nch - 1)));
}
@@ -1219,7 +1219,7 @@ validate_parameters(node *tree)
*
* suite:
* simple_stmt
- * | NEWLINE INDENT stmt+ DEDENT
+ * | PYTOK_NEWLINE PYTOK_INDENT stmt+ PYTOK_DEDENT
*/
static int
validate_suite(node *tree)
@@ -1230,7 +1230,7 @@ validate_suite(node *tree)
if (res && (nch == 1))
res = validate_simple_stmt(CHILD(tree, 0));
else if (res) {
- /* NEWLINE INDENT stmt+ DEDENT */
+ /* PYTOK_NEWLINE PYTOK_INDENT stmt+ PYTOK_DEDENT */
res = (validate_newline(CHILD(tree, 0))
&& validate_indent(CHILD(tree, 1))
&& validate_stmt(CHILD(tree, 2))
@@ -1238,7 +1238,7 @@ validate_suite(node *tree)
if (res && (nch > 4)) {
int i = 3;
- --nch; /* forget the DEDENT */
+ --nch; /* forget the PYTOK_DEDENT */
for ( ; res && (i < nch); ++i)
res = validate_stmt(CHILD(tree, i));
}
@@ -1265,8 +1265,8 @@ validate_testlist_star_expr(node *tl)
/* validate either vfpdef or tfpdef.
- * vfpdef: NAME
- * tfpdef: NAME [':' test]
+ * vfpdef: PYTOK_NAME
+ * tfpdef: PYTOK_NAME [':' test]
*/
static int
validate_vfpdef(node *tree)
@@ -1289,7 +1289,7 @@ validate_vfpdef(node *tree)
}
/* '*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef] | '**' vfpdef
- * ..or tfpdef in place of vfpdef. vfpdef: NAME; tfpdef: NAME [':' test]
+ * ..or tfpdef in place of vfpdef. vfpdef: PYTOK_NAME; tfpdef: PYTOK_NAME [':' test]
*/
static int
validate_varargslist_trailer(node *tree, int start)
@@ -1301,7 +1301,7 @@ validate_varargslist_trailer(node *tree,
err_string("expected variable argument trailer for varargslist");
return 0;
}
- if (TYPE(CHILD(tree, start)) == STAR) {
+ if (TYPE(CHILD(tree, start)) == PYTOK_STAR) {
/*
* '*' [vfpdef]
*/
@@ -1317,19 +1317,19 @@ validate_varargslist_trailer(node *tree,
TYPE(CHILD(tree, start + 1)) == tfpdef)) {
res = (validate_comma(CHILD(tree, start++))
&& validate_vfpdef(CHILD(tree, start++)));
- if (res && start + 1 < nch && TYPE(CHILD(tree, start)) == EQUAL)
+ if (res && start + 1 < nch && TYPE(CHILD(tree, start)) == PYTOK_EQUAL)
res = (validate_equal(CHILD(tree, start++))
&& validate_test(CHILD(tree, start++)));
}
/*
* [',' '**' vfpdef]
*/
- if (res && start + 2 < nch && TYPE(CHILD(tree, start+1)) == DOUBLESTAR)
+ if (res && start + 2 < nch && TYPE(CHILD(tree, start+1)) == PYTOK_DOUBLESTAR)
res = (validate_comma(CHILD(tree, start++))
&& validate_doublestar(CHILD(tree, start++))
&& validate_vfpdef(CHILD(tree, start++)));
}
- else if (TYPE(CHILD(tree, start)) == DOUBLESTAR) {
+ else if (TYPE(CHILD(tree, start)) == PYTOK_DOUBLESTAR) {
/*
* '**' vfpdef
*/
@@ -1362,12 +1362,12 @@ validate_varargslist_trailer(node *tree,
* ('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] |
* '**' tfpdef)
* | tfpdef ['=' test] (',' tfpdef ['=' test])* [','])
- * tfpdef: NAME [':' test]
+ * tfpdef: PYTOK_NAME [':' test]
* varargslist: ((vfpdef ['=' test] ',')*
* ('*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef] |
* '**' vfpdef)
* | vfpdef ['=' test] (',' vfpdef ['=' test])* [','])
- * vfpdef: NAME
+ * vfpdef: PYTOK_NAME
*
*/
static int
@@ -1394,7 +1394,7 @@ validate_varargslist(node *tree)
/* validate (vfpdef ['=' test] ',')+ */
res = validate_vfpdef(ch);
++i;
- if (res && (i+2 <= nch) && TYPE(CHILD(tree, i)) == EQUAL) {
+ if (res && (i+2 <= nch) && TYPE(CHILD(tree, i)) == PYTOK_EQUAL) {
res = (validate_equal(CHILD(tree, i))
&& validate_test(CHILD(tree, i+1)));
if (res)
@@ -1404,7 +1404,7 @@ validate_varargslist(node *tree)
res = validate_comma(CHILD(tree, i));
++i;
}
- } else if (sym == DOUBLESTAR || sym == STAR) {
+ } else if (sym == PYTOK_DOUBLESTAR || sym == PYTOK_STAR) {
res = validate_varargslist_trailer(tree, i);
break;
} else {
@@ -1495,7 +1495,7 @@ validate_stmt(node *tree)
}
-/* small_stmt (';' small_stmt)* [';'] NEWLINE
+/* small_stmt (';' small_stmt)* [';'] PYTOK_NEWLINE
*
*/
static int
@@ -1509,7 +1509,7 @@ validate_simple_stmt(node *tree)
if (nch < 2)
res = validate_numnodes(tree, 2, "simple_stmt");
- --nch; /* forget the NEWLINE */
+ --nch; /* forget the PYTOK_NEWLINE */
if (res && is_even(nch))
res = validate_semi(CHILD(tree, --nch));
if (res && (nch > 2)) {
@@ -1771,7 +1771,7 @@ validate_import_as_name(node *tree)
}
-/* dotted_name: NAME ("." NAME)*
+/* dotted_name: PYTOK_NAME ("." PYTOK_NAME)*
*/
static int
validate_dotted_name(node *tree)
@@ -1790,7 +1790,7 @@ validate_dotted_name(node *tree)
}
-/* dotted_as_name: dotted_name [NAME NAME]
+/* dotted_as_name: dotted_name [PYTOK_NAME PYTOK_NAME]
*/
static int
validate_dotted_as_name(node *tree)
@@ -1862,7 +1862,7 @@ count_from_dots(node *tree)
{
int i;
for (i = 1; i < NCH(tree); i++)
- if (TYPE(CHILD(tree, i)) != DOT && TYPE(CHILD(tree, i)) != ELLIPSIS)
+ if (TYPE(CHILD(tree, i)) != PYTOK_DOT && TYPE(CHILD(tree, i)) != PYTOK_ELLIPSIS)
break;
return i - 1;
}
@@ -1884,12 +1884,12 @@ validate_import_from(node *tree)
&& (!havename || validate_dotted_name(CHILD(tree, ndots + 1)))
&& validate_name(CHILD(tree, offset + 1), "import");
- if (res && TYPE(CHILD(tree, offset + 2)) == LPAR)
+ if (res && TYPE(CHILD(tree, offset + 2)) == PYTOK_LPAR)
res = ((nch == offset + 5)
&& validate_lparen(CHILD(tree, offset + 2))
&& validate_import_as_names(CHILD(tree, offset + 3))
&& validate_rparen(CHILD(tree, offset + 4)));
- else if (res && TYPE(CHILD(tree, offset + 2)) != STAR)
+ else if (res && TYPE(CHILD(tree, offset + 2)) != PYTOK_STAR)
res = validate_import_as_names(CHILD(tree, offset + 2));
return (res);
}
@@ -1924,7 +1924,7 @@ validate_import_stmt(node *tree)
/* global_stmt:
*
- * 'global' NAME (',' NAME)*
+ * 'global' PYTOK_NAME (',' PYTOK_NAME)*
*/
static int
validate_global_stmt(node *tree)
@@ -1939,17 +1939,17 @@ validate_global_stmt(node *tree)
if (res)
res = (validate_name(CHILD(tree, 0), "global")
- && validate_ntype(CHILD(tree, 1), NAME));
+ && validate_ntype(CHILD(tree, 1), PYTOK_NAME));
for (j = 2; res && (j < nch); j += 2)
res = (validate_comma(CHILD(tree, j))
- && validate_ntype(CHILD(tree, j + 1), NAME));
+ && validate_ntype(CHILD(tree, j + 1), PYTOK_NAME));
return (res);
}
/* nonlocal_stmt:
*
- * 'nonlocal' NAME (',' NAME)*
+ * 'nonlocal' PYTOK_NAME (',' PYTOK_NAME)*
*/
static int
validate_nonlocal_stmt(node *tree)
@@ -1964,10 +1964,10 @@ validate_nonlocal_stmt(node *tree)
if (res)
res = (validate_name(CHILD(tree, 0), "nonlocal")
- && validate_ntype(CHILD(tree, 1), NAME));
+ && validate_ntype(CHILD(tree, 1), PYTOK_NAME));
for (j = 2; res && (j < nch); j += 2)
res = (validate_comma(CHILD(tree, j))
- && validate_ntype(CHILD(tree, j + 1), NAME));
+ && validate_ntype(CHILD(tree, j + 1), PYTOK_NAME));
return res;
}
@@ -2066,7 +2066,7 @@ validate_try(node *tree)
"Illegal number of children for try/%s node.", name);
}
/* Handle try/finally statement */
- if (res && (TYPE(CHILD(tree, pos)) == NAME) &&
+ if (res && (TYPE(CHILD(tree, pos)) == PYTOK_NAME) &&
(strcmp(STR(CHILD(tree, pos)), "finally") == 0)) {
res = (validate_numnodes(tree, 6, "try/finally")
&& validate_colon(CHILD(tree, 4))
@@ -2081,7 +2081,7 @@ validate_try(node *tree)
pos += 3;
}
/* skip else clause */
- if (res && pos < nch && (TYPE(CHILD(tree, pos)) == NAME) &&
+ if (res && pos < nch && (TYPE(CHILD(tree, pos)) == PYTOK_NAME) &&
(strcmp(STR(CHILD(tree, pos)), "else") == 0)) {
res = (validate_colon(CHILD(tree, pos + 1))
&& validate_suite(CHILD(tree, pos + 2)));
@@ -2110,7 +2110,7 @@ validate_except_clause(node *tree)
res = validate_test(CHILD(tree, 1));
if (res && (nch == 4))
res = (validate_name(CHILD(tree, 2), "as")
- && validate_ntype(CHILD(tree, 3), NAME));
+ && validate_ntype(CHILD(tree, 3), PYTOK_NAME));
return (res);
}
@@ -2229,20 +2229,20 @@ validate_comp_op(node *tree)
if (nch == 1) {
/*
* Only child will be a terminal with a well-defined symbolic name
- * or a NAME with a string of either 'is' or 'in'
+ * or a PYTOK_NAME with a string of either 'is' or 'in'
*/
tree = CHILD(tree, 0);
switch (TYPE(tree)) {
- case LESS:
- case GREATER:
- case EQEQUAL:
- case EQUAL:
- case LESSEQUAL:
- case GREATEREQUAL:
- case NOTEQUAL:
+ case PYTOK_LESS:
+ case PYTOK_GREATER:
+ case PYTOK_EQEQUAL:
+ case PYTOK_EQUAL:
+ case PYTOK_LESSEQUAL:
+ case PYTOK_GREATEREQUAL:
+ case PYTOK_NOTEQUAL:
res = 1;
break;
- case NAME:
+ case PYTOK_NAME:
res = ((strcmp(STR(tree), "in") == 0)
|| (strcmp(STR(tree), "is") == 0));
if (!res) {
@@ -2256,8 +2256,8 @@ validate_comp_op(node *tree)
}
}
else if ((res = validate_numnodes(tree, 2, "comp_op")) != 0) {
- res = (validate_ntype(CHILD(tree, 0), NAME)
- && validate_ntype(CHILD(tree, 1), NAME)
+ res = (validate_ntype(CHILD(tree, 0), PYTOK_NAME)
+ && validate_ntype(CHILD(tree, 1), PYTOK_NAME)
&& (((strcmp(STR(CHILD(tree, 0)), "is") == 0)
&& (strcmp(STR(CHILD(tree, 1)), "not") == 0))
|| ((strcmp(STR(CHILD(tree, 0)), "not") == 0)
@@ -2276,7 +2276,7 @@ validate_star_expr(node *tree)
if (!res) return res;
if (!validate_numnodes(tree, 2, "star_expr"))
return 0;
- return validate_ntype(CHILD(tree, 0), STAR) && \
+ return validate_ntype(CHILD(tree, 0), PYTOK_STAR) && \
validate_expr(CHILD(tree, 1));
}
@@ -2355,7 +2355,7 @@ validate_shift_expr(node *tree)
{
return (validate_ntype(tree, shift_expr)
&& validate_chain_two_ops(tree, validate_arith_expr,
- LEFTSHIFT, RIGHTSHIFT));
+ PYTOK_LEFTSHIFT, PYTOK_RIGHTSHIFT));
}
@@ -2363,7 +2363,7 @@ static int
validate_arith_expr(node *tree)
{
return (validate_ntype(tree, arith_expr)
- && validate_chain_two_ops(tree, validate_term, PLUS, MINUS));
+ && validate_chain_two_ops(tree, validate_term, PYTOK_PLUS, PYTOK_MINUS));
}
@@ -2377,10 +2377,10 @@ validate_term(node *tree)
&& validate_factor(CHILD(tree, 0)));
for ( ; res && (pos < nch); pos += 2)
- res = (((TYPE(CHILD(tree, pos)) == STAR)
- || (TYPE(CHILD(tree, pos)) == SLASH)
- || (TYPE(CHILD(tree, pos)) == DOUBLESLASH)
- || (TYPE(CHILD(tree, pos)) == PERCENT))
+ res = (((TYPE(CHILD(tree, pos)) == PYTOK_STAR)
+ || (TYPE(CHILD(tree, pos)) == PYTOK_SLASH)
+ || (TYPE(CHILD(tree, pos)) == PYTOK_DOUBLESLASH)
+ || (TYPE(CHILD(tree, pos)) == PYTOK_PERCENT))
&& validate_factor(CHILD(tree, pos + 1)));
return (res);
@@ -2397,9 +2397,9 @@ validate_factor(node *tree)
int nch = NCH(tree);
int res = (validate_ntype(tree, factor)
&& (((nch == 2)
- && ((TYPE(CHILD(tree, 0)) == PLUS)
- || (TYPE(CHILD(tree, 0)) == MINUS)
- || (TYPE(CHILD(tree, 0)) == TILDE))
+ && ((TYPE(CHILD(tree, 0)) == PYTOK_PLUS)
+ || (TYPE(CHILD(tree, 0)) == PYTOK_MINUS)
+ || (TYPE(CHILD(tree, 0)) == PYTOK_TILDE))
&& validate_factor(CHILD(tree, 1)))
|| ((nch == 1)
&& validate_power(CHILD(tree, 0)))));
@@ -2445,7 +2445,7 @@ validate_atom(node *tree)
res = validate_numnodes(tree, nch+1, "atom");
if (res) {
switch (TYPE(CHILD(tree, 0))) {
- case LPAR:
+ case PYTOK_LPAR:
res = ((nch <= 3)
&& (validate_rparen(CHILD(tree, nch - 1))));
@@ -2456,32 +2456,32 @@ validate_atom(node *tree)
res = validate_testlist_comp(CHILD(tree, 1));
}
break;
- case LSQB:
+ case PYTOK_LSQB:
if (nch == 2)
- res = validate_ntype(CHILD(tree, 1), RSQB);
+ res = validate_ntype(CHILD(tree, 1), PYTOK_RSQB);
else if (nch == 3)
res = (validate_testlist_comp(CHILD(tree, 1))
- && validate_ntype(CHILD(tree, 2), RSQB));
+ && validate_ntype(CHILD(tree, 2), PYTOK_RSQB));
else {
res = 0;
err_string("illegal list display atom");
}
break;
- case LBRACE:
+ case PYTOK_LBRACE:
res = ((nch <= 3)
- && validate_ntype(CHILD(tree, nch - 1), RBRACE));
+ && validate_ntype(CHILD(tree, nch - 1), PYTOK_RBRACE));
if (res && (nch == 3))
res = validate_dictorsetmaker(CHILD(tree, 1));
break;
- case NAME:
- case NUMBER:
- case ELLIPSIS:
+ case PYTOK_NAME:
+ case PYTOK_NUMBER:
+ case PYTOK_ELLIPSIS:
res = (nch == 1);
break;
- case STRING:
+ case PYTOK_STRING:
for (pos = 1; res && (pos < nch); ++pos)
- res = validate_ntype(CHILD(tree, pos), STRING);
+ res = validate_ntype(CHILD(tree, pos), PYTOK_STRING);
break;
default:
res = 0;
@@ -2531,7 +2531,7 @@ validate_testlist_comp(node *tree)
}
/* decorator:
- * '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
+ * '@' dotted_name [ '(' [arglist] ')' ] PYTOK_NEWLINE
*/
static int
validate_decorator(node *tree)
@@ -2606,7 +2606,7 @@ validate_with_stmt(node *tree)
return ok;
}
-/* funcdef: 'def' NAME parameters ['->' test] ':' suite */
+/* funcdef: 'def' PYTOK_NAME parameters ['->' test] ':' suite */
static int
validate_funcdef(node *tree)
@@ -2616,14 +2616,14 @@ validate_funcdef(node *tree)
if (res) {
if (nch == 5) {
res = (validate_name(CHILD(tree, 0), "def")
- && validate_ntype(CHILD(tree, 1), NAME)
+ && validate_ntype(CHILD(tree, 1), PYTOK_NAME)
&& validate_parameters(CHILD(tree, 2))
&& validate_colon(CHILD(tree, 3))
&& validate_suite(CHILD(tree, 4)));
}
else if (nch == 7) {
res = (validate_name(CHILD(tree, 0), "def")
- && validate_ntype(CHILD(tree, 1), NAME)
+ && validate_ntype(CHILD(tree, 1), PYTOK_NAME)
&& validate_parameters(CHILD(tree, 2))
&& validate_rarrow(CHILD(tree, 3))
&& validate_test(CHILD(tree, 4))
@@ -2745,7 +2745,7 @@ validate_arglist(node *tree)
ok = 0;
}
}
- else if (sym == STAR) {
+ else if (sym == PYTOK_STAR) {
ok = validate_star(CHILD(tree, i));
if (ok && (nch-i == 2))
ok = validate_test(CHILD(tree, i+1));
@@ -2759,7 +2759,7 @@ validate_arglist(node *tree)
ok = 0;
}
}
- else if (sym == DOUBLESTAR) {
+ else if (sym == PYTOK_DOUBLESTAR) {
if (nch-i == 2)
ok = (validate_doublestar(CHILD(tree, i))
&& validate_test(CHILD(tree, i+1)));
@@ -2803,7 +2803,7 @@ validate_argument(node *tree)
/* trailer:
*
- * '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
+ * '(' [arglist] ')' | '[' subscriptlist ']' | '.' PYTOK_NAME
*/
static int
validate_trailer(node *tree)
@@ -2813,19 +2813,19 @@ validate_trailer(node *tree)
if (res) {
switch (TYPE(CHILD(tree, 0))) {
- case LPAR:
+ case PYTOK_LPAR:
res = validate_rparen(CHILD(tree, nch - 1));
if (res && (nch == 3))
res = validate_arglist(CHILD(tree, 1));
break;
- case LSQB:
+ case PYTOK_LSQB:
res = (validate_numnodes(tree, 3, "trailer")
&& validate_subscriptlist(CHILD(tree, 1))
- && validate_ntype(CHILD(tree, 2), RSQB));
+ && validate_ntype(CHILD(tree, 2), PYTOK_RSQB));
break;
- case DOT:
+ case PYTOK_DOT:
res = (validate_numnodes(tree, 2, "trailer")
- && validate_ntype(CHILD(tree, 1), NAME));
+ && validate_ntype(CHILD(tree, 1), PYTOK_NAME));
break;
default:
res = 0;
@@ -2867,7 +2867,7 @@ validate_subscript(node *tree)
err_string("invalid number of arguments for subscript node");
return (0);
}
- if (TYPE(CHILD(tree, 0)) == DOT)
+ if (TYPE(CHILD(tree, 0)) == PYTOK_DOT)
/* take care of ('.' '.' '.') possibility */
return (validate_numnodes(tree, 3, "subscript")
&& validate_dot(CHILD(tree, 0))
@@ -2884,7 +2884,7 @@ validate_subscript(node *tree)
* but at least one of the optional components will
* be present, but we don't know which yet.
*/
- if ((TYPE(CHILD(tree, 0)) != COLON) || (nch == 4)) {
+ if ((TYPE(CHILD(tree, 0)) != PYTOK_COLON) || (nch == 4)) {
res = validate_test(CHILD(tree, 0));
offset = 1;
}
@@ -2974,7 +2974,7 @@ validate_dictorsetmaker(node *tree)
if (!res)
return 0;
- if (nch - i >= 2 && TYPE(CHILD(tree, i)) == COLON) {
+ if (nch - i >= 2 && TYPE(CHILD(tree, i)) == PYTOK_COLON) {
/* Dictionary display or dictionary comprehension. */
res = (validate_colon(CHILD(tree, i++))
&& validate_test(CHILD(tree, i++)));
@@ -3045,10 +3045,10 @@ validate_eval_input(node *tree)
int res = (validate_ntype(tree, eval_input)
&& (nch >= 2)
&& validate_testlist(CHILD(tree, 0))
- && validate_ntype(CHILD(tree, nch - 1), ENDMARKER));
+ && validate_ntype(CHILD(tree, nch - 1), PYTOK_ENDMARKER));
for (pos = 1; res && (pos < (nch - 1)); ++pos)
- res = validate_ntype(CHILD(tree, pos), NEWLINE);
+ res = validate_ntype(CHILD(tree, pos), PYTOK_NEWLINE);
return (res);
}
@@ -3258,7 +3258,7 @@ validate_expr_tree(node *tree)
/* file_input:
- * (NEWLINE | stmt)* ENDMARKER
+ * (PYTOK_NEWLINE | stmt)* PYTOK_ENDMARKER
*/
static int
validate_file_input(node *tree)
@@ -3266,7 +3266,7 @@ validate_file_input(node *tree)
int j;
int nch = NCH(tree) - 1;
int res = ((nch >= 0)
- && validate_ntype(CHILD(tree, nch), ENDMARKER));
+ && validate_ntype(CHILD(tree, nch), PYTOK_ENDMARKER));
for (j = 0; res && (j < nch); ++j) {
if (TYPE(CHILD(tree, j)) == stmt)
« no previous file with comments | « Makefile.pre.in ('k') | Parser/acceler.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+