diff options
author | Aleksey Kladov <[email protected]> | 2018-01-09 20:32:18 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-01-09 20:32:18 +0000 |
commit | 5ea7e5fb7ab9f9ed762c8b5220ba01a29796a871 (patch) | |
tree | e67b91e3fe1d046d886bce5e896bb045e327169e /src | |
parent | 1544e89c49c67df00fc72d841f3e39be792cbe2b (diff) |
G: simplest use items
Diffstat (limited to 'src')
-rw-r--r-- | src/parser/event_parser/grammar/items.rs | 8 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/mod.rs | 9 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/paths.rs | 15 | ||||
-rw-r--r-- | src/syntax_kinds.rs | 12 |
4 files changed, 33 insertions, 11 deletions
diff --git a/src/parser/event_parser/grammar/items.rs b/src/parser/event_parser/grammar/items.rs index e775db14b..950e02a4d 100644 --- a/src/parser/event_parser/grammar/items.rs +++ b/src/parser/event_parser/grammar/items.rs | |||
@@ -12,7 +12,7 @@ pub(super) fn mod_contents(p: &mut Parser) { | |||
12 | 12 | ||
13 | fn item_first(p: &Parser) -> bool { | 13 | fn item_first(p: &Parser) -> bool { |
14 | match p.current() { | 14 | match p.current() { |
15 | STRUCT_KW | FN_KW | EXTERN_KW | MOD_KW => true, | 15 | STRUCT_KW | FN_KW | EXTERN_KW | MOD_KW | USE_KW => true, |
16 | _ => false, | 16 | _ => false, |
17 | } | 17 | } |
18 | } | 18 | } |
@@ -43,6 +43,7 @@ fn item(p: &mut Parser) -> bool { | |||
43 | // || node_if(p, TYPE_KW, TYPE_ITEM, type_item) | 43 | // || node_if(p, TYPE_KW, TYPE_ITEM, type_item) |
44 | node_if(p, [EXTERN_KW, CRATE_KW], EXTERN_CRATE_ITEM, extern_crate_item) | 44 | node_if(p, [EXTERN_KW, CRATE_KW], EXTERN_CRATE_ITEM, extern_crate_item) |
45 | || node_if(p, MOD_KW, MOD_ITEM, mod_item) | 45 | || node_if(p, MOD_KW, MOD_ITEM, mod_item) |
46 | || node_if(p, USE_KW, USE_ITEM, use_item) | ||
46 | || node_if(p, STRUCT_KW, STRUCT_ITEM, struct_item) | 47 | || node_if(p, STRUCT_KW, STRUCT_ITEM, struct_item) |
47 | || node_if(p, FN_KW, FN_ITEM, fn_item) | 48 | || node_if(p, FN_KW, FN_ITEM, fn_item) |
48 | } | 49 | } |
@@ -66,6 +67,11 @@ fn mod_item(p: &mut Parser) { | |||
66 | p.curly_block(mod_contents); | 67 | p.curly_block(mod_contents); |
67 | } | 68 | } |
68 | 69 | ||
70 | fn use_item(p: &mut Parser) { | ||
71 | paths::use_path(p); | ||
72 | p.expect(SEMI); | ||
73 | } | ||
74 | |||
69 | fn struct_field(p: &mut Parser) -> bool { | 75 | fn struct_field(p: &mut Parser) -> bool { |
70 | node_if(p, IDENT, STRUCT_FIELD, |p| { | 76 | node_if(p, IDENT, STRUCT_FIELD, |p| { |
71 | p.expect(COLON) && p.expect(IDENT); | 77 | p.expect(COLON) && p.expect(IDENT); |
diff --git a/src/parser/event_parser/grammar/mod.rs b/src/parser/event_parser/grammar/mod.rs index 6d1cd7ec3..60458ce70 100644 --- a/src/parser/event_parser/grammar/mod.rs +++ b/src/parser/event_parser/grammar/mod.rs | |||
@@ -6,10 +6,11 @@ use syntax_kinds::*; | |||
6 | mod items; | 6 | mod items; |
7 | mod attributes; | 7 | mod attributes; |
8 | mod expressions; | 8 | mod expressions; |
9 | mod paths; | ||
9 | 10 | ||
10 | pub(crate) fn file(p: &mut Parser) { | 11 | pub(crate) fn file(p: &mut Parser) { |
11 | node(p, FILE, |p| { | 12 | node(p, FILE, |p| { |
12 | p.optional(SHEBANG); | 13 | p.eat(SHEBANG); |
13 | items::mod_contents(p); | 14 | items::mod_contents(p); |
14 | }) | 15 | }) |
15 | } | 16 | } |
@@ -99,12 +100,6 @@ impl<'p> Parser<'p> { | |||
99 | } | 100 | } |
100 | } | 101 | } |
101 | 102 | ||
102 | fn optional(&mut self, kind: SyntaxKind) { | ||
103 | if self.current() == kind { | ||
104 | self.bump(); | ||
105 | } | ||
106 | } | ||
107 | |||
108 | fn eat(&mut self, kind: SyntaxKind) -> bool { | 103 | fn eat(&mut self, kind: SyntaxKind) -> bool { |
109 | self.current() == kind && { self.bump(); true } | 104 | self.current() == kind && { self.bump(); true } |
110 | } | 105 | } |
diff --git a/src/parser/event_parser/grammar/paths.rs b/src/parser/event_parser/grammar/paths.rs new file mode 100644 index 000000000..96966b380 --- /dev/null +++ b/src/parser/event_parser/grammar/paths.rs | |||
@@ -0,0 +1,15 @@ | |||
1 | use super::*; | ||
2 | |||
3 | pub(crate) fn use_path(p: &mut Parser) { | ||
4 | if !AnyOf(&[IDENT, COLONCOLON]).is_ahead(p) { | ||
5 | return; | ||
6 | } | ||
7 | node(p, PATH, |p| { | ||
8 | p.eat(COLONCOLON); | ||
9 | path_segment(p); | ||
10 | }) | ||
11 | } | ||
12 | |||
13 | fn path_segment(p: &mut Parser) -> bool { | ||
14 | node_if(p, IDENT, PATH_SEGMENT, |p| ()) | ||
15 | } \ No newline at end of file | ||
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index 26838d2d8..a86f203d7 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs | |||
@@ -72,10 +72,13 @@ pub const EXTERN_CRATE_ITEM: SyntaxKind = SyntaxKind(67); | |||
72 | pub const ATTR: SyntaxKind = SyntaxKind(68); | 72 | pub const ATTR: SyntaxKind = SyntaxKind(68); |
73 | pub const META_ITEM: SyntaxKind = SyntaxKind(69); | 73 | pub const META_ITEM: SyntaxKind = SyntaxKind(69); |
74 | pub const MOD_ITEM: SyntaxKind = SyntaxKind(70); | 74 | pub const MOD_ITEM: SyntaxKind = SyntaxKind(70); |
75 | pub const LITERAL: SyntaxKind = SyntaxKind(71); | 75 | pub const USE_ITEM: SyntaxKind = SyntaxKind(71); |
76 | pub const ALIAS: SyntaxKind = SyntaxKind(72); | 76 | pub const PATH: SyntaxKind = SyntaxKind(72); |
77 | pub const PATH_SEGMENT: SyntaxKind = SyntaxKind(73); | ||
78 | pub const LITERAL: SyntaxKind = SyntaxKind(74); | ||
79 | pub const ALIAS: SyntaxKind = SyntaxKind(75); | ||
77 | 80 | ||
78 | static INFOS: [SyntaxInfo; 73] = [ | 81 | static INFOS: [SyntaxInfo; 76] = [ |
79 | SyntaxInfo { name: "USE_KW" }, | 82 | SyntaxInfo { name: "USE_KW" }, |
80 | SyntaxInfo { name: "FN_KW" }, | 83 | SyntaxInfo { name: "FN_KW" }, |
81 | SyntaxInfo { name: "STRUCT_KW" }, | 84 | SyntaxInfo { name: "STRUCT_KW" }, |
@@ -147,6 +150,9 @@ static INFOS: [SyntaxInfo; 73] = [ | |||
147 | SyntaxInfo { name: "ATTR" }, | 150 | SyntaxInfo { name: "ATTR" }, |
148 | SyntaxInfo { name: "META_ITEM" }, | 151 | SyntaxInfo { name: "META_ITEM" }, |
149 | SyntaxInfo { name: "MOD_ITEM" }, | 152 | SyntaxInfo { name: "MOD_ITEM" }, |
153 | SyntaxInfo { name: "USE_ITEM" }, | ||
154 | SyntaxInfo { name: "PATH" }, | ||
155 | SyntaxInfo { name: "PATH_SEGMENT" }, | ||
150 | SyntaxInfo { name: "LITERAL" }, | 156 | SyntaxInfo { name: "LITERAL" }, |
151 | SyntaxInfo { name: "ALIAS" }, | 157 | SyntaxInfo { name: "ALIAS" }, |
152 | ]; | 158 | ]; |