aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/parser/event_parser/grammar/expressions.rs6
-rw-r--r--src/parser/event_parser/grammar/items/mod.rs9
-rw-r--r--src/parser/event_parser/grammar/items/structs.rs34
-rw-r--r--src/syntax_kinds.rs4
-rw-r--r--src/tree/mod.rs14
5 files changed, 64 insertions, 3 deletions
diff --git a/src/parser/event_parser/grammar/expressions.rs b/src/parser/event_parser/grammar/expressions.rs
index c81dc6c35..8caaf3553 100644
--- a/src/parser/event_parser/grammar/expressions.rs
+++ b/src/parser/event_parser/grammar/expressions.rs
@@ -12,3 +12,9 @@ pub(super) fn literal(p: &mut Parser) -> bool {
12 _ => false, 12 _ => false,
13 } 13 }
14} 14}
15
16pub(super) fn expr(p: &mut Parser) {
17 if !literal(p) {
18 p.error().message("expected expression").emit();
19 }
20}
diff --git a/src/parser/event_parser/grammar/items/mod.rs b/src/parser/event_parser/grammar/items/mod.rs
index f10fb230b..0a50fffc1 100644
--- a/src/parser/event_parser/grammar/items/mod.rs
+++ b/src/parser/event_parser/grammar/items/mod.rs
@@ -9,8 +9,9 @@ pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) {
9 } 9 }
10} 10}
11 11
12pub(super) const ITEM_FIRST: TokenSet = 12pub(super) const ITEM_FIRST: TokenSet = token_set![
13 token_set![EXTERN_KW, MOD_KW, USE_KW, STRUCT_KW, FN_KW, PUB_KW, POUND,]; 13 EXTERN_KW, MOD_KW, USE_KW, STRUCT_KW, ENUM_KW, FN_KW, PUB_KW, POUND
14];
14 15
15fn item(p: &mut Parser) { 16fn item(p: &mut Parser) {
16 let item = p.start(); 17 let item = p.start();
@@ -34,6 +35,10 @@ fn item(p: &mut Parser) {
34 structs::struct_item(p); 35 structs::struct_item(p);
35 STRUCT_ITEM 36 STRUCT_ITEM
36 } 37 }
38 ENUM_KW => {
39 structs::enum_item(p);
40 ENUM_ITEM
41 }
37 FN_KW => { 42 FN_KW => {
38 fn_item(p); 43 fn_item(p);
39 FN_ITEM 44 FN_ITEM
diff --git a/src/parser/event_parser/grammar/items/structs.rs b/src/parser/event_parser/grammar/items/structs.rs
index 0934f3d28..6e438413b 100644
--- a/src/parser/event_parser/grammar/items/structs.rs
+++ b/src/parser/event_parser/grammar/items/structs.rs
@@ -40,6 +40,40 @@ pub(super) fn struct_item(p: &mut Parser) {
40 } 40 }
41} 41}
42 42
43pub(super) fn enum_item(p: &mut Parser) {
44 assert!(p.at(ENUM_KW));
45 p.bump();
46 p.expect(IDENT);
47 type_param_list(p);
48 where_clause(p);
49 if p.expect(L_CURLY) {
50 while !p.at(EOF) && !p.at(R_CURLY) {
51 let var = p.start();
52 attributes::outer_attributes(p);
53 if p.at(IDENT) {
54 p.bump();
55 match p.current() {
56 L_CURLY => named_fields(p),
57 L_PAREN => pos_fields(p),
58 EQ => {
59 p.bump();
60 expressions::expr(p);
61 }
62 _ => (),
63 }
64 var.complete(p, ENUM_VARIANT);
65 } else {
66 var.abandon(p);
67 p.err_and_bump("expected enum variant");
68 }
69 if !p.at(R_CURLY) {
70 p.expect(COMMA);
71 }
72 }
73 p.expect(R_CURLY);
74 }
75}
76
43fn named_fields(p: &mut Parser) { 77fn named_fields(p: &mut Parser) {
44 assert!(p.at(L_CURLY)); 78 assert!(p.at(L_CURLY));
45 p.bump(); 79 p.bump();
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs
index b6c281cd5..519326f48 100644
--- a/src/syntax_kinds.rs
+++ b/src/syntax_kinds.rs
@@ -76,6 +76,8 @@ pub enum SyntaxKind {
76 SHEBANG, 76 SHEBANG,
77 FILE, 77 FILE,
78 STRUCT_ITEM, 78 STRUCT_ITEM,
79 ENUM_ITEM,
80 ENUM_VARIANT,
79 NAMED_FIELD, 81 NAMED_FIELD,
80 POS_FIELD, 82 POS_FIELD,
81 FN_ITEM, 83 FN_ITEM,
@@ -176,6 +178,8 @@ impl SyntaxKind {
176 SHEBANG => &SyntaxInfo { name: "SHEBANG" }, 178 SHEBANG => &SyntaxInfo { name: "SHEBANG" },
177 FILE => &SyntaxInfo { name: "FILE" }, 179 FILE => &SyntaxInfo { name: "FILE" },
178 STRUCT_ITEM => &SyntaxInfo { name: "STRUCT_ITEM" }, 180 STRUCT_ITEM => &SyntaxInfo { name: "STRUCT_ITEM" },
181 ENUM_ITEM => &SyntaxInfo { name: "ENUM_ITEM" },
182 ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" },
179 NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, 183 NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" },
180 POS_FIELD => &SyntaxInfo { name: "POS_FIELD" }, 184 POS_FIELD => &SyntaxInfo { name: "POS_FIELD" },
181 FN_ITEM => &SyntaxInfo { name: "FN_ITEM" }, 185 FN_ITEM => &SyntaxInfo { name: "FN_ITEM" },
diff --git a/src/tree/mod.rs b/src/tree/mod.rs
index 795f23f42..9ed0504c7 100644
--- a/src/tree/mod.rs
+++ b/src/tree/mod.rs
@@ -106,7 +106,19 @@ impl<'f> Node<'f> {
106 106
107impl<'f> fmt::Debug for Node<'f> { 107impl<'f> fmt::Debug for Node<'f> {
108 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { 108 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
109 write!(fmt, "{:?}@{:?}", self.kind(), self.range()) 109 write!(fmt, "{:?}@{:?}", self.kind(), self.range())?;
110 if has_short_text(self.kind()) {
111 write!(fmt, " \"{}\"", self.text())?;
112 }
113 Ok(())
114 }
115}
116
117fn has_short_text(kind: SyntaxKind) -> bool {
118 use syntax_kinds::*;
119 match kind {
120 IDENT | LIFETIME => true,
121 _ => false,
110 } 122 }
111} 123}
112 124