Closed OceanOak closed 7 months ago
I wonder if we could write a function in our grammar.js that would abstract over this pattern
choice(
seq(
$.indent,
repeat1(field("then_expression", $.expression)),
$.dedent,
),
field("then_expression", $.paren_expression),
),
like
let maybeWithIndentDedent (thing) =
choice(
seq($.indent, thing, $.dedent),
thing,
),
I wonder if we could write a function in our grammar.js that would abstract over this pattern
choice( seq( $.indent, repeat1(field("then_expression", $.expression)), $.dedent, ), field("then_expression", $.paren_expression), ),
like
let maybeWithIndentDedent (thing) = choice( seq($.indent, thing, $.dedent), thing, ),
Some initial thoughts:
$.indent
and $.dedent
since they're defined after the function's declaration
i.e.
let maybeWithIndentDedent ....
module.exports = grammar({ name: "darklang",
// I believe we can't declare that function here ...
so, the function would probably be more like
let maybeWithIndentDedent = (indent, thing, dedent) => choice(seq(indent, thing, dedent), thing);
- Losing the field names would make it challenging to capture in the parser, no?
**Unrelated note:**
we still need to wrap the 'then' expression in parentheses (only when writing an inline if/else expression) due to conflicts. planning to address this when fixing `apply`...
Changelog:
5321