Commit 5eb732ac authored by eckhart's avatar eckhart

- Refactoring: Elimination of ParserBase. Still one Error!

parent f414983c
......@@ -87,7 +87,7 @@ try:
import regex as re
except ImportError:
import re
from DHParser import logging, is_filename, load_if_file, MockParser, \\
from DHParser import logging, is_filename, load_if_file, \\
Grammar, Compiler, nil_preprocessor, PreprocessorToken, Whitespace, \\
Lookbehind, Lookahead, Alternative, Pop, Token, Synonym, AllOf, SomeOf, Unordered, \\
Option, NegativeLookbehind, OneOrMore, RegExp, Retrieve, Series, Capture, \\
......
......@@ -52,12 +52,9 @@ import collections
import contextlib
import html
import os
import threading
from DHParser.error import line_col
from DHParser.stringview import StringView
from DHParser.syntaxtree import Node
from DHParser.parse import ParserBase
from DHParser.toolkit import is_filename, escape_control_characters, GLOBALS, typing
from typing import List, Tuple, Union
......@@ -221,17 +218,15 @@ class HistoryRecord:
'\n</style>\n</head>\n<body>\n')
HTML_LEAD_OUT = '\n</body>\n</html>\n'
def __init__(self, call_stack: List['ParserBase'], node: Node, text: StringView) -> None:
def __init__(self, call_stack: List[str],
node: Node,
text: StringView,
line_col: Tuple[int, int]) -> None:
# copy call stack, dropping uninformative Forward-Parsers
self.call_stack = [p for p in call_stack if p.ptype != ":Forward"] # type: List['ParserBase']
self.call_stack = [tn for tn in call_stack if tn != ":Forward"] # type: List[str]
self.node = node # type: Node
self.text = text # type: StringView
self.line_col = (1, 1) # type: Tuple[int, int]
if call_stack:
grammar = call_stack[-1].grammar
document = grammar.document__
lbreaks = grammar.document_lbreaks__
self.line_col = line_col(lbreaks, len(document) - len(text))
self.line_col = line_col # type: Tuple[int, int]
def __str__(self):
return '%4i, %2i: %s; %s; "%s"' % self.as_tuple()
......@@ -287,8 +282,7 @@ class HistoryRecord:
@property
def stack(self) -> str:
return "->".join((p.repr if p.ptype in {':RegExp', ':Token'} else p.name or p.ptype)
for p in self.call_stack)
return "->".join(self.call_stack)
@property
def status(self) -> str:
......
This diff is collapsed.
......@@ -349,7 +349,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
or (len(raw_errors) == 1
and raw_errors[-1].code == Error.MANDATORY_CONTINUATION_AT_EOF)
and any(isinstance(p, Lookahead)
for p in parser.history__[-1].call_stack))
for p in parser.history__[-1].call_stack)) # TODO: Refactor this clause!!!
for parser_name, tests in test_unit.items():
assert parser_name, "Missing parser name in test %s!" % unit_name
......
......@@ -33,7 +33,6 @@ from functools import partial, singledispatch
from DHParser.error import Error, ErrorCode
from DHParser.syntaxtree import Node, WHITESPACE_PTYPE, TOKEN_PTYPE, ZOMBIE_NODE, RootNode, parse_sxpr, flatten_sxpr
from DHParser.parse import ParserBase, MockParser
from DHParser.toolkit import issubtype, isgenerictype, expand_table, smart_list, re, typing
from typing import AbstractSet, Any, ByteString, Callable, cast, Container, Dict, \
Tuple, List, Sequence, Union, Text, Generic
......
......@@ -33,7 +33,6 @@ from DHParser import logging, is_filename, load_if_file, \
remove_nodes, remove_content, remove_brackets, replace_parser, remove_anonymous_tokens, \
keep_children, is_one_of, has_content, apply_if, remove_first, remove_last, \
remove_anonymous_empty, keep_nodes, traverse_locally, strip, lstrip, rstrip, ZOMBIE_NODE
from DHParser.parse import MockParser
#######################################################################
......@@ -395,7 +394,7 @@ class XMLCompiler(Compiler):
node.attr.update(attributes)
node.result = ''
self.tree.empty_tags.add('?xml')
node.parser = self.get_parser('?xml')
node.tag_name = '?xml' # node.parser = self.get_parser('?xml')
return node
# def on_VersionInfo(self, node):
......@@ -597,7 +596,7 @@ class XMLCompiler(Compiler):
attributes = self.extract_attributes(node.children)
if attributes:
node.attr.update(attributes)
node.parser = self.get_parser(node['Name'].content)
node.tag_name = node['Name'].content # node.parser = self.get_parser(node['Name'].content)
node.result = ''
self.tree.empty_tags.add(node.tag_name)
return node
......
......@@ -33,7 +33,6 @@ from DHParser import logging, is_filename, load_if_file, Grammar, Compiler, nil_
remove_anonymous_empty, keep_nodes, traverse_locally, strip, lstrip, rstrip, \
replace_content, replace_content_by, forbid, assert_content, remove_infix_operator, \
error_on, recompile_grammar, GLOBALS
from DHParser.parse import MockParser
#######################################################################
......
......@@ -25,7 +25,7 @@ from functools import partial
sys.path.extend(['../', './'])
from DHParser.toolkit import compile_python_object
from DHParser.log import logging, is_logging, log_ST
from DHParser.log import logging, is_logging, log_ST, log_parsing_history
from DHParser.error import Error
from DHParser.parse import Retrieve, Parser, Grammar, Forward, TKN, ZeroOrMore, RE, \
RegExp, Lookbehind, NegativeLookahead, OneOrMore, Series, Alternative, AllOf, SomeOf, \
......@@ -73,7 +73,7 @@ class TestInfiLoopsAndRecursion:
assert snippet == str(syntax_tree)
if is_logging():
log_ST(syntax_tree, "test_LeftRecursion_direct.cst")
parser.log_parsing_history__("test_LeftRecursion_direct")
log_parsing_history(parser, "test_LeftRecursion_direct")
def test_direct_left_recursion2(self):
minilang = """
......@@ -110,7 +110,7 @@ class TestInfiLoopsAndRecursion:
assert snippet == str(syntax_tree)
if is_logging():
log_ST(syntax_tree, "test_LeftRecursion_indirect.cst")
parser.log_parsing_history__("test_LeftRecursion_indirect")
log_parsing_history(parser, "test_LeftRecursion_indirect")
def test_inifinite_loops(self):
minilang = """not_forever = { // } \n"""
......@@ -243,7 +243,7 @@ class TestRegex:
assert not messages, str(messages)
parser = compile_python_object(DHPARSER_IMPORTS + result, '\w+Grammar$')()
result = parser(testdoc)
# parser.log_parsing_history("test.log")
# log_parsing_history(parser, "test.log")
assert not result.error_flag
......
......@@ -24,7 +24,6 @@ import sys
sys.path.extend(['../', './'])
from DHParser.syntaxtree import Node, RootNode, parse_sxpr, parse_xml, flatten_sxpr, flatten_xml
from DHParser.parse import MockParser
from DHParser.transform import traverse, reduce_single_child, \
replace_by_single_child, flatten, remove_expendables
from DHParser.ebnf import get_ebnf_grammar, get_ebnf_transformer, get_ebnf_compiler
......
......@@ -253,7 +253,7 @@ class TestLookahead:
"""
EBNF = r"""
document = { category | entry } { LF }
category = {LF } sequence_of_letters { /:/ sequence_of_letters } /:/ §&(LF sequence_of_letters)
category = { LF } sequence_of_letters { /:/ sequence_of_letters } /:/ §&(LF sequence_of_letters)
entry = { LF } sequence_of_letters !/:/
sequence_of_letters = /[A-Za-z0-9 ]+/
LF = / *\n/
......
......@@ -26,7 +26,6 @@ sys.path.extend(['../', './'])
from DHParser.syntaxtree import Node, parse_sxpr, flatten_sxpr, parse_xml, ZOMBIE_NODE, \
TOKEN_PTYPE
from DHParser.parse import MockParser
from DHParser.transform import traverse, reduce_single_child, remove_whitespace, \
traverse_locally, collapse, collapse_if, lstrip, rstrip, remove_content, remove_tokens, \
transformation_factory, has_parent
......
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