Haskell's layout indentation? #651
Replies: 6 comments
-
I think you could make it work with same level and deeper level of indentation, but I don't really understand how the shallower indentation works. Is it |
Beta Was this translation helpful? Give feedback.
-
Sorry, let me clarify in the OP ETA: basically, a layout starts at the first non-space item, and every subsequent line indented to the same column is an item in the layout. Every deeper-indented line is a part of the above item, and the layout ends at the first shallower indented line. |
Beta Was this translation helpful? Give feedback.
-
This is definitely possible. It's not the most trivial of approaches, but I find it quite elegant. The idea behind this is that you know how long |
Beta Was this translation helpful? Give feedback.
-
Yeah, the problem is that the layout keywords constitute expressions themselves, so they can be preceded by arbitrary tokens. Maybe I can peek on the line if it contains a keyword, but I don’t understand how to “push whitespace instead” ETA there’s also the issue of the indentation level being given on the same line as the layout keyword. |
Beta Was this translation helpful? Give feedback.
-
Are the arbitrary tokens on the same line? |
Beta Was this translation helpful? Give feedback.
-
The link (https://pest.rs/?bin=jgwd2#editor) seems dead, do you have the grammar somewhere ? I'm also interested about it |
Beta Was this translation helpful? Give feedback.
-
Haskell uses a peculiar form of significant whitespace.
When a 'layout' keyword appears in the source code, the next non-whitespace source element determines the indentation; even if it appears on the same line as the keyword. Subsequent lines are parsed based on whether they are of greater, lesser, or the same indentation.
AFAICT, this form of matching isn't possible. Perhaps a way to match on the current column? A way to unconditionally push strings?
Beta Was this translation helpful? Give feedback.
All reactions