leostera / caramel

:candy: a functional language for building type-safe, scalable, and maintainable applications
https://caramel.run
Apache License 2.0
1.06k stars 25 forks source link

Support parsing of Erlang expression sequences #14

Closed leostera closed 3 years ago

leostera commented 4 years ago

The following Erlang code:

A, B, C.

Should parse to the equivalent AST:

open Erlang.Std.Ast_helper

Expr.sequence
   (Expr.ident (Name.var "A"))
   (Expr.sequence
      (Expr.ident (Name.var "B"))
      (Expr.ident (Name.var "C")))

So this looks like a degenerate case of let binding, where the expression A is bound to _. At the moment that's how this is being worked around, so _ = A, can be parsed, and is equivalent to A.

There is definitely work to be done in ./src/erlang/erl_parser.mly, and for inspiration we can look at the way the OCaml language parser is written to handle them: https://github.com/ocaml/ocaml/blob/trunk/parsing/parser.mly#L2075-L2084

leostera commented 3 years ago

This is currently possible thanks to the tree-sitter-erlang grammar.