aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/parser/event_parser/grammar/items/consts.rs21
-rw-r--r--src/parser/event_parser/grammar/items/mod.rs33
-rw-r--r--src/syntax_kinds.rs5
3 files changed, 45 insertions, 14 deletions
diff --git a/src/parser/event_parser/grammar/items/consts.rs b/src/parser/event_parser/grammar/items/consts.rs
new file mode 100644
index 000000000..c9881d681
--- /dev/null
+++ b/src/parser/event_parser/grammar/items/consts.rs
@@ -0,0 +1,21 @@
1use super::*;
2
3pub(super) fn static_item(p: &mut Parser) {
4 const_or_static(p, STATIC_KW)
5}
6
7pub(super) fn const_item(p: &mut Parser) {
8 const_or_static(p, CONST_KW)
9}
10
11fn const_or_static(p: &mut Parser, kw: SyntaxKind) {
12 assert!(p.at(kw));
13 p.bump();
14 p.eat(MUT_KW); // TODO: validator to forbid const mut
15 p.expect(IDENT);
16 p.expect(COLON);
17 types::type_ref(p);
18 p.expect(EQ);
19 expressions::expr(p);
20 p.expect(SEMI);
21}
diff --git a/src/parser/event_parser/grammar/items/mod.rs b/src/parser/event_parser/grammar/items/mod.rs
index 9930de347..8ccf8f90f 100644
--- a/src/parser/event_parser/grammar/items/mod.rs
+++ b/src/parser/event_parser/grammar/items/mod.rs
@@ -2,6 +2,7 @@ use super::*;
2 2
3mod structs; 3mod structs;
4mod use_item; 4mod use_item;
5mod consts;
5 6
6pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { 7pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) {
7 attributes::inner_attributes(p); 8 attributes::inner_attributes(p);
@@ -47,9 +48,26 @@ fn item(p: &mut Parser) {
47 } 48 }
48 } 49 }
49 STATIC_KW => { 50 STATIC_KW => {
50 static_item(p); 51 consts::static_item(p);
51 STATIC_ITEM 52 STATIC_ITEM
52 } 53 }
54 CONST_KW => match p.nth(1) {
55 FN_KW => {
56 p.bump();
57 fn_item(p);
58 FN_ITEM
59 }
60 UNSAFE_KW if p.nth(2) == FN_KW => {
61 p.bump();
62 p.bump();
63 fn_item(p);
64 FN_ITEM
65 }
66 _ => {
67 consts::const_item(p);
68 CONST_ITEM
69 }
70 },
53 MOD_KW => { 71 MOD_KW => {
54 mod_item(p); 72 mod_item(p);
55 MOD_ITEM 73 MOD_ITEM
@@ -101,19 +119,6 @@ fn extern_block(p: &mut Parser) {
101 p.bump(); 119 p.bump();
102 p.expect(R_CURLY); 120 p.expect(R_CURLY);
103} 121}
104
105fn static_item(p: &mut Parser) {
106 assert!(p.at(STATIC_KW));
107 p.bump();
108 p.eat(MUT_KW);
109 p.expect(IDENT);
110 p.expect(COLON);
111 types::type_ref(p);
112 p.expect(EQ);
113 expressions::expr(p);
114 p.expect(SEMI);
115}
116
117fn mod_item(p: &mut Parser) { 122fn mod_item(p: &mut Parser) {
118 assert!(p.at(MOD_KW)); 123 assert!(p.at(MOD_KW));
119 p.bump(); 124 p.bump();
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs
index 8d21d3fb7..c182aea78 100644
--- a/src/syntax_kinds.rs
+++ b/src/syntax_kinds.rs
@@ -31,6 +31,7 @@ pub enum SyntaxKind {
31 CONST_KW, 31 CONST_KW,
32 STATIC_KW, 32 STATIC_KW,
33 MUT_KW, 33 MUT_KW,
34 UNSAFE_KW,
34 ERROR, 35 ERROR,
35 IDENT, 36 IDENT,
36 UNDERSCORE, 37 UNDERSCORE,
@@ -90,6 +91,7 @@ pub enum SyntaxKind {
90 MOD_ITEM, 91 MOD_ITEM,
91 USE_ITEM, 92 USE_ITEM,
92 STATIC_ITEM, 93 STATIC_ITEM,
94 CONST_ITEM,
93 EXTERN_BLOCK, 95 EXTERN_BLOCK,
94 ENUM_VARIANT, 96 ENUM_VARIANT,
95 NAMED_FIELD, 97 NAMED_FIELD,
@@ -144,6 +146,7 @@ impl SyntaxKind {
144 CONST_KW => &SyntaxInfo { name: "CONST_KW" }, 146 CONST_KW => &SyntaxInfo { name: "CONST_KW" },
145 STATIC_KW => &SyntaxInfo { name: "STATIC_KW" }, 147 STATIC_KW => &SyntaxInfo { name: "STATIC_KW" },
146 MUT_KW => &SyntaxInfo { name: "MUT_KW" }, 148 MUT_KW => &SyntaxInfo { name: "MUT_KW" },
149 UNSAFE_KW => &SyntaxInfo { name: "UNSAFE_KW" },
147 ERROR => &SyntaxInfo { name: "ERROR" }, 150 ERROR => &SyntaxInfo { name: "ERROR" },
148 IDENT => &SyntaxInfo { name: "IDENT" }, 151 IDENT => &SyntaxInfo { name: "IDENT" },
149 UNDERSCORE => &SyntaxInfo { name: "UNDERSCORE" }, 152 UNDERSCORE => &SyntaxInfo { name: "UNDERSCORE" },
@@ -203,6 +206,7 @@ impl SyntaxKind {
203 MOD_ITEM => &SyntaxInfo { name: "MOD_ITEM" }, 206 MOD_ITEM => &SyntaxInfo { name: "MOD_ITEM" },
204 USE_ITEM => &SyntaxInfo { name: "USE_ITEM" }, 207 USE_ITEM => &SyntaxInfo { name: "USE_ITEM" },
205 STATIC_ITEM => &SyntaxInfo { name: "STATIC_ITEM" }, 208 STATIC_ITEM => &SyntaxInfo { name: "STATIC_ITEM" },
209 CONST_ITEM => &SyntaxInfo { name: "CONST_ITEM" },
206 EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, 210 EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" },
207 ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, 211 ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" },
208 NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, 212 NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" },
@@ -253,6 +257,7 @@ pub(crate) fn ident_to_keyword(ident: &str) -> Option<SyntaxKind> {
253 "const" => Some(CONST_KW), 257 "const" => Some(CONST_KW),
254 "static" => Some(STATIC_KW), 258 "static" => Some(STATIC_KW),
255 "mut" => Some(MUT_KW), 259 "mut" => Some(MUT_KW),
260 "unsafe" => Some(UNSAFE_KW),
256 _ => None, 261 _ => None,
257 } 262 }
258} 263}