diff --git a/DHParser/toolkit.py b/DHParser/toolkit.py index b6a0284d8ec3ff276838d8f975ff5c7c3081a82b..c03303b5b15515acb91c9851dc7e6eff1cf4ef90 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 0abed9c7b4ee049d709fc067c1678d01692f1906..acf68e540bf4ad3cb39ee72ea29bbb40f7edbad5 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 e3020131eac994f16f5e7c590e9d899b88975d83..f9e9622e0bfa4ab04af2bb6e20a6e5315554bbc5 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)