Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
tabatkins committed Dec 7, 2023
1 parent 17bdea4 commit 9367f19
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 3 additions & 2 deletions bikeshed/h/parser/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
8 changes: 3 additions & 5 deletions bikeshed/h/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down

0 comments on commit 9367f19

Please sign in to comment.