Commit 17b20862 authored by Robert Bradshaw's avatar Robert Bradshaw

Add option to use formal grammar.

parent c4c0acc5
......@@ -304,6 +304,13 @@ class Context(object):
s = PyrexScanner(f, source_desc, source_encoding = f.encoding,
scope = scope, context = self)
tree = Parsing.p_module(s, pxd, full_module_name)
if Options.formal_grammar:
try:
from ..Parser import ConcreteSyntaxTree
except ImportError:
raise RuntimeError(
"Formal grammer can only be used with compiled Cython with an available pgen.")
ConcreteSyntaxTree.p_module(source_filename)
finally:
f.close()
except UnicodeDecodeError, e:
......
......@@ -80,6 +80,9 @@ closure_freelist_size = 8
# Should tp_clear() set object fields to None instead of clearing them to NULL?
clear_to_none = True
# Should we try parsing files with the formal grammar (experimental)?
formal_grammar = True
# Declare compiler directives
directive_defaults = {
......
cdef extern from "graminit.c":
pass
def p_module(source):
print "Using formal grammar to parse", source
......@@ -4,6 +4,7 @@ try:
except ImportError:
from distutils.core import setup, Extension
import os
import subprocess
import sys
try:
......@@ -119,6 +120,30 @@ def compile_cython_modules(profile=False, compile_more=False, cython_with_refnan
"Cython.Compiler.Optimize",
])
from distutils.spawn import find_executable
from distutils.sysconfig import get_python_inc
pgen = find_executable(
'pgen', os.pathsep.join([os.environ['PATH'], os.path.join(get_python_inc(), '..', 'Parser')]))
if not pgen:
print "Unable to find pgen, not compiling formal grammar."
else:
parser_dir = os.path.join(os.path.dirname(__file__), 'Cython', 'Parser')
print ' '.join([
pgen,
os.path.join(get_python_inc(), '..', 'Grammar', 'Grammar'),
os.path.join(parser_dir, 'graminit.h'),
os.path.join(parser_dir, 'graminit.c'),
])
subprocess.check_call([
pgen,
os.path.join(get_python_inc(), '..', 'Grammar', 'Grammar'),
os.path.join(parser_dir, 'graminit.h'),
os.path.join(parser_dir, 'graminit.c'),
])
compiled_modules.extend([
"Cython.Parser.ConcreteSyntaxTree",
])
defines = []
if cython_with_refnanny:
defines.append(('CYTHON_REFNANNY', '1'))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment