aboutsummaryrefslogtreecommitdiff
path: root/src/parser
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-02-03 09:05:25 +0000
committerAleksey Kladov <[email protected]>2018-02-03 09:05:57 +0000
commite5273d33d05196ca215db4b1c4e207328fa5df08 (patch)
treec7dc8cc7c4d8bfd21e64c5a946a23b2d00ca697e /src/parser
parent5e7504b978c9b1365e0381691ef453e97603defa (diff)
G: const item
Diffstat (limited to 'src/parser')
-rw-r--r--src/parser/event_parser/grammar/items/consts.rs21
-rw-r--r--src/parser/event_parser/grammar/items/mod.rs33
2 files changed, 40 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();