[wadler] Prettier handling of trivia

Split the rules for pre- and post- trivia, understand when we want to
do either, handle multi-line-break (in an unsatisfying way, I guess)
but otherwise lay the groundwork for thinking about it better.

Also now we don't generate lazy "Text" nodes because I thought I might
want to actually look at the newlines in the source but I don't yet.
I *can* now, though. (I can also detect EOF so there's that.)
This commit is contained in:
John Doty 2024-09-19 16:39:32 -07:00
parent c31d527077
commit 8a17cfd586
5 changed files with 159 additions and 108 deletions

View file

@ -2109,6 +2109,10 @@ class Re:
UNICODE_MAX_CP = 1114112
def _str_repr(x: int) -> str:
return repr(chr(x))[1:-1]
@dataclasses.dataclass
class ReSet(Re):
values: list[Span]
@ -2165,12 +2169,12 @@ class ReSet(Re):
if len(self.values) == 1:
span = self.values[0]
if len(span) == 1:
return chr(span.lower)
return _str_repr(span.lower)
ranges = []
for span in self.values:
start = chr(span.lower)
end = chr(span.upper - 1)
start = _str_repr(span.lower)
end = _str_repr(span.upper - 1)
if start == end:
ranges.append(start)
else:
@ -2736,7 +2740,7 @@ class TriviaMode(enum.Enum):
pretty-printing. Attach this to a "trivia_mode" property on a Terminal
definition.
- Ignore means that the trivia should be ignored. (This is the default.)
- Blank means that the trivia represents blank space. (This is the default.)
- NewLine means that the trivia is a line break. This is important for
other modes, specifically...
@ -2748,7 +2752,7 @@ class TriviaMode(enum.Enum):
a forced break.
"""
Ignore = 0
Blank = 0
NewLine = 1
LineComment = 2