In January 2021 we will introduce a 10 GB quota for project repositories. Higher limits for individual projects will be available on request. Please see https://doku.lrz.de/display/PUBLIC/GitLab for more information.

Commit 3004d9b7 authored by eckhart's avatar eckhart

- moved compilation support to a separate module "compile.py"

parent 3f663703
......@@ -18,6 +18,7 @@ implied. See the License for the specific language governing
permissions and limitations under the License.
"""
from .compile import *
from .dsl import *
from .ebnf import *
# Flat namespace for the DHParser Package. Is this a good idea...?
......
......@@ -30,9 +30,10 @@ from DHParser.ebnf import EBNFCompiler, grammar_changed, \
PreprocessorFactoryFunc, ParserFactoryFunc, TransformerFactoryFunc, CompilerFactoryFunc
from DHParser.error import Error, is_error, has_errors, only_errors
from DHParser.log import logging
from DHParser.parse import Grammar, Compiler, compile_source
from DHParser.parse import Grammar
from DHParser import Compiler, compile_source, TransformationFunc
from DHParser.preprocess import nil_preprocessor, PreprocessorFunc
from DHParser.syntaxtree import Node, TransformationFunc
from DHParser.syntaxtree import Node
from DHParser.toolkit import load_if_file, is_python_code, compile_python_object, \
re
......
......@@ -31,10 +31,10 @@ from typing import Callable, Dict, List, Set, Tuple
from DHParser.error import Error
from DHParser.parse import Grammar, mixin_comment, Forward, RegExp, RE, \
NegativeLookahead, Alternative, Series, Option, OneOrMore, ZeroOrMore, Token, \
Compiler
NegativeLookahead, Alternative, Series, Option, OneOrMore, ZeroOrMore, Token
from DHParser import Compiler, TransformationFunc
from DHParser.preprocess import nil_preprocessor, PreprocessorFunc
from DHParser.syntaxtree import Node, TransformationFunc, WHITESPACE_PTYPE, TOKEN_PTYPE
from DHParser.syntaxtree import Node, WHITESPACE_PTYPE, TOKEN_PTYPE
from DHParser.toolkit import load_if_file, escape_re, md5, sane_parser_name, re, expand_table
from DHParser.transform import traverse, remove_brackets, \
reduce_single_child, replace_by_single_child, remove_expendables, \
......
This diff is collapsed.
......@@ -26,12 +26,11 @@ parser classes are defined in the ``parse`` module.
import collections.abc
import copy
from functools import partial
from DHParser.error import Error, linebreaks, line_col
from DHParser.stringview import StringView
from DHParser.toolkit import re, typing
from typing import Any, Callable, cast, Iterator, List, Union, Tuple, Hashable, Optional
from DHParser.toolkit import re
from typing import Callable, cast, Iterator, List, Union, Tuple, Optional
__all__ = ('ParserBase',
......@@ -42,8 +41,7 @@ __all__ = ('ParserBase',
'ZOMBIE_PARSER',
'Node',
'mock_syntax_tree',
'flatten_sxpr',
'TransformationFunc')
'flatten_sxpr')
#######################################################################
......@@ -745,10 +743,6 @@ def mock_syntax_tree(sxpr):
node._pos = 0
return node
TransformationFunc = Union[Callable[[Node], Any], partial]
# if __name__ == "__main__":
# st = mock_syntax_tree("(alpha (beta (gamma i\nj\nk) (delta y)) (epsilon z))")
# print(st.as_sxpr())
......
......@@ -38,6 +38,7 @@ from typing import AbstractSet, Any, ByteString, Callable, cast, Container, Dict
__all__ = ('TransformationDict',
'TransformationProc',
'TransformationFunc',
'ConditionFunc',
'KeyFunc',
'transformation_factory',
......@@ -96,6 +97,7 @@ __all__ = ('TransformationDict',
TransformationProc = Callable[[List[Node]], None]
TransformationDict = Dict[str, Sequence[Callable]]
TransformationFunc = Union[Callable[[Node], Any], partial]
ProcessingTableType = Dict[str, Union[Sequence[Callable], TransformationDict]]
ConditionFunc = Callable # Callable[[List[Node]], bool]
KeyFunc = Callable[[Node], str]
......@@ -846,3 +848,4 @@ def forbid(context: List[Node], child_tags: AbstractSet[str]):
if child.tag_name in child_tags:
node.add_error('Element "%s" cannot be nested inside "%s".' %
(child.parser.name, node.parser.name))
......@@ -25,7 +25,7 @@ import sys
from DHParser.dsl import compileDSL, compile_on_disk
from DHParser.ebnf import get_ebnf_grammar, get_ebnf_transformer, get_ebnf_compiler
from DHParser.parse import compile_source
from DHParser import compile_source
from DHParser.log import logging
EBNF_TEMPLATE = r"""-grammar
......
......@@ -63,9 +63,9 @@ Main Modules Reference
The core of DHParser are the modules containing the functionality
for the parsing and compiling process. The modules ``preprocess``,
``parse`` and ``transform`` represent particular stages of the
``parse``, ``transform`` and ``compile`` represent particular stages of the
parsing/compiling process, while ``syntaxtree`` and ``error`` define
clases for syntax trees and parser/compiler errors, respectively.
classes for syntax trees and parser/compiler errors, respectively.
Module ``preprocess``
---------------------
......@@ -91,6 +91,12 @@ Module ``transform``
.. automodule:: transform
:members:
Module ``compile``
--------------------
.. automodule:: compile
:members:
Module ``error``
----------------
......
......@@ -23,13 +23,14 @@ from DHParser import is_filename, load_if_file, \
Option, NegativeLookbehind, OneOrMore, RegExp, Retrieve, Series, RE, Capture, \
ZeroOrMore, Forward, NegativeLookahead, mixin_comment, compile_source, \
last_value, counterpart, accumulate, PreprocessorFunc, \
Node, TransformationFunc, TransformationDict, TRUE_CONDITION, \
Node, TransformationDict, TRUE_CONDITION, \
traverse, remove_children_if, merge_children, is_anonymous, \
reduce_single_child, replace_by_single_child, replace_or_reduce, remove_whitespace, \
remove_expendables, remove_empty, remove_tokens, flatten, is_whitespace, \
is_empty, is_expendable, collapse, replace_content, remove_nodes, remove_content, remove_brackets, replace_parser, \
keep_children, is_one_of, has_content, apply_if, remove_first, remove_last, \
WHITESPACE_PTYPE, TOKEN_PTYPE
from DHParser.transform import TransformationFunc
from DHParser.log import logging
......
......@@ -24,7 +24,8 @@ import os
import sys
sys.path.extend(['../', './'])
from DHParser.parse import Grammar, Compiler
from DHParser.parse import Grammar
from DHParser import Compiler
from DHParser.error import is_error
from DHParser.dsl import compile_on_disk, run_compiler, compileEBNF, grammar_provider, \
load_compiler_suite
......
......@@ -27,7 +27,7 @@ sys.path.extend(['../', './'])
from DHParser.toolkit import compile_python_object, re
from DHParser.preprocess import nil_preprocessor
from DHParser.parse import compile_source
from DHParser import compile_source
from DHParser.error import has_errors
from DHParser.syntaxtree import WHITESPACE_PTYPE
from DHParser.ebnf import get_ebnf_grammar, get_ebnf_transformer, EBNFTransform, get_ebnf_compiler
......
......@@ -26,12 +26,10 @@ sys.path.extend(['../', './'])
from DHParser.toolkit import compile_python_object
from DHParser.log import logging, is_logging, log_ST
from DHParser.stringview import StringView
from DHParser.error import Error
from DHParser.syntaxtree import mock_syntax_tree
from DHParser.parse import compile_source, Retrieve, Grammar, Forward, Token, ZeroOrMore, RE, \
RegExp, Lookbehind, NegativeLookahead, OneOrMore, Series, Alternative, AllOf, SomeOf, Compiler, \
UnknownParserError
from DHParser.parse import Retrieve, Grammar, Forward, Token, ZeroOrMore, RE, \
RegExp, Lookbehind, NegativeLookahead, OneOrMore, Series, Alternative, AllOf, SomeOf, UnknownParserError
from DHParser import compile_source
from DHParser.ebnf import get_ebnf_grammar, get_ebnf_transformer, get_ebnf_compiler
from DHParser.dsl import grammar_provider, DHPARSER_IMPORTS
......@@ -548,22 +546,6 @@ class TestBorderlineCases:
assert not cst.error_flag
class TestCompilerClass:
def test_error_propagations(self):
tree = mock_syntax_tree('(A (B 1) (C (D (E 2) (F 3))))')
A = tree
B = next(tree.find(lambda node: str(node) == "1"))
D = next(tree.find(lambda node: node.parser.name == "D"))
F = next(tree.find(lambda node: str(node) == "3"))
B.add_error("Error in child node")
F.add_error("Error in child's child node")
Compiler.propagate_error_flags(tree, lazy=True)
assert A.error_flag
assert not D.error_flag
Compiler.propagate_error_flags(tree, lazy=False)
assert D.error_flag
class TestUnknownParserError:
def test_unknown_parser_error(self):
gr = Grammar()
......
......@@ -25,7 +25,7 @@ limitations under the License.
from functools import partial
from DHParser.dsl import grammar_provider
from DHParser.parse import compile_source
from DHParser import compile_source
from DHParser.preprocess import make_token, tokenized_to_original_mapping, source_map, \
BEGIN_TOKEN, END_TOKEN, TOKEN_DELIMITER, SourceMapFunc, SourceMap, chain_preprocessors, \
strip_tokens
......
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