mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 04:08:19 +00:00
Support '??' syntax for optional record fields
This commit is contained in:
parent
3d4dd5b583
commit
a24fe430b4
21 changed files with 42 additions and 43 deletions
|
@ -2082,6 +2082,7 @@ pub fn merge_spaces<'a>(
|
|||
/// If the given Expr would parse the same way as a valid Pattern, convert it.
|
||||
/// Example: (foo) could be either an Expr::Var("foo") or Pattern::Identifier("foo")
|
||||
fn expr_to_pattern_help<'a>(arena: &'a Bump, expr: &Expr<'a>) -> Result<Pattern<'a>, ()> {
|
||||
println!("expr_to_pattern_help");
|
||||
let mut expr = expr.extract_spaces();
|
||||
|
||||
while let Expr::ParensAround(loc_expr) = &expr.item {
|
||||
|
@ -3587,7 +3588,10 @@ pub fn record_field<'a>() -> impl Parser<'a, RecordField<'a>, ERecord<'a>> {
|
|||
optional(either(
|
||||
and(byte(b':', ERecord::Colon), record_field_expr()),
|
||||
and(
|
||||
byte(b'?', ERecord::QuestionMark),
|
||||
and(
|
||||
byte(b'?', ERecord::QuestionMark),
|
||||
optional(byte(b'?', ERecord::QuestionMark)),
|
||||
),
|
||||
spaces_before(specialize_err_ref(ERecord::Expr, loc_expr(true))),
|
||||
),
|
||||
)),
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::blankspace::{space0_before_optional_after, space0_e, spaces, spaces_b
|
|||
use crate::ident::{lowercase_ident, parse_ident, Accessor, Ident};
|
||||
use crate::keyword;
|
||||
use crate::parser::{
|
||||
self, backtrackable, byte, collection_trailing_sep_e, fail_when, loc, map, map_with_arena,
|
||||
self, and, backtrackable, byte, collection_trailing_sep_e, fail_when, loc, map, map_with_arena,
|
||||
optional, skip_first, skip_second, specialize_err, specialize_err_ref, then, three_bytes,
|
||||
two_bytes, zero_or_more, EPattern, PInParens, PList, PRecord, Parser,
|
||||
};
|
||||
|
@ -551,7 +551,10 @@ fn record_pattern_field<'a>() -> impl Parser<'a, Loc<Pattern<'a>>, PRecord<'a>>
|
|||
// (This is true in both literals and types.)
|
||||
let (_, opt_loc_val, state) = optional(either(
|
||||
byte(b':', PRecord::Colon),
|
||||
byte(b'?', PRecord::Optional),
|
||||
and(
|
||||
byte(b'?', PRecord::Optional),
|
||||
optional(byte(b'?', PRecord::Optional)),
|
||||
),
|
||||
))
|
||||
.parse(arena, state, min_indent)?;
|
||||
|
||||
|
|
|
@ -588,7 +588,10 @@ fn record_type_field<'a>() -> impl Parser<'a, AssignedField<'a, TypeAnnotation<'
|
|||
// (This is true in both literals and types.)
|
||||
let (_, opt_loc_val, state) = optional(either(
|
||||
byte(b':', ETypeRecord::Colon),
|
||||
byte(b'?', ETypeRecord::Optional),
|
||||
and(
|
||||
byte(b'?', ETypeRecord::Optional),
|
||||
optional(byte(b'?', ETypeRecord::Optional)),
|
||||
),
|
||||
))
|
||||
.parse(arena, state, min_indent)?;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue