Commit cf262cfd authored by di68kap's avatar di68kap

transfer from gitlab PyDDSL to gitlab DHParser

parent ff32c89f
......@@ -30,7 +30,7 @@ from .parsers import GrammarBase, mixin_comment, nil_scanner, Forward, RE, Negat
Capture, Retrieve
from .syntaxtree import Node, traverse, remove_enclosing_delimiters, reduce_single_child, \
replace_by_single_child, TOKEN_KEYWORD, remove_expendables, remove_tokens, flatten, \
forbid, assert_content, WHITESPACE_KEYWORD
forbid, assert_content, WHITESPACE_KEYWORD, key_parser_name, key_tag_name
from .versionnumber import __version__
......@@ -45,8 +45,6 @@ __all__ = ['get_ebnf_scanner',
'grammar_changed']
########################################################################
#
# EBNF scanning
......@@ -221,14 +219,14 @@ EBNF_transformation_table = {
EBNF_validation_table = {
# Semantic validation on the AST
"repetition, option, oneormore":
[partial(forbid, child_names=['repetition', 'option', 'oneormore']),
[partial(forbid, child_tags=['repetition', 'option', 'oneormore']),
partial(assert_content, regex=r'(?!§)')],
}
def EBNFTransformer(syntax_tree):
for processing_table, key_func in [(EBNF_transformation_table, lambda node: node.parser.name),
(EBNF_validation_table, lambda node: node.tag_name)]:
for processing_table, key_func in [(EBNF_transformation_table, key_parser_name),
(EBNF_validation_table, key_tag_name)]:
traverse(syntax_tree, processing_table, key_func)
......
......@@ -36,6 +36,8 @@ __all__ = ['WHITESPACE_KEYWORD',
'Error',
'Node',
'mock_syntax_tree',
'key_parser_name',
'key_tag_name',
'traverse',
'no_operation',
'replace_by_single_child',
......@@ -481,7 +483,15 @@ WHITESPACE_KEYWORD = 'WSP__'
TOKEN_KEYWORD = 'TOKEN__'
def traverse(root_node, processing_table, key_func=lambda node: node.parser.name):
def key_parser_name(node):
return node.parser.name
def key_tag_name(node):
return node.tag_name
def traverse(root_node, processing_table, key_func=key_parser_name):
"""Traverses the snytax tree starting with the given ``node`` depth
first and applies the sequences of callback functions registered
in the ``calltable``-dictionary.
......@@ -660,16 +670,16 @@ def remove_enclosing_delimiters(node):
########################################################################
def require(node, child_names):
def require(node, child_tag):
for child in node.children:
if child.parser.name not in child_names:
if child.tag_name not in child_tag:
node.add_error('Element "%s" is not allowed inside "%s".' %
(child.parser.name, node.parser.name))
def forbid(node, child_names):
def forbid(node, child_tags):
for child in node.children:
if child.parser.name in child_names:
if child.tag_name in child_tags:
node.add_error('Element "%s" cannot be nested inside "%s".' %
(child.parser.name, node.parser.name))
......
......@@ -298,7 +298,7 @@ class TestSelfHosting:
def test_multiprocessing(self):
with Pool(processes=2) as pool:
res = [pool.apply_async(self.multiprocessing_task, ()) for i in range(4)]
errors = [r.get(timeout=5) for r in res]
errors = [r.get(timeout=10) for r in res]
for i, e in enumerate(errors):
assert not e, ("%i: " % i) + str(e)
......
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