Compare commits
No commits in common. "63bb1e67e0e312c35f0d0c85269330da9f3e8d28" and "eacbcce376962e6f57b3413bf486d3bbf502990b" have entirely different histories.
63bb1e67e0
...
eacbcce376
@ -17,18 +17,7 @@ class LogbookDrawerNode:
|
|||||||
self.children.append(child)
|
self.children.append(child)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<LogBook: {}>".format(len(self.children))
|
return "<Properties: {}>".format(len(self.children))
|
||||||
|
|
||||||
|
|
||||||
class ResultsDrawerNode:
|
|
||||||
def __init__(self):
|
|
||||||
self.children = []
|
|
||||||
|
|
||||||
def append(self, child):
|
|
||||||
self.children.append(child)
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return "<Results: {}>".format(len(self.children))
|
|
||||||
|
|
||||||
|
|
||||||
class PropertyNode:
|
class PropertyNode:
|
||||||
|
@ -98,7 +98,7 @@ RESULTS_DRAWER_RE = re.compile(r"^\s*:results:\s*$", re.I)
|
|||||||
CodeSnippet = collections.namedtuple("CodeSnippet", ("name", "content", "result"))
|
CodeSnippet = collections.namedtuple("CodeSnippet", ("name", "content", "result"))
|
||||||
|
|
||||||
# Groupings
|
# Groupings
|
||||||
NON_FINISHED_GROUPS = (type(None), dom.ListGroupNode, dom.ResultsDrawerNode, dom.PropertyDrawerNode)
|
NON_FINISHED_GROUPS = (type(None), dom.ListGroupNode)
|
||||||
FREE_GROUPS = (dom.CodeBlock,)
|
FREE_GROUPS = (dom.CodeBlock,)
|
||||||
|
|
||||||
|
|
||||||
@ -181,9 +181,9 @@ def text_to_dom(tokens, item):
|
|||||||
in_description = False
|
in_description = False
|
||||||
link_value = []
|
link_value = []
|
||||||
link_description = []
|
link_description = []
|
||||||
|
|
||||||
contents = []
|
contents = []
|
||||||
|
|
||||||
for tok in tokens:
|
for tok in tokens:
|
||||||
if isinstance(tok, LinkToken):
|
if isinstance(tok, LinkToken):
|
||||||
if tok.tok_type == LinkTokenType.OPEN_LINK:
|
if tok.tok_type == LinkTokenType.OPEN_LINK:
|
||||||
@ -362,7 +362,7 @@ class Headline:
|
|||||||
current_node.append(dom.Text(line))
|
current_node.append(dom.Text(line))
|
||||||
else:
|
else:
|
||||||
if type(current_node) not in NON_FINISHED_GROUPS:
|
if type(current_node) not in NON_FINISHED_GROUPS:
|
||||||
raise NotImplementedError('Not implemented node type: {}'.format(current_node))
|
assert type(current_node) in NON_FINISHED_GROUPS
|
||||||
current_node = None
|
current_node = None
|
||||||
contents = []
|
contents = []
|
||||||
tree.append(dom.Text(text_to_dom(line.contents, line)))
|
tree.append(dom.Text(text_to_dom(line.contents, line)))
|
||||||
@ -373,9 +373,7 @@ class Headline:
|
|||||||
tree.append(current_node)
|
tree.append(current_node)
|
||||||
indentation_tree = [current_node]
|
indentation_tree = [current_node]
|
||||||
if not isinstance(current_node, dom.ListGroupNode):
|
if not isinstance(current_node, dom.ListGroupNode):
|
||||||
if not isinstance(current_node, dom.ListGroupNode):
|
assert isinstance(current_node, dom.ListGroupNode)
|
||||||
logging.warning("Expected a {}, found: {} on line {}".format(dom.ListGroupNode, current_node, line.linenum))
|
|
||||||
# This can happen. Frequently inside a LogDrawer
|
|
||||||
|
|
||||||
if len(indentation_tree) > 0 and (
|
if len(indentation_tree) > 0 and (
|
||||||
(len(indentation_tree[-1].children) > 0)
|
(len(indentation_tree[-1].children) > 0)
|
||||||
@ -449,21 +447,10 @@ class Headline:
|
|||||||
current_node = dom.LogbookDrawerNode()
|
current_node = dom.LogbookDrawerNode()
|
||||||
tree.append(current_node)
|
tree.append(current_node)
|
||||||
elif content.strip().upper() == ":END:":
|
elif content.strip().upper() == ":END:":
|
||||||
if current_node is None:
|
assert isinstance(
|
||||||
logging.warning('Finished node (:END:) with no known starter')
|
|
||||||
elif not (isinstance(
|
|
||||||
current_node, dom.PropertyDrawerNode
|
current_node, dom.PropertyDrawerNode
|
||||||
) or isinstance(
|
) or isinstance(current_node, dom.LogbookDrawerNode)
|
||||||
current_node, dom.LogbookDrawerNode
|
|
||||||
) or isinstance(
|
|
||||||
current_node, dom.ResultsDrawerNode
|
|
||||||
)):
|
|
||||||
raise Exception('Unexpected node: {}'.format(current_node))
|
|
||||||
current_node = None
|
current_node = None
|
||||||
elif content.strip().upper() == ":RESULTS:":
|
|
||||||
assert current_node is None
|
|
||||||
current_node = dom.ResultsDrawerNode()
|
|
||||||
tree.append(current_node)
|
|
||||||
else:
|
else:
|
||||||
raise Exception("Unknown structural line: {}".format(line))
|
raise Exception("Unknown structural line: {}".format(line))
|
||||||
else:
|
else:
|
||||||
@ -1489,9 +1476,6 @@ def parse_headline(hl, doc, parent) -> Headline:
|
|||||||
|
|
||||||
contents = parse_contents(hl["contents"])
|
contents = parse_contents(hl["contents"])
|
||||||
|
|
||||||
if not (isinstance(parent, OrgDoc) or depth > parent.depth):
|
|
||||||
raise AssertionError("Incorrectly parsed parent on `{}' > `{}'".format(parent.title, title))
|
|
||||||
|
|
||||||
headline = Headline(
|
headline = Headline(
|
||||||
start_line=hl["linenum"],
|
start_line=hl["linenum"],
|
||||||
depth=depth,
|
depth=depth,
|
||||||
@ -1797,26 +1781,18 @@ class OrgDocReader:
|
|||||||
"list_items": [],
|
"list_items": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
while (depth - 1) > len(self.headline_hierarchy):
|
while (depth - 2) > len(self.headline_hierarchy):
|
||||||
# Introduce structural headlines
|
# Introduce structural headlines
|
||||||
self.headline_hierarchy.append(None)
|
self.headline_hierarchy.append(None)
|
||||||
while depth <= len(self.headline_hierarchy):
|
while depth < len(self.headline_hierarchy):
|
||||||
self.headline_hierarchy.pop()
|
self.headline_hierarchy.pop()
|
||||||
|
|
||||||
if depth == 1:
|
if depth == 1:
|
||||||
self.headlines.append(headline)
|
self.headlines.append(headline)
|
||||||
else:
|
else:
|
||||||
parent_idx = len(self.headline_hierarchy) - 1
|
self.headline_hierarchy[-1]["children"].append(headline)
|
||||||
while self.headline_hierarchy[parent_idx] is None:
|
|
||||||
parent_idx -= 1
|
|
||||||
self.headline_hierarchy[parent_idx]["children"].append(headline)
|
|
||||||
self.headline_hierarchy.append(headline)
|
self.headline_hierarchy.append(headline)
|
||||||
|
|
||||||
if all([hl is not None for hl in self.headline_hierarchy]):
|
|
||||||
if not ([ len(hl['orig'].group('stars')) for hl in self.headline_hierarchy ]
|
|
||||||
== list(range(1, len(self.headline_hierarchy) + 1))):
|
|
||||||
raise AssertionError('Error on Headline Hierarchy')
|
|
||||||
|
|
||||||
def add_list_item_line(self, linenum: int, match: re.Match) -> int:
|
def add_list_item_line(self, linenum: int, match: re.Match) -> int:
|
||||||
li = ListItem(
|
li = ListItem(
|
||||||
linenum,
|
linenum,
|
||||||
|
Loading…
Reference in New Issue
Block a user