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

- bugfixes

parent 70ee21b7
......@@ -328,7 +328,12 @@ class Grammar:
self.dirty_flag = False
self.history_tracking = False
self._assign_parser_names() # prepare class first
# prepare parsers in the class, first
# then deep-copy the parser tree from class to instance;
# parsers not connected to the root object will be copied later
# on demand (see Grammar.__getitem__()). Usually, the need to
# do so only arises during testing.
self.root__ = root if root else copy.deepcopy(self.__class__.root__)
if self.wspL__:
self.wsp_left_parser__ = Whitespace(self.wspL__) # type: ParserBase
......@@ -350,8 +355,14 @@ class Grammar:
except KeyError:
parser = getattr(self, key, None)
if parser:
raise KeyError(('Parser "%s" inaccesible, because it is not connected '
'to the root parser "%s" !') % (key,
# if toolkit.warnings():
# raise KeyError(('Parser "%s" inaccesible, because it is not connected '
# 'to the root parser "%s" !') % (key,
print('Parser "%s" not connected to root parser.' % key)
# add parser to grammar object on the fly...
setattr(self, key, copy.deepcopy(parser))
self[key].apply(self._add_parser) # might become a problem with all_parsers
return self[key]
raise KeyError('Unknown parser "%s" !' % key)
def _reset(self):
......@@ -369,7 +380,7 @@ class Grammar:
# TODO: Either make sure not to miss out unconnected parsers or raise an error! Actually, the EBNF-Compiler should keep track of this!
def _add_parser(self, parser: Parser) -> None:
"""Adds the copy of the classes parser object to this
"""Adds the particular copy of the parser object to this
particular instance of Grammar.
......@@ -6,7 +6,7 @@
latexdoc = preamble document
preamble = { command }+
document = [PARSEP] sequence [PARSEP] §EOF
document = [PARSEP] { [PARSEP] paragraph } §EOF
genericenv = beginenv sequence §endenv
beginenv = "\begin" §( "{" NAME "}" )
......@@ -27,8 +27,9 @@ from DHParser import toolkit
from LaTeXCompiler import get_grammar, get_transformer
with toolkit.logging(True):
error_report = testing.grammar_suite('grammar_tests', get_grammar,
get_transformer, verbose=True)
with toolkit.supress_warnings(True):
error_report = testing.grammar_suite('grammar_tests', get_grammar,
get_transformer, verbose=True)
assert not error_report, error_report
......@@ -20,12 +20,13 @@ See the License for the specific language governing permissions and
limitations under the License.
import sys
from functools import partial
from multiprocessing import Pool
import sys
sys.path.extend(['../', './'])
from DHParser.toolkit import is_logging, compile_python_object
from DHParser.toolkit import is_logging, compile_python_object, supress_warnings
from DHParser.parsers import compile_source, Retrieve, WHITESPACE_PTYPE, nil_scanner
from DHParser.ebnf import get_ebnf_grammar, get_ebnf_transformer, EBNFTransformer, get_ebnf_compiler
from DHParser.dsl import CompilationError, compileDSL, DHPARSER_IMPORTS, parser_factory
......@@ -348,7 +349,8 @@ class TestBoundaryCases:
unconnected = /.*/
grammar = parser_factory(ebnf)()
with supress_warnings(False):
grammar = parser_factory(ebnf)()
assert False, "EBNF compiler should complain about unconnected rules."
except CompilationError as err:
grammar_src = err.result
......@@ -357,10 +359,8 @@ class TestBoundaryCases:
assert grammar['root'], "Grammar objects should be subscriptable by parser names!"
unconnected = grammar['unconnected']
assert False, "Grammar objects should raise a KeyError if subscripted by " \
"names of parsers that are unconnected to the root parser!"
except KeyError:
assert False, "Grammar objects should be able to cope with unconnected parsers!"
nonexistant = grammar['nonexistant']
assert False, "Grammar object shoul raise a KeyError if subscripted by " \
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