4 ms·
I believe the way it's usually done is to always parse a tuple, then parse the arrow as a binary operator applied to the two surrounding expressions. This poten
by drakmaniso 6y ago
I believe the way it's usually done is to always parse a tuple, then parse the arrow as a binary operator applied to the two surrounding expressions. This potentially produce a syntactically incorrect AST (e.g. if there is an arrow following a tuple containing numbers), so you need to detect those in another pass and produce the corresponding error.
- tgv 6y agoCan be done in one go: just check the type of the left and right operand at the end of X -> expr "=>" expr, or assign "=>" the highest priority when following a tuple, X -> tuple ("=>" "{" body "}")?.
- hardwaregeek 6y agoWhat's subtly tricky about my language is that not all function arguments are valid expressions. For instance I allow: (a: int, b: float, c) => { .... which is not a valid tuple expression. Just had to make my life harder haha