Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions crates/parser/src/grammar/items/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,27 @@ pub(crate) fn variant_list(p: &mut Parser<'_>) {
attributes::outer_attrs(p);
if p.at(IDENT) {
name(p);
match p.current() {
T!['{'] => record_field_list(p),
T!['('] => tuple_field_list(p),
_ => (),
}

// test variant_discriminant
// enum E { X(i32) = 10 }
if p.eat(T![=]) {
let m = p.start();
expressions::expr(p);
m.complete(p, CONST_ARG);
}
m.complete(p, VARIANT);
} else if p.at(T![_]) {
p.bump(T![_]);
} else {
m.abandon(p);
p.err_and_bump("expected enum variant");
return;
}
match p.current() {
T!['{'] => record_field_list(p),
T!['('] => tuple_field_list(p),
_ => (),
}

// test variant_discriminant
// enum E { X(i32) = 10 }
if p.eat(T![=]) {
let m = p.start();
expressions::expr(p);
m.complete(p, CONST_ARG);
}
m.complete(p, VARIANT);
}
}

Expand Down
10 changes: 10 additions & 0 deletions crates/parser/test_data/parser/ok/0019_enums.rast
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ SOURCE_FILE
L_PAREN "("
R_PAREN ")"
COMMA ","
WHITESPACE "\n "
VARIANT
UNDERSCORE "_"
WHITESPACE " "
EQ "="
WHITESPACE " "
CONST_ARG
RANGE_EXPR
DOT2 ".."
COMMA ","
WHITESPACE "\n"
R_CURLY "}"
WHITESPACE "\n"
1 change: 1 addition & 0 deletions crates/parser/test_data/parser/ok/0019_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ enum E5 {
F {},
D(u32,),
E(),
_ = ..,
}
2 changes: 1 addition & 1 deletion crates/syntax/rust.ungram
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ VariantList =

Variant =
Attr* Visibility?
Name FieldList? ('=' ConstArg)?
(Name | '_') FieldList? ('=' ConstArg)?

Union =
Attr* Visibility?
Expand Down
2 changes: 2 additions & 0 deletions crates/syntax/src/ast/generated/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2059,6 +2059,8 @@ impl Variant {
pub fn field_list(&self) -> Option<FieldList> { support::child(&self.syntax) }
#[inline]
pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
#[inline]
pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) }
}
pub struct VariantList {
pub(crate) syntax: SyntaxNode,
Expand Down
Loading