[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:
parent
c31d527077
commit
8a17cfd586
5 changed files with 159 additions and 108 deletions
|
|
@ -24,7 +24,7 @@ class FineGrammar(Grammar):
|
|||
# generator = parser.GenerateLR1
|
||||
start = "File"
|
||||
|
||||
trivia = ["BLANKS", "LINE_BREAKS", "COMMENT"]
|
||||
trivia = ["BLANKS", "LINE_BREAK", "COMMENT"]
|
||||
|
||||
pretty_indent = " "
|
||||
|
||||
|
|
@ -426,7 +426,7 @@ class FineGrammar(Grammar):
|
|||
return self.IDENTIFIER | group(self.IDENTIFIER, self.COLON, indent(sp, self.expression))
|
||||
|
||||
BLANKS = Terminal(Re.set(" ", "\t").plus())
|
||||
LINE_BREAKS = Terminal(Re.set("\r", "\n").plus(), trivia_mode=TriviaMode.NewLine)
|
||||
LINE_BREAK = Terminal(Re.set("\r", "\n"), trivia_mode=TriviaMode.NewLine)
|
||||
COMMENT = Terminal(
|
||||
Re.seq(Re.literal("//"), Re.set("\n").invert().star()),
|
||||
highlight=highlight.comment.line,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue