Commit c3899a9a authored by di68kap's avatar di68kap
Browse files

- windows compatibility of test_dsl.py (that old utf-8 probelm under windows!)

parent c721e133
......@@ -17,5 +17,6 @@ DEBUG*
LOGS/
external_resources/
tmp/*
test/tmp*
build/
dist/
......@@ -248,6 +248,7 @@ def load_compiler_suite(compiler_suite):
except ValueError as error:
raise AssertionError('File "' + compiler_suite + '" seems to be corrupted. '
'Please delete or repair file manually.')
# TODO: Compile in one step and pick parts from namespace later ?
scanner = compile_python_object(imports + scanner_py, 'get_\w*_scanner$')
ast = compile_python_object(imports + ast_py, 'get_\w*_transformer$')
compiler = compile_python_object(imports + compiler_py, 'get_\w*_compiler$')
......
......@@ -90,7 +90,7 @@ class EBNFGrammar(GrammarBase):
retrieveop = "::" | ":" # '::' pop, ':' retrieve
group = "(" expression §")"
regexchain = "<" expression §">" # compiles "expression" into a singular regular expression
regexchain = ">" expression §"<" # compiles "expression" into a singular regular expression
oneormore = "{" expression "}+"
repetition = "{" expression §"}"
option = "[" expression §"]"
......@@ -238,14 +238,12 @@ def get_ebnf_transformer():
########################################################################
SCANNER_FACTORY = '''
def get_{NAME}_scanner():
return {NAME}Scanner
'''
GRAMMAR_FACTORY = '''
def get_{NAME}_grammar():
global thread_local_{NAME}_grammar_singleton
try:
......@@ -258,14 +256,12 @@ def get_{NAME}_grammar():
TRANSFORMER_FACTORY = '''
def get_{NAME}_transformer():
return {NAME}Transform
'''
COMPILER_FACTORY = '''
def get_{NAME}_compiler(grammar_name="{NAME}",
grammar_source=""):
global thread_local_{NAME}_compiler_singleton
......@@ -366,6 +362,7 @@ class EBNFCompiler(CompilerBase):
def gen_parser(self, definitions):
# fix capture of variables that have been defined before usage [sic!]
if self.variables:
for i in range(len(definitions)):
if definitions[i][0] in self.variables:
......@@ -384,6 +381,7 @@ class EBNFCompiler(CompilerBase):
# prepare parser class header and docstring and
# add EBNF grammar to the doc string of the parser class
article = 'an ' if self.grammar_name[0:1] in "AaEeIiOoUu" else 'a ' # what about 'hour', 'universe' etc.?
declarations = ['class ' + self.grammar_name +
'Grammar(GrammarBase):',
......@@ -401,6 +399,7 @@ class EBNFCompiler(CompilerBase):
declarations.append('"""')
# add default functions for counterpart filters of pop or retrieve operators
for symbol in self.directives['counterpart']:
# declarations.append('def %s_counterpart(value): \n' % symbol +
# ' return value.replace("(", ")").replace("[", "]")'
......@@ -409,6 +408,7 @@ class EBNFCompiler(CompilerBase):
'.replace("[", "]").replace("{", "}").replace(">", "<")')
# turn definitions into declarations in reverse order
self.root = definitions[0][0] if definitions else ""
definitions.reverse()
declarations += [symbol + ' = Forward()'
......
......@@ -60,7 +60,7 @@ class TestCompilerGeneration:
WSPC = /\s+/
"""
tmp = 'tmp/' if os.path.isdir('tmp') else ('test/tmp/')
trivial_text = """Es war ein König in Thule."""
trivial_text = u"""Es war ein Koenig in Thule."""
grammar_name = tmp + "TestCompilerGeneration.ebnf"
compiler_name = tmp + "TestCompilerGeneration_compiler.py"
text_name = tmp + "TestCompilerGeneration_text.txt"
......
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