From 89694ec8f685e545585b96b2db6e5410ba117527 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 20 Mar 2020 08:50:34 +0100 Subject: Support arbitrary discriminants Closes #3661 --- crates/ra_parser/src/grammar/items/adt.rs | 10 +++++--- .../parser/inline/ok/0157_variant_discriminant.rs | 1 + .../parser/inline/ok/0157_variant_discriminant.txt | 30 ++++++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 crates/ra_syntax/test_data/parser/inline/ok/0157_variant_discriminant.rs create mode 100644 crates/ra_syntax/test_data/parser/inline/ok/0157_variant_discriminant.txt (limited to 'crates') diff --git a/crates/ra_parser/src/grammar/items/adt.rs b/crates/ra_parser/src/grammar/items/adt.rs index c777bc9d0..74b9f514b 100644 --- a/crates/ra_parser/src/grammar/items/adt.rs +++ b/crates/ra_parser/src/grammar/items/adt.rs @@ -83,12 +83,14 @@ pub(crate) fn enum_variant_list(p: &mut Parser) { match p.current() { T!['{'] => record_field_def_list(p), T!['('] => tuple_field_def_list(p), - T![=] => { - p.bump(T![=]); - expressions::expr(p); - } _ => (), } + + // test variant_discriminant + // enum E { X(i32) = 10 } + if p.eat(T![=]) { + expressions::expr(p); + } var.complete(p, ENUM_VARIANT); } else { var.abandon(p); diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0157_variant_discriminant.rs b/crates/ra_syntax/test_data/parser/inline/ok/0157_variant_discriminant.rs new file mode 100644 index 000000000..c8c5c0f17 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0157_variant_discriminant.rs @@ -0,0 +1 @@ +enum E { X(i32) = 10 } diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0157_variant_discriminant.txt b/crates/ra_syntax/test_data/parser/inline/ok/0157_variant_discriminant.txt new file mode 100644 index 000000000..a378dd80b --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0157_variant_discriminant.txt @@ -0,0 +1,30 @@ +SOURCE_FILE@[0; 23) + ENUM_DEF@[0; 22) + ENUM_KW@[0; 4) "enum" + WHITESPACE@[4; 5) " " + NAME@[5; 6) + IDENT@[5; 6) "E" + WHITESPACE@[6; 7) " " + ENUM_VARIANT_LIST@[7; 22) + L_CURLY@[7; 8) "{" + WHITESPACE@[8; 9) " " + ENUM_VARIANT@[9; 20) + NAME@[9; 10) + IDENT@[9; 10) "X" + TUPLE_FIELD_DEF_LIST@[10; 15) + L_PAREN@[10; 11) "(" + TUPLE_FIELD_DEF@[11; 14) + PATH_TYPE@[11; 14) + PATH@[11; 14) + PATH_SEGMENT@[11; 14) + NAME_REF@[11; 14) + IDENT@[11; 14) "i32" + R_PAREN@[14; 15) ")" + WHITESPACE@[15; 16) " " + EQ@[16; 17) "=" + WHITESPACE@[17; 18) " " + LITERAL@[18; 20) + INT_NUMBER@[18; 20) "10" + WHITESPACE@[20; 21) " " + R_CURLY@[21; 22) "}" + WHITESPACE@[22; 23) "\n" -- cgit v1.2.3