diff --git a/bikeshed/h/parser/nodes.py b/bikeshed/h/parser/nodes.py index 09f95a586b..dc77b6974c 100644 --- a/bikeshed/h/parser/nodes.py +++ b/bikeshed/h/parser/nodes.py @@ -14,9 +14,10 @@ class ParserNode(metaclass=ABCMeta): endLine: int @property - def height(self): + def height(self) -> int: return self.endLine - self.line + @dataclass class Text(ParserNode, metaclass=ABCMeta): text: str @@ -43,7 +44,7 @@ def curlifyApostrophes(self, lastNode: ParserNode | None) -> RawText: self.text = re.sub(r"(\w)'(\w)", r"\1’\2", self.text) return self - def needsLCCs(self): + def needsLCCs(self) -> bool: """ Whether or not the node will eventally insert an ILCC or DLCC to fix the line count when serializing to a string. diff --git a/bikeshed/h/parser/parser.py b/bikeshed/h/parser/parser.py index 4eca9776de..3ea35139bf 100644 --- a/bikeshed/h/parser/parser.py +++ b/bikeshed/h/parser/parser.py @@ -29,6 +29,7 @@ def nodesFromStream(s: Stream, start: int) -> t.Generator[ParserNode, None, None node.curlifyApostrophes(lastNode) if node.needsLCCs(): if heldLast: + assert lastNode is not None yield lastNode yield node lastNode = node @@ -42,30 +43,27 @@ def nodesFromStream(s: Stream, start: int) -> t.Generator[ParserNode, None, None heldLast = True else: if heldLast: + assert lastNode is not None yield lastNode yield node lastNode = node heldLast = False if heldLast: + assert lastNode is not None yield lastNode def generateNodes(s: Stream, start: int) -> t.Generator[ParserNode, None, None]: i = start end = len(s) - context = s.config.context while i < end: nodes, i = parseAnything(s, i).vi if nodes is None: return elif isinstance(nodes, list): for node in nodes: - if context is not None: - node.context = context yield node else: - if context is not None: - nodes.context = context yield nodes