From 57b09014b9e78f7f5945b48aeea60ad373e45ae4 Mon Sep 17 00:00:00 2001 From: Eckhart Arnold Date: Thu, 31 Aug 2017 20:13:57 +0200 Subject: [PATCH] - fixed pypy3 compatibility --- DHParser/toolkit.py | 6 ++-- dhparser.py | 48 ++++++++++++++++---------------- examples/LaTeX/tst_LaTeX_docs.py | 2 +- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/DHParser/toolkit.py b/DHParser/toolkit.py index b6a0284..c03303b 100644 --- a/DHParser/toolkit.py +++ b/DHParser/toolkit.py @@ -43,9 +43,9 @@ except ImportError: import sys try: - from typing import Any, List, Tuple, Collection, Union, Optional + from typing import Any, List, Tuple, Iterable, Union, Optional except ImportError: - from .typing34 import Any, List, Tuple, Collection, Union, Optional + from .typing34 import Any, List, Tuple, Iterable, Union, Optional __all__ = ('logging', 'is_logging', @@ -218,7 +218,7 @@ def sv_match(regex, sv: StringView): return regex.match(sv.text, pos=sv.begin, endpos=sv.end) -def sv_index(absolute_index: Union[int, Collection], sv: StringView) -> Union[int, tuple]: +def sv_index(absolute_index: Union[int, Iterable], sv: StringView) -> Union[int, tuple]: """ Converts the an index into string watched by a StringView object to an index relativ to the string view object, e.g.: diff --git a/dhparser.py b/dhparser.py index 0abed9c..acf68e5 100755 --- a/dhparser.py +++ b/dhparser.py @@ -147,30 +147,6 @@ else: ''' -def selftest() -> bool: - print("DHParser selftest...") - print("\nSTAGE I: Trying to compile EBNF-Grammar:\n") - builtin_ebnf_parser = get_ebnf_grammar() - ebnf_src = builtin_ebnf_parser.__doc__[builtin_ebnf_parser.__doc__.find('#'):] - ebnf_transformer = get_ebnf_transformer() - ebnf_compiler = get_ebnf_compiler('EBNF') - generated_ebnf_parser, errors, ast = compile_source(ebnf_src, None, - builtin_ebnf_parser, ebnf_transformer, ebnf_compiler) - - if errors: - print("Selftest FAILED :-(") - print("\n\n".join(errors)) - return False - print(generated_ebnf_parser) - print("\n\nSTAGE 2: Selfhosting-test: Trying to compile EBNF-Grammar with generated parser...\n") - selfhosted_ebnf_parser = compileDSL(ebnf_src, None, generated_ebnf_parser, - ebnf_transformer, ebnf_compiler) - ebnf_compiler.gen_transformer_skeleton() - print(selfhosted_ebnf_parser) - print("\n\n Selftest SUCCEEDED :-)\n\n") - return True - - def create_project(path, ebnf_tmpl=EBNF_TEMPLATE, readme_tmpl=README_TEMPLATE, @@ -208,6 +184,30 @@ def create_project(path, print('ready.') +def selftest() -> bool: + print("DHParser selftest...") + print("\nSTAGE I: Trying to compile EBNF-Grammar:\n") + builtin_ebnf_parser = get_ebnf_grammar() + ebnf_src = builtin_ebnf_parser.__doc__[builtin_ebnf_parser.__doc__.find('#'):] + ebnf_transformer = get_ebnf_transformer() + ebnf_compiler = get_ebnf_compiler('EBNF') + generated_ebnf_parser, errors, ast = compile_source(ebnf_src, None, + builtin_ebnf_parser, ebnf_transformer, ebnf_compiler) + + if errors: + print("Selftest FAILED :-(") + print("\n\n".join(errors)) + return False + print(generated_ebnf_parser) + print("\n\nSTAGE 2: Selfhosting-test: Trying to compile EBNF-Grammar with generated parser...\n") + selfhosted_ebnf_parser = compileDSL(ebnf_src, None, generated_ebnf_parser, + ebnf_transformer, ebnf_compiler) + ebnf_compiler.gen_transformer_skeleton() + print(selfhosted_ebnf_parser) + print("\n\n Selftest SUCCEEDED :-)\n\n") + return True + + def cpu_profile(func, repetitions=1): import cProfile, pstats pr = cProfile.Profile() diff --git a/examples/LaTeX/tst_LaTeX_docs.py b/examples/LaTeX/tst_LaTeX_docs.py index e302013..f9e9622 100755 --- a/examples/LaTeX/tst_LaTeX_docs.py +++ b/examples/LaTeX/tst_LaTeX_docs.py @@ -87,7 +87,7 @@ def mem_profile(func): print(stat) if __name__ == "__main__": - mem_profile(tst_func) + cpu_profile(tst_func) -- GitLab