Commit Graph

7 Commits

Author SHA1 Message Date
KtorZ
5c59b816ea Add parser for 'Pair' pattern
And a few more tests along the way for others. Note that it is important here that we try to parse for a 'Pair' BEFORE we try to parse for a constructor pattern. Because the latter would swallow any Pair pattern.
2024-05-04 14:04:12 -04:00
rvcas
1b8e94fe32 feat: expect boolean sugar 2023-07-15 20:50:02 -04:00
KtorZ
78d34f7f76 Fix parsing of negative int patterns and constants
This was trickier than expected as the expression parser, and in particular the bin-op parser will interpret negative patterns as a continuation of a binary operation and eventually choke on the next right-arrow symbol. This is due to how we actually completely erase newlines once we're done with the lexer. The newline separating when clause is actually semantically important. In principle, we could only parse an expression until the next newline.

  Ideally, we would keep that newline in the list of token but it's difficult to figure out which newline to keep between two right arrows since a clause guard can be written over multiple lines. Though, since we know that this is only truly a problem for negative integers, we can use the same trick as for tuples and define a new 'NewLineMinus' token. That token CANNOT be part of a binop expression. That means it's impossible to write a binary operation with a minus over multiple lines, or more specifically, with the '-' symbol on a newline. This sounds like a fair limitation. What we get in exchange is less ambiguity when parsing patterns following expressions in when clause cases.

  Another more cumbersome option could be to preserve the first newline encountered after a 'right-arrow' symbol and before any parenthesis or curly brace is found (which would otherwise signal the beginning of a new block). That requires to traverse, at least partially, the list of tokens twice. This feels unnecessary for now and until we do face a similar issue with a binary operator.
2023-07-06 16:10:46 -04:00
KtorZ
5a4a2faa4d Split pattern parser into individual modules. 2023-07-06 16:10:46 -04:00
KtorZ
4f6defcf3e rename: 'r' → 'expression' & 'seq_r' → 'sequence'
Better readability.
2023-07-05 14:42:14 +02:00
rvcas
eea94fc9a4 feat: move anon fn, let, and expect 2023-07-04 17:19:28 -04:00
rvcas
e3ed5d3b00 feat: move expr_parser and remove module.rs to definitions 2023-07-04 17:19:28 -04:00