I've been working on https://github.com/roc-lang/roc/issues/6532, and I've got a representation question. The two options I see for the AST to represent something like {x: x1 ? 0.0}
is to:
Pattern::AliasedOptionalField
that holds a references to x
, x1
as a Pattern::Identifier
, and 0.0
as an Expr
.Pattern::RequiredField
hold a reference to a Patter::OptionalField
in this case.Option 1 seems to be more semantically correct, while option 2 seems like an easier change. I'm inclined to go with option 1, but wanted to get some feedback before I get too far. Is there another option I'm missing here?
@Brendan Hansknecht and @Luke Boswell, you may have some input here as I mentioned this a different stream. I didn't want to derail that, so I thought I should move the conversation here
I'm barely qualified to comment on this, but I feel like I'd try Option 1 first.
I'm not sure how it flows through to Can and later stages... so that would be where i would be looking to see what makes the most sense.
I'm getting stuck trying to figure out parsing for this one. Is anyone familiar with the parser able to help?
I've modified the roc_parse::parse::record_pattern_help
so that it can parse the new syntax in a test, but when I try to run the whole compiler, the new code doesn't seem to get run. It seems like another part of the parser is recognizing it. I've also tried looking for other uses of collection_trailing_sep_e
, but the only other usage that seemed similar was in the record_type
function
@Joshua Warner and @Ayaz Hafiz know the most about the parser. Maybe @Folkert de Vries has some idea as well?
I can probably help, but not until tomorrow sometime.
Do you have a WIP branch?
Ok, cool. I've got this PR. I've done a few more exploratory changes, but nothing that I've committed and pushed
Cool. I'm quite terrible I think with the parser, but I have spent the last couple of weeks looking at it trying to figure out how it works.
So hopefully I cant help
You should be able to run with --features=parse_debug_trace
, and it'll print out a bunch of useful debug information about what the parser is doing
Yeah, I did end up finding that, as well. That's what allowed me to figure out exactly what was running. Great tip!
Last updated: Jul 06 2025 at 12:14 UTC