bpo-40334: Fix build errors and warnings in test_peg_generator (GH-19672)

This commit is contained in:
Pablo Galindo 2020-04-23 12:42:13 +01:00 committed by GitHub
parent ee40e4b856
commit 1df5a9e88c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 2 deletions

View File

@ -640,6 +640,16 @@ _PyPegen_is_memoized(Parser *p, int type, void *pres)
return 0;
}
int
_PyPegen_lookahead_with_name(int positive, expr_ty (func)(Parser *), Parser *p)
{
int mark = p->mark;
void *res = func(p);
p->mark = mark;
return (res != NULL) == positive;
}
int
_PyPegen_lookahead_with_string(int positive, void *(func)(Parser *, const char *), Parser *p,
const char *arg)
@ -663,7 +673,7 @@ int
_PyPegen_lookahead(int positive, void *(func)(Parser *), Parser *p)
{
int mark = p->mark;
void *res = func(p);
void *res = (void*)func(p);
p->mark = mark;
return (res != NULL) == positive;
}

View File

@ -85,6 +85,7 @@ int _PyPegen_insert_memo(Parser *p, int mark, int type, void *node);
int _PyPegen_update_memo(Parser *p, int mark, int type, void *node);
int _PyPegen_is_memoized(Parser *p, int type, void *pres);
int _PyPegen_lookahead_with_name(int, expr_ty (func)(Parser *), Parser *);
int _PyPegen_lookahead_with_string(int, void *(func)(Parser *, const char *), Parser *, const char *);
int _PyPegen_lookahead_with_int(int, Token *(func)(Parser *, int), Parser *, int);
int _PyPegen_lookahead(int, void *(func)(Parser *), Parser *);

View File

@ -9,6 +9,7 @@ import distutils.log
from distutils.core import Distribution, Extension
from distutils.command.clean import clean # type: ignore
from distutils.command.build_ext import build_ext # type: ignore
from distutils.tests.support import fixup_build_ext
from pegen.c_generator import CParserGenerator
from pegen.grammar import Grammar
@ -69,6 +70,7 @@ def compile_c_extension(
]
dist = Distribution({"name": extension_name, "ext_modules": extension})
cmd = build_ext(dist)
fixup_build_ext(cmd)
cmd.inplace = True
if build_dir:
cmd.build_temp = build_dir

View File

@ -93,7 +93,9 @@ class CCallMakerVisitor(GrammarVisitor):
func, args = call.split("(", 1)
assert args[-1] == ")"
args = args[:-1]
if not args.startswith("p,"):
if "name_token" in call:
return None, f"_PyPegen_lookahead_with_name({positive}, {func}, {args})"
elif not args.startswith("p,"):
return None, f"_PyPegen_lookahead({positive}, {func}, {args})"
elif args[2:].strip().isalnum():
return None, f"_PyPegen_lookahead_with_int({positive}, {func}, {args})"