The expiration time for new job artifacts in CI/CD pipelines is now 30 days (GitLab default). Previously generated artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

Commit 5a5efa7b authored by eckhart's avatar eckhart
Browse files

- ebnf.py: compile_ebnf added

parent 3ec7a844
......@@ -113,10 +113,10 @@ def compile_src(source, log_dir=''):
with logging(log_dir):
compiler = get_compiler()
cname = compiler.__class__.__name__
result = compile_source(source, get_preprocessor(),
get_grammar(),
get_transformer(), compiler)
return result
result_tuple = compile_source(source, get_preprocessor(),
get_grammar(),
get_transformer(), compiler)
return result_tuple
if __name__ == "__main__":
......
......@@ -29,7 +29,7 @@ from functools import partial
import keyword
import os
from DHParser.compile import CompilerError, Compiler
from DHParser.compile import CompilerError, Compiler, compile_source
from DHParser.error import Error
from DHParser.parse import Grammar, mixin_comment, Forward, RegExp, Whitespace, \
NegativeLookahead, Alternative, Series, Option, OneOrMore, ZeroOrMore, Token
......@@ -41,7 +41,7 @@ from DHParser.transform import TransformationFunc, traverse, remove_brackets, \
reduce_single_child, replace_by_single_child, remove_expendables, \
remove_tokens, flatten, forbid, assert_content
from DHParser.versionnumber import __version__
from typing import Callable, Dict, List, Set, Tuple, Union
from typing import Callable, Dict, List, Set, Tuple, Union, Optional, Any
__all__ = ('get_ebnf_preprocessor',
......@@ -53,6 +53,7 @@ __all__ = ('get_ebnf_preprocessor',
'EBNFCompilerError',
'EBNFCompiler',
'grammar_changed',
'compile_ebnf',
'PreprocessorFactoryFunc',
'ParserFactoryFunc',
'TransformerFactoryFunc',
......@@ -1195,4 +1196,29 @@ def get_ebnf_compiler(grammar_name="", grammar_source="") -> EBNFCompiler:
return compiler
########################################################################
#
# EBNF compiler
#
########################################################################
def compile_ebnf(ebnf_source: str, branding: str = 'DSL') \
-> Tuple[Optional[Any], List[Error], Optional[Node]]:
"""Compiles an `ebnf_source` (file_name or EBNF-string) and returns
a tuple of the python code of the compiler, a list of warnings or errors
and the abstract syntax tree of the EBNF-source.
This function is merely syntactic sugar."""
return compile_source(ebnf_source,
get_ebnf_preprocessor(),
get_ebnf_grammar(),
get_ebnf_transformer(),
get_ebnf_compiler(branding, ebnf_source))
########################################################################
#
# Presets
#
########################################################################
CONFIG_PRESET['add_grammar_source_to_parser_docstring'] = False
......@@ -30,7 +30,8 @@ from DHParser.preprocess import nil_preprocessor
from DHParser import compile_source
from DHParser.error import has_errors, Error
from DHParser.syntaxtree import WHITESPACE_PTYPE
from DHParser.ebnf import get_ebnf_grammar, get_ebnf_transformer, EBNFTransform, get_ebnf_compiler
from DHParser.ebnf import get_ebnf_grammar, get_ebnf_transformer, EBNFTransform, \
get_ebnf_compiler, compile_ebnf
from DHParser.dsl import CompilationError, compileDSL, DHPARSER_IMPORTS, grammar_provider
from DHParser.testing import grammar_unit
......@@ -504,8 +505,7 @@ class TestErrorCustomization:
series = "A" § "B" "C"
other = "X" | "Y" | "Z"
"""
result, messages, ast = compile_source(lang, None, get_ebnf_grammar(),
get_ebnf_transformer(), get_ebnf_compiler())
result, messages, ast = compile_ebnf(lang)
assert messages[0].code == Error.UNUSED_ERROR_MSG_WARNING
......
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