Notice to GitKraken users: A vulnerability has been found in the SSH key generation of GitKraken versions 7.6.0 to 8.0.0 (https://www.gitkraken.com/blog/weak-ssh-key-fix). If you use GitKraken and have generated a SSH key using one of these versions, please remove it both from your local workstation and from your LRZ GitLab profile.

21.10.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit db0a8568 authored by Eckhart Arnold's avatar Eckhart Arnold
Browse files

bugfixes

parent 0e90dfe0
...@@ -82,8 +82,9 @@ from DHParser.parsers import Grammar, Compiler, nil_scanner, \\ ...@@ -82,8 +82,9 @@ from DHParser.parsers import Grammar, Compiler, nil_scanner, \\
last_value, counterpart, accumulate, ScannerFunc last_value, counterpart, accumulate, ScannerFunc
from DHParser.syntaxtree import Node, traverse, remove_enclosing_delimiters, \\ from DHParser.syntaxtree import Node, traverse, remove_enclosing_delimiters, \\
remove_children_if, reduce_single_child, replace_by_single_child, remove_whitespace, \\ remove_children_if, reduce_single_child, replace_by_single_child, remove_whitespace, \\
no_transformation, remove_expendables, remove_tokens, flatten, is_whitespace, is_expendable, \\ no_transformation, remove_expendables, remove_empty, remove_tokens, flatten, is_whitespace, \\
collapse, map_content, WHITESPACE_PTYPE, TOKEN_PTYPE, TransformationFunc is_empty, is_expendable, collapse, map_content, WHITESPACE_PTYPE, TOKEN_PTYPE, \\
TransformationFunc
''' '''
...@@ -257,7 +258,6 @@ def parser_factory(ebnf_src: str, branding="DSL") -> Grammar: ...@@ -257,7 +258,6 @@ def parser_factory(ebnf_src: str, branding="DSL") -> Grammar:
""" """
grammar_src = compileDSL(ebnf_src, nil_scanner, get_ebnf_grammar(), grammar_src = compileDSL(ebnf_src, nil_scanner, get_ebnf_grammar(),
get_ebnf_transformer(), get_ebnf_compiler(branding)) get_ebnf_transformer(), get_ebnf_compiler(branding))
print(grammar_src)
return compile_python_object(DHPARSER_IMPORTS + grammar_src, 'get_(?:\w+_)?grammar$') return compile_python_object(DHPARSER_IMPORTS + grammar_src, 'get_(?:\w+_)?grammar$')
......
...@@ -356,9 +356,10 @@ class EBNFCompiler(Compiler): ...@@ -356,9 +356,10 @@ class EBNFCompiler(Compiler):
transtable = [tt_name + ' = {', transtable = [tt_name + ' = {',
' # AST Transformations for the ' + ' # AST Transformations for the ' +
self.grammar_name + '-grammar'] self.grammar_name + '-grammar']
transtable.append(' "+": remove_empty,')
for name in self.rules: for name in self.rules:
transtable.append(' "' + name + '": no_transformation,') transtable.append(' "' + name + '": no_transformation,')
transtable += [' "*": no_transformation', '}', '', tf_name + transtable += [' "*": replace_by_single_child', '}', '', tf_name +
' = partial(traverse, processing_table=%s)' % tt_name, ''] ' = partial(traverse, processing_table=%s)' % tt_name, '']
transtable += [TRANSFORMER_FACTORY.format(NAME=self.grammar_name)] transtable += [TRANSFORMER_FACTORY.format(NAME=self.grammar_name)]
return '\n'.join(transtable) return '\n'.join(transtable)
......
...@@ -390,7 +390,9 @@ class Grammar: ...@@ -390,7 +390,9 @@ class Grammar:
particular instance of Grammar. particular instance of Grammar.
""" """
if parser.name: if parser.name:
assert parser.name not in self.__dict__, \ # prevent overwriting instance variables or parsers of a different class
assert parser.name not in self.__dict__ or \
isinstance(self.__dict__[parser.name], parser.__class__), \
('Cannot add parser "%s" because a field with the same name ' ('Cannot add parser "%s" because a field with the same name '
'already exists in grammar object!' % parser.name) 'already exists in grammar object!' % parser.name)
setattr(self, parser.name, parser) setattr(self, parser.name, parser)
......
...@@ -58,6 +58,7 @@ __all__ = ['WHITESPACE_PTYPE', ...@@ -58,6 +58,7 @@ __all__ = ['WHITESPACE_PTYPE',
'is_token', 'is_token',
'remove_children_if', 'remove_children_if',
'remove_whitespace', 'remove_whitespace',
'remove_empty',
'remove_expendables', 'remove_expendables',
'remove_tokens', 'remove_tokens',
'flatten', 'flatten',
...@@ -755,8 +756,8 @@ def remove_children_if(node, condition): ...@@ -755,8 +756,8 @@ def remove_children_if(node, condition):
remove_whitespace = remove_children_if(is_whitespace) # partial(remove_children_if, condition=is_whitespace) remove_whitespace = remove_children_if(is_whitespace) # partial(remove_children_if, condition=is_whitespace)
remove_empty = remove_children_if(is_empty)
remove_expendables = remove_children_if(is_expendable) # partial(remove_children_if, condition=is_expendable) remove_expendables = remove_children_if(is_expendable) # partial(remove_children_if, condition=is_expendable)
# remove_scanner_tokens = remove_children_if(is_scanner_token) # partial(remove_children_if, condition=is_scanner_token)
@transformation_factory @transformation_factory
...@@ -777,7 +778,8 @@ def remove_enclosing_delimiters(node): ...@@ -777,7 +778,8 @@ def remove_enclosing_delimiters(node):
node.result = node.result[1:-1] node.result = node.result[1:-1]
def map_content(node, func: Callable[[Node], ResultType]): @transformation_factory
def map_content(node, func: Callable): # Callable[[Node], ResultType]
"""Replaces the content of the node. ``func`` takes the node """Replaces the content of the node. ``func`` takes the node
as an argument an returns the mapped result. as an argument an returns the mapped result.
""" """
......
...@@ -16,3 +16,4 @@ ...@@ -16,3 +16,4 @@
Im allgemeinen werden die Bewohner Göttingens eingeteilt in Studenten, Im allgemeinen werden die Bewohner Göttingens eingeteilt in Studenten,
Professoren, Philister und Vieh; welche vier Stände doch nichts weniger Professoren, Philister und Vieh; welche vier Stände doch nichts weniger
als streng geschieden sind. Der Viehstand ist der bedeutendste. als streng geschieden sind. Der Viehstand ist der bedeutendste.
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