diff options
-rw-r--r-- | grammar.ron | 2 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/items/mod.rs | 28 | ||||
-rw-r--r-- | src/syntax_kinds.rs | 5 | ||||
-rw-r--r-- | tests/data/lexer/0011_keywords.rs | 3 | ||||
-rw-r--r-- | tests/data/lexer/0011_keywords.txt | 4 | ||||
-rw-r--r-- | tests/data/parser/ok/0023_static_items.rs | 2 | ||||
-rw-r--r-- | tests/data/parser/ok/0023_static_items.txt | 31 |
7 files changed, 67 insertions, 8 deletions
diff --git a/grammar.ron b/grammar.ron index e7acd3cb0..53248519f 100644 --- a/grammar.ron +++ b/grammar.ron | |||
@@ -24,6 +24,7 @@ Grammar( | |||
24 | "match", | 24 | "match", |
25 | "const", | 25 | "const", |
26 | "static", | 26 | "static", |
27 | "mut", | ||
27 | ], | 28 | ], |
28 | tokens: [ | 29 | tokens: [ |
29 | "ERROR", | 30 | "ERROR", |
@@ -87,6 +88,7 @@ Grammar( | |||
87 | "EXTERN_CRATE_ITEM", | 88 | "EXTERN_CRATE_ITEM", |
88 | "MOD_ITEM", | 89 | "MOD_ITEM", |
89 | "USE_ITEM", | 90 | "USE_ITEM", |
91 | "STATIC_ITEM", | ||
90 | 92 | ||
91 | "EXTERN_BLOCK", | 93 | "EXTERN_BLOCK", |
92 | "ENUM_VARIANT", | 94 | "ENUM_VARIANT", |
diff --git a/src/parser/event_parser/grammar/items/mod.rs b/src/parser/event_parser/grammar/items/mod.rs index 35825e7c4..9930de347 100644 --- a/src/parser/event_parser/grammar/items/mod.rs +++ b/src/parser/event_parser/grammar/items/mod.rs | |||
@@ -46,6 +46,10 @@ fn item(p: &mut Parser) { | |||
46 | } | 46 | } |
47 | } | 47 | } |
48 | } | 48 | } |
49 | STATIC_KW => { | ||
50 | static_item(p); | ||
51 | STATIC_ITEM | ||
52 | } | ||
49 | MOD_KW => { | 53 | MOD_KW => { |
50 | mod_item(p); | 54 | mod_item(p); |
51 | MOD_ITEM | 55 | MOD_ITEM |
@@ -92,6 +96,24 @@ fn extern_crate_item(p: &mut Parser) { | |||
92 | p.expect(IDENT) && alias(p) && p.expect(SEMI); | 96 | p.expect(IDENT) && alias(p) && p.expect(SEMI); |
93 | } | 97 | } |
94 | 98 | ||
99 | fn extern_block(p: &mut Parser) { | ||
100 | assert!(p.at(L_CURLY)); | ||
101 | p.bump(); | ||
102 | p.expect(R_CURLY); | ||
103 | } | ||
104 | |||
105 | fn 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 | |||
95 | fn mod_item(p: &mut Parser) { | 117 | fn mod_item(p: &mut Parser) { |
96 | assert!(p.at(MOD_KW)); | 118 | assert!(p.at(MOD_KW)); |
97 | p.bump(); | 119 | p.bump(); |
@@ -104,12 +126,6 @@ fn mod_item(p: &mut Parser) { | |||
104 | } | 126 | } |
105 | } | 127 | } |
106 | 128 | ||
107 | fn extern_block(p: &mut Parser) { | ||
108 | assert!(p.at(L_CURLY)); | ||
109 | p.bump(); | ||
110 | p.expect(R_CURLY); | ||
111 | } | ||
112 | |||
113 | fn abi(p: &mut Parser) { | 129 | fn abi(p: &mut Parser) { |
114 | assert!(p.at(EXTERN_KW)); | 130 | assert!(p.at(EXTERN_KW)); |
115 | let abi = p.start(); | 131 | let abi = p.start(); |
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index f5d01c6f3..8d21d3fb7 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs | |||
@@ -30,6 +30,7 @@ pub enum SyntaxKind { | |||
30 | MATCH_KW, | 30 | MATCH_KW, |
31 | CONST_KW, | 31 | CONST_KW, |
32 | STATIC_KW, | 32 | STATIC_KW, |
33 | MUT_KW, | ||
33 | ERROR, | 34 | ERROR, |
34 | IDENT, | 35 | IDENT, |
35 | UNDERSCORE, | 36 | UNDERSCORE, |
@@ -88,6 +89,7 @@ pub enum SyntaxKind { | |||
88 | EXTERN_CRATE_ITEM, | 89 | EXTERN_CRATE_ITEM, |
89 | MOD_ITEM, | 90 | MOD_ITEM, |
90 | USE_ITEM, | 91 | USE_ITEM, |
92 | STATIC_ITEM, | ||
91 | EXTERN_BLOCK, | 93 | EXTERN_BLOCK, |
92 | ENUM_VARIANT, | 94 | ENUM_VARIANT, |
93 | NAMED_FIELD, | 95 | NAMED_FIELD, |
@@ -141,6 +143,7 @@ impl SyntaxKind { | |||
141 | MATCH_KW => &SyntaxInfo { name: "MATCH_KW" }, | 143 | MATCH_KW => &SyntaxInfo { name: "MATCH_KW" }, |
142 | CONST_KW => &SyntaxInfo { name: "CONST_KW" }, | 144 | CONST_KW => &SyntaxInfo { name: "CONST_KW" }, |
143 | STATIC_KW => &SyntaxInfo { name: "STATIC_KW" }, | 145 | STATIC_KW => &SyntaxInfo { name: "STATIC_KW" }, |
146 | MUT_KW => &SyntaxInfo { name: "MUT_KW" }, | ||
144 | ERROR => &SyntaxInfo { name: "ERROR" }, | 147 | ERROR => &SyntaxInfo { name: "ERROR" }, |
145 | IDENT => &SyntaxInfo { name: "IDENT" }, | 148 | IDENT => &SyntaxInfo { name: "IDENT" }, |
146 | UNDERSCORE => &SyntaxInfo { name: "UNDERSCORE" }, | 149 | UNDERSCORE => &SyntaxInfo { name: "UNDERSCORE" }, |
@@ -199,6 +202,7 @@ impl SyntaxKind { | |||
199 | EXTERN_CRATE_ITEM => &SyntaxInfo { name: "EXTERN_CRATE_ITEM" }, | 202 | EXTERN_CRATE_ITEM => &SyntaxInfo { name: "EXTERN_CRATE_ITEM" }, |
200 | MOD_ITEM => &SyntaxInfo { name: "MOD_ITEM" }, | 203 | MOD_ITEM => &SyntaxInfo { name: "MOD_ITEM" }, |
201 | USE_ITEM => &SyntaxInfo { name: "USE_ITEM" }, | 204 | USE_ITEM => &SyntaxInfo { name: "USE_ITEM" }, |
205 | STATIC_ITEM => &SyntaxInfo { name: "STATIC_ITEM" }, | ||
202 | EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, | 206 | EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, |
203 | ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, | 207 | ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, |
204 | NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, | 208 | NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, |
@@ -248,6 +252,7 @@ pub(crate) fn ident_to_keyword(ident: &str) -> Option<SyntaxKind> { | |||
248 | "match" => Some(MATCH_KW), | 252 | "match" => Some(MATCH_KW), |
249 | "const" => Some(CONST_KW), | 253 | "const" => Some(CONST_KW), |
250 | "static" => Some(STATIC_KW), | 254 | "static" => Some(STATIC_KW), |
255 | "mut" => Some(MUT_KW), | ||
251 | _ => None, | 256 | _ => None, |
252 | } | 257 | } |
253 | } | 258 | } |
diff --git a/tests/data/lexer/0011_keywords.rs b/tests/data/lexer/0011_keywords.rs index 7a1000bb7..b74fc606e 100644 --- a/tests/data/lexer/0011_keywords.rs +++ b/tests/data/lexer/0011_keywords.rs | |||
@@ -1,2 +1,3 @@ | |||
1 | fn use struct trait enum impl true false as extern crate | 1 | fn use struct trait enum impl true false as extern crate |
2 | mod pub self super in where for loop while if match const static | 2 | mod pub self super in where for loop while if match const |
3 | static mut | ||
diff --git a/tests/data/lexer/0011_keywords.txt b/tests/data/lexer/0011_keywords.txt index b38b4bd64..05b1f0995 100644 --- a/tests/data/lexer/0011_keywords.txt +++ b/tests/data/lexer/0011_keywords.txt | |||
@@ -43,6 +43,8 @@ WHITESPACE 1 " " | |||
43 | MATCH_KW 5 "match" | 43 | MATCH_KW 5 "match" |
44 | WHITESPACE 1 " " | 44 | WHITESPACE 1 " " |
45 | CONST_KW 5 "const" | 45 | CONST_KW 5 "const" |
46 | WHITESPACE 1 " " | 46 | WHITESPACE 1 "\n" |
47 | STATIC_KW 6 "static" | 47 | STATIC_KW 6 "static" |
48 | WHITESPACE 1 " " | ||
49 | MUT_KW 3 "mut" | ||
48 | WHITESPACE 1 "\n" | 50 | WHITESPACE 1 "\n" |
diff --git a/tests/data/parser/ok/0023_static_items.rs b/tests/data/parser/ok/0023_static_items.rs new file mode 100644 index 000000000..5fb92ce33 --- /dev/null +++ b/tests/data/parser/ok/0023_static_items.rs | |||
@@ -0,0 +1,2 @@ | |||
1 | static FOO: u32 = 1; | ||
2 | static mut BAR: i32 = 92; | ||
diff --git a/tests/data/parser/ok/0023_static_items.txt b/tests/data/parser/ok/0023_static_items.txt new file mode 100644 index 000000000..7cd2228fa --- /dev/null +++ b/tests/data/parser/ok/0023_static_items.txt | |||
@@ -0,0 +1,31 @@ | |||
1 | FILE@[0; 47) | ||
2 | STATIC_ITEM@[0; 21) | ||
3 | STATIC_KW@[0; 6) | ||
4 | WHITESPACE@[6; 7) | ||
5 | IDENT@[7; 10) "FOO" | ||
6 | COLON@[10; 11) | ||
7 | WHITESPACE@[11; 12) | ||
8 | IDENT@[12; 15) "u32" | ||
9 | WHITESPACE@[15; 16) | ||
10 | EQ@[16; 17) | ||
11 | LITERAL@[17; 19) | ||
12 | WHITESPACE@[17; 18) | ||
13 | INT_NUMBER@[18; 19) | ||
14 | SEMI@[19; 20) | ||
15 | WHITESPACE@[20; 21) | ||
16 | STATIC_ITEM@[21; 47) | ||
17 | STATIC_KW@[21; 27) | ||
18 | WHITESPACE@[27; 28) | ||
19 | MUT_KW@[28; 31) | ||
20 | WHITESPACE@[31; 32) | ||
21 | IDENT@[32; 35) "BAR" | ||
22 | COLON@[35; 36) | ||
23 | WHITESPACE@[36; 37) | ||
24 | IDENT@[37; 40) "i32" | ||
25 | WHITESPACE@[40; 41) | ||
26 | EQ@[41; 42) | ||
27 | LITERAL@[42; 45) | ||
28 | WHITESPACE@[42; 43) | ||
29 | INT_NUMBER@[43; 45) | ||
30 | SEMI@[45; 46) | ||
31 | WHITESPACE@[46; 47) | ||