Added a little more debug and info. Corrected a mistake on the finalize_pile
This commit is contained in:
parent
69c9e3f412
commit
63b3109800
|
|
@ -202,7 +202,7 @@ class ReContextContainer(BaseContainer):
|
|||
children = ""
|
||||
|
||||
def get_content(self, exm, arbitrary_list=None):
|
||||
child_start, child_end = exm(export.ExportRequest(self.type, self.children)) # noqa: F841
|
||||
child_start, child_end = exm(export.ExportRequest(self.type, self.children)) # noqa F821
|
||||
output = "\n"
|
||||
for element in self.content:
|
||||
if isinstance(element, syntax.Linebreak):
|
||||
|
|
@ -340,7 +340,7 @@ class ContextManager:
|
|||
"""
|
||||
Class in charge of piling all the parsed elements and then encapsulating them inside one another.
|
||||
"""
|
||||
def __init__(self, parsed_list):
|
||||
def __init__(self, parsed_list, name=None, ident=0):
|
||||
"""
|
||||
Takes a list of parsed tokens.
|
||||
Parameters
|
||||
|
|
@ -351,6 +351,8 @@ class ContextManager:
|
|||
self.output = []
|
||||
self.parsed_list = parsed_list
|
||||
self.pile = []
|
||||
self.name = name
|
||||
self.ident = ident
|
||||
self.matched_elements = {}
|
||||
self.dict_lookahead = {
|
||||
"list:ulist": ["list:ulist"],
|
||||
|
|
@ -442,6 +444,8 @@ class ContextManager:
|
|||
while index < len(self.parsed_list):
|
||||
token = self.parsed_list[index]
|
||||
token.line_number = line_number
|
||||
token.file_name = self.name
|
||||
token.ident = self.ident
|
||||
self.pile.append(token)
|
||||
try:
|
||||
# Linebreaks
|
||||
|
|
@ -500,8 +504,14 @@ class ContextManager:
|
|||
if isinstance(p, BaseContainer):
|
||||
final_pile.append(p)
|
||||
else: # Cleanup of non-matched elements
|
||||
if isinstance(p, syntax.SemanticType):
|
||||
line = p.line_number
|
||||
name = p.file_name
|
||||
else:
|
||||
line = "Undefined"
|
||||
name = "Undefined"
|
||||
log_exception(
|
||||
TypeError(f"Expected BaseContainer, found {type(p)} instead."),
|
||||
TypeError(f"Encountered a non-container element in the pile during the final pass: {p}, at line {line} in file {name}."),
|
||||
level="CRITICAL"
|
||||
)
|
||||
self.pile = final_pile
|
||||
|
|
@ -536,7 +546,7 @@ class ContextManager:
|
|||
return range_to_encapsulate, line_skipped
|
||||
|
||||
def recontext(self, token):
|
||||
token.content = ContextManager(token.content)()
|
||||
token.content = ContextManager(token.content, name=self.name)()
|
||||
|
||||
def get_last_container_in_pile(self, index):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -158,10 +158,12 @@ class MismatchedContainerError(BootstraparseError):
|
|||
if token:
|
||||
self.line = token.line_number
|
||||
self.label = token.label
|
||||
self.name = token.file_name
|
||||
else:
|
||||
self.line = None
|
||||
self.label = None
|
||||
super().__init__(f"Could not process {self.label} at line {self.line}.")
|
||||
self.name = None
|
||||
super().__init__(f"Could not process {self.label} at line {self.line} in file {self.name}.")
|
||||
|
||||
|
||||
class LonelyOptionalError(BootstraparseError):
|
||||
|
|
@ -173,12 +175,14 @@ class LonelyOptionalError(BootstraparseError):
|
|||
if token:
|
||||
self.line = token.line_number
|
||||
self.label = token.label
|
||||
self.name = token.file_name
|
||||
else:
|
||||
self.line = None
|
||||
self.label = None
|
||||
self.name = None
|
||||
if last_in_pile:
|
||||
super().__init__(f"Could not match token {token} at line {self.line} with "
|
||||
f"last element in pile {last_in_pile} at line {last_in_pile.line_number} (not a container).")
|
||||
f"last element in pile {last_in_pile} at line {last_in_pile.line_number} in file {self.name}(not a container).")
|
||||
else:
|
||||
super().__init__(f"Could not match token {token} at line {self.line} "
|
||||
super().__init__(f"Could not match token {token} at line {self.line} in file {self.name}"
|
||||
f"as there was nothing in the pile.")
|
||||
|
|
|
|||
|
|
@ -247,7 +247,7 @@ if __name__ == '__main__': # pragma: no cover
|
|||
test = parser.parse_line(io_string)
|
||||
__config = config.ConfigLoader(pathresolver.b_path("configs/"))
|
||||
__templates = config.ConfigLoader(pathresolver.b_path("templates/"))
|
||||
exm = ExportManager(None, None, __config, __templates)
|
||||
exm = ExportManager(__config, __templates)
|
||||
cxm = context_mngr.ContextManager(test)
|
||||
cxc = ContextConverter(cxm(), exm)
|
||||
rich.inspect(cxc)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
# Module sequencing the successive actions necessary for website building
|
||||
import os
|
||||
|
||||
import rich
|
||||
|
||||
from bootstraparse.modules import pathresolver, sitecrawler, environment, config, export, parser, context_mngr
|
||||
|
||||
|
||||
|
|
@ -48,7 +51,7 @@ def create_crawler(origin, destination, _env):
|
|||
def preparse_parse(preparser):
|
||||
io = preparser.do_replacements()
|
||||
parsed_list = parser.parse_line(io)
|
||||
output = context_mngr.ContextManager(parsed_list)()
|
||||
output = context_mngr.ContextManager(parsed_list, name=preparser.name)()
|
||||
return output
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ class SemanticType:
|
|||
|
||||
def __init__(self, content):
|
||||
self.content = content
|
||||
self.line_number = "Undefined"
|
||||
self.file_name = "Undefined"
|
||||
self.label_container = self.label
|
||||
|
||||
def to_markup(self):
|
||||
|
|
|
|||
|
|
@ -571,31 +571,6 @@ def test_context_mngr():
|
|||
assert base != base2
|
||||
base.debug_map()
|
||||
|
||||
#
|
||||
# def test_base_container_with_optionals():
|
||||
# base = context_mngr.BaseContainer()
|
||||
# assert base is not None
|
||||
#
|
||||
# assert base.class_name() == 'BaseContainerWithOptionals'
|
||||
# assert base.debug_map() is None
|
||||
#
|
||||
# base.add('test')
|
||||
# assert base[0] == 'test'
|
||||
# assert len(base) == 1
|
||||
#
|
||||
# assert base.fetch_html_insert() == []
|
||||
#
|
||||
# class OI:
|
||||
# label = 'optional:insert'
|
||||
#
|
||||
# class CI:
|
||||
# label = 'optional:class'
|
||||
#
|
||||
# i, c = OI(), CI()
|
||||
# base.optionals = [i, c]
|
||||
# assert base.fetch_html_insert() == [i]
|
||||
# assert base.fetch_class_insert() == [c]
|
||||
|
||||
|
||||
def test_print():
|
||||
base = context_mngr.BaseContainer()
|
||||
|
|
@ -681,3 +656,10 @@ def test_get_last_container_in_pile(base_cm):
|
|||
base_cm.pile[0] = None
|
||||
with pytest.raises(error_mngr.LonelyOptionalError):
|
||||
base_cm.get_last_container_in_pile(3)
|
||||
|
||||
|
||||
def test_finalize_pile(base_cm):
|
||||
base_cm()
|
||||
base_cm.pile[0] = {}
|
||||
with pytest.raises(TypeError):
|
||||
base_cm.finalize_pile()
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ all_logging_tests = [(i, j, k) for i in [None, "test.log"]
|
|||
all_non_blocking_exception_tests = [
|
||||
(ParsingError("test error", 10, 10, "testfile.bpr")),
|
||||
(ParsingError()),
|
||||
(MismatchedContainerError(namedtuple("Test", ["label", "line_number"])("test", 10),)),
|
||||
(MismatchedContainerError(namedtuple("Test", ["label", "line_number", "file_name"])("test", 10, "test.bpr"),)),
|
||||
]
|
||||
all_blocking_exception_tests = [
|
||||
|
||||
|
|
@ -110,7 +110,7 @@ def test_weird_exception_cases():
|
|||
raise(error_mngr.LonelyOptionalError(None, None))
|
||||
|
||||
from typing import NamedTuple
|
||||
tk = NamedTuple("falsetoken", [("line_number", int), ("label", str)])(1, "test")
|
||||
tk = NamedTuple("falsetoken", [("line_number", int), ("label", str), ("file_name", str)])(1, "test", "test.bpr")
|
||||
with pytest.raises(error_mngr.LonelyOptionalError):
|
||||
raise(error_mngr.LonelyOptionalError(tk, None))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue