Commit 32e93e8f authored by di68kap's avatar di68kap

- compatibility fixes for windows and cython

parent d1948d19
......@@ -332,10 +332,10 @@ class Parser:
# otherwise also cache None-results
self.visited[location] = (None, rest)
else:
assert node._pos < 0 or node == EMPTY_NODE
# assert node._pos < 0 or node == EMPTY_NODE
node._pos = location
assert node._pos >= 0 or node == EMPTY_NODE, \
str("%i < %i" % (grammar.document_length__, location))
# assert node._pos >= 0 or node == EMPTY_NODE, \
# str("%i < %i" % (grammar.document_length__, location))
if (grammar.last_rb__loc__ < location
and (grammar.memoization__ or location in grammar.recursion_locations__)):
# - variable manipulating parsers will not be entered into the cache,
......@@ -387,13 +387,12 @@ class Parser:
@property
def grammar(self) -> 'Grammar':
try:
grammar = self._grammar
if self._grammar != GRAMMAR_PLACEHOLDER:
return self._grammar
else:
raise AssertionError('Grammar has not yet been set!')
except AttributeError:
raise AssertionError('Parser placeholder does not have a grammar!')
except (AttributeError, NameError):
raise AttributeError('Parser placeholder does not have a grammar!')
@grammar.setter
def grammar(self, grammar: 'Grammar'):
......@@ -406,6 +405,8 @@ class Parser:
"to a different Grammar object!")
except AttributeError:
pass # ignore setting of grammar attribute for placeholder parser
except NameError: # Cython: No access to GRAMMA_PLACEHOLDER, yet :-(
self._grammar = grammar
# def _grammar_assigned_notifier(self):
# """A function that notifies the parser object that it has been
......
......@@ -515,6 +515,7 @@ def grammar_suite(directory, parser_factory, transformer_factory,
if any(fnmatch.fnmatch(filename, pattern) for pattern in fn_patterns):
parameters = filename, parser_factory, transformer_factory, report, verbose
errata_futures.append((filename, pool.submit(grammar_unit, *parameters)))
# grammar_unit(*parameters)
for filename, err_future in errata_futures:
try:
errata = err_future.result()
......
......@@ -23,27 +23,27 @@ import sys
sys.path.extend(['../../', '../'])
import DHParser.log
import DHParser.dsl
from DHParser import testing
from DHParser import toolkit
if not DHParser.dsl.recompile_grammar('BibTeX.ebnf', force=False): # recompiles Grammar only if it has changed
print('\nErrors while recompiling "BibTeX.ebnf":\n--------------------------------------\n\n')
with open('BibTeX_ebnf_ERRORS.txt') as f:
print(f.read())
sys.exit(1)
sys.path.append('./')
# must be appended after module creation, because otherwise an ImportError is raised under Windows
from BibTeXCompiler import get_grammar, get_transformer
with DHParser.log.logging(True):
error_report = testing.grammar_suite('grammar_tests', get_grammar,
get_transformer, report=True, verbose=True)
if error_report:
print('\n')
print(error_report)
sys.exit(1)
else:
print('\nSUCCESS! All tests passed :-)')
if __name__ == "__main__":
if not DHParser.dsl.recompile_grammar('BibTeX.ebnf', force=False): # recompiles Grammar only if it has changed
print('\nErrors while recompiling "BibTeX.ebnf":\n--------------------------------------\n\n')
with open('BibTeX_ebnf_ERRORS.txt') as f:
print(f.read())
sys.exit(1)
sys.path.append('./')
# must be appended after module creation, because otherwise an ImportError is raised under Windows
from BibTeXCompiler import get_grammar, get_transformer
with DHParser.log.logging(True):
error_report = testing.grammar_suite('grammar_tests', get_grammar,
get_transformer, report=True, verbose=True)
if error_report:
print('\n')
print(error_report)
sys.exit(1)
else:
print('\nSUCCESS! All tests passed :-)')
......@@ -26,7 +26,7 @@ setup(
'DHParser/compile.py',
'DHParser/ebnf.py',
],
nthreads=4, annotate=False),
nthreads=0, annotate=False),
url='https://gitlab.lrz.de/badw-it/DHParser',
license='[Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0)',
author='Eckhart Arnold',
......
......@@ -41,7 +41,7 @@ if __name__ == "__main__":
interpreters = ['python.exe ']
cwd = os.getcwd()
os.chdir(scriptdir + '/..')
os.chdir(os.path.join(scriptdir, '..'))
timestamp = time.time()
......@@ -65,9 +65,10 @@ if __name__ == "__main__":
# command = interpreter + os.path.join('test', filename)
# results.append(pool.submit(run_unittests, command))
os.system(' '.join([interpreter, '-c',
"""'import sys;"""
"""sys.path.extend(["DHParser"]);"""
"""import testing; testing.run_path("%s")'""" % scriptdir,
'''"import sys; '''
'''sys.path.extend(['DHParser']);'''
'''import testing; testing.run_path('%s')"''' %
scriptdir.replace('\\', '\\\\'),
os.path.join(os.getcwd(), 'test')]))
concurrent.futures.wait(results)
......
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