Skip to content
This repository has been archived by the owner on Aug 17, 2023. It is now read-only.

Newline Fix #75

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions hamlpy/parser/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ def read_node(stream, prev, compiler):
if indent:
indent = indent[0] * len(indent)

# empty lines with carriage returns are recorded as newlines on previous node
# if followed by a newline, it is skipped
if stream.text[stream.ptr] == '\r':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it would be easier to understand this if it was happening at the stream level.. what if we added def is_newline() and def read_newline() to the Stream class?

if prev:
prev.newlines += 1
stream.ptr += 1
if stream.text[stream.ptr] == '\n':
stream.ptr += 1
continue

# empty lines are recorded as newlines on previous node
if stream.text[stream.ptr] == '\n':
if prev:
Expand Down