darklang / dark

Darklang main repo, including language, backend, and infra
https://darklang.com
Other
1.65k stars 90 forks source link

Tree-sitter grammar: support match expressions #5364

Closed OceanOak closed 3 months ago

OceanOak commented 3 months ago

Changelog:

Tree-sitter-darklang
- Update the grammar to support match expressions

5321

OceanOak commented 3 months ago

Questions:

StachuDotNet commented 3 months ago
  • What should we do about wildcard eg. Error _ -> ... or | _ -> ... we can add support for it in the grammar, but I am not sure how it will be captured in writtenTypes. Could you please provide some insights on this?

It's OK to capture these as Variable match patterns. Maybe someday we'll have a separate Wildcard MatchPattern, though -- I've thought that for a while - I'm not sure, then, what _this would be captured as (wildcard or variable?).

  • why don't we have MPDict?

I'm not sure what that would look like. I don't believe similar languages have one we could use for inspiration (besides's F#'s record pattern but I don't think it perfectly applies). I suppose the answer here is that our other match patterns are used to deconstruct structures and extract values out of them, safely, but the fields of a dict are unstable, so unsafe to deconstruct them Also, our other patterns can be checked at parse-time, whereas a dict one (if we could imagine how it looks) probably couldn't.