diff options
author | Aleksey Kladov <[email protected]> | 2019-09-02 15:37:48 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-09-02 15:37:48 +0100 |
commit | 32bebfaf0e24651316c4d70d1e23ef170224bd7c (patch) | |
tree | db9afdd2881a2585b34c885723a406905903d6cf /crates | |
parent | f39f72db57a78b7f92f99377be0e05ec3db6dc98 (diff) |
cleanup
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_parser/src/grammar.rs | 146 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/paths.rs | 2 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/patterns.rs | 2 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/types.rs | 2 | ||||
-rw-r--r-- | crates/ra_parser/src/lib.rs | 24 |
5 files changed, 86 insertions, 90 deletions
diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs index dee3a229d..2bcbb4184 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs | |||
@@ -49,98 +49,96 @@ pub(crate) fn root(p: &mut Parser) { | |||
49 | m.complete(p, SOURCE_FILE); | 49 | m.complete(p, SOURCE_FILE); |
50 | } | 50 | } |
51 | 51 | ||
52 | pub(crate) fn macro_items(p: &mut Parser) { | 52 | /// Various pieces of syntax that can be parsed by macros by example |
53 | let m = p.start(); | 53 | pub(crate) mod fragments { |
54 | items::mod_contents(p, false); | 54 | use super::*; |
55 | m.complete(p, MACRO_ITEMS); | ||
56 | } | ||
57 | 55 | ||
58 | pub(crate) fn macro_stmts(p: &mut Parser) { | 56 | pub(crate) use super::{ |
59 | let m = p.start(); | 57 | expressions::block, paths::type_path as path, patterns::pattern, types::type_, |
60 | 58 | }; | |
61 | while !p.at(EOF) { | ||
62 | if p.current() == T![;] { | ||
63 | p.bump(); | ||
64 | continue; | ||
65 | } | ||
66 | 59 | ||
67 | expressions::stmt(p, expressions::StmtWithSemi::Optional); | 60 | pub(crate) fn expr(p: &mut Parser) { |
61 | let _ = expressions::expr(p); | ||
68 | } | 62 | } |
69 | 63 | ||
70 | m.complete(p, MACRO_STMTS); | 64 | pub(crate) fn stmt(p: &mut Parser, with_semi: bool) { |
71 | } | 65 | let with_semi = |
72 | 66 | if with_semi { expressions::StmtWithSemi::Yes } else { expressions::StmtWithSemi::No }; | |
73 | pub(crate) fn path(p: &mut Parser) { | ||
74 | paths::type_path(p); | ||
75 | } | ||
76 | 67 | ||
77 | pub(crate) fn expr(p: &mut Parser) { | 68 | expressions::stmt(p, with_semi) |
78 | expressions::expr(p); | 69 | } |
79 | } | ||
80 | 70 | ||
81 | pub(crate) fn type_(p: &mut Parser) { | 71 | pub(crate) fn opt_visibility(p: &mut Parser) { |
82 | types::type_(p) | 72 | let _ = super::opt_visibility(p); |
83 | } | 73 | } |
84 | 74 | ||
85 | pub(crate) fn pattern(p: &mut Parser) { | 75 | // Parse a meta item , which excluded [], e.g : #[ MetaItem ] |
86 | patterns::pattern(p) | 76 | pub(crate) fn meta_item(p: &mut Parser) { |
87 | } | 77 | fn is_delimiter(p: &mut Parser) -> bool { |
78 | match p.current() { | ||
79 | T!['{'] | T!['('] | T!['['] => true, | ||
80 | _ => false, | ||
81 | } | ||
82 | } | ||
88 | 83 | ||
89 | pub(crate) fn stmt(p: &mut Parser, with_semi: bool) { | 84 | if is_delimiter(p) { |
90 | let with_semi = | 85 | items::token_tree(p); |
91 | if with_semi { expressions::StmtWithSemi::Yes } else { expressions::StmtWithSemi::No }; | 86 | return; |
87 | } | ||
92 | 88 | ||
93 | expressions::stmt(p, with_semi) | 89 | let m = p.start(); |
94 | } | 90 | while !p.at(EOF) { |
91 | if is_delimiter(p) { | ||
92 | items::token_tree(p); | ||
93 | break; | ||
94 | } else { | ||
95 | // https://doc.rust-lang.org/reference/attributes.html | ||
96 | // https://doc.rust-lang.org/reference/paths.html#simple-paths | ||
97 | // The start of an meta must be a simple path | ||
98 | match p.current() { | ||
99 | IDENT | T![::] | T![super] | T![self] | T![crate] => p.bump(), | ||
100 | T![=] => { | ||
101 | p.bump(); | ||
102 | match p.current() { | ||
103 | c if c.is_literal() => p.bump(), | ||
104 | T![true] | T![false] => p.bump(), | ||
105 | _ => {} | ||
106 | } | ||
107 | break; | ||
108 | } | ||
109 | _ => break, | ||
110 | } | ||
111 | } | ||
112 | } | ||
95 | 113 | ||
96 | pub(crate) fn block(p: &mut Parser) { | 114 | m.complete(p, TOKEN_TREE); |
97 | expressions::block(p); | 115 | } |
98 | } | ||
99 | 116 | ||
100 | // Parse a meta item , which excluded [], e.g : #[ MetaItem ] | 117 | pub(crate) fn item(p: &mut Parser) { |
101 | pub(crate) fn meta_item(p: &mut Parser) { | 118 | items::item_or_macro(p, true, items::ItemFlavor::Mod) |
102 | fn is_delimiter(p: &mut Parser) -> bool { | ||
103 | match p.current() { | ||
104 | T!['{'] | T!['('] | T!['['] => true, | ||
105 | _ => false, | ||
106 | } | ||
107 | } | 119 | } |
108 | 120 | ||
109 | if is_delimiter(p) { | 121 | pub(crate) fn macro_items(p: &mut Parser) { |
110 | items::token_tree(p); | 122 | let m = p.start(); |
111 | return; | 123 | items::mod_contents(p, false); |
124 | m.complete(p, MACRO_ITEMS); | ||
112 | } | 125 | } |
113 | 126 | ||
114 | let m = p.start(); | 127 | pub(crate) fn macro_stmts(p: &mut Parser) { |
115 | while !p.at(EOF) { | 128 | let m = p.start(); |
116 | if is_delimiter(p) { | 129 | |
117 | items::token_tree(p); | 130 | while !p.at(EOF) { |
118 | break; | 131 | if p.current() == T![;] { |
119 | } else { | 132 | p.bump(); |
120 | // https://doc.rust-lang.org/reference/attributes.html | 133 | continue; |
121 | // https://doc.rust-lang.org/reference/paths.html#simple-paths | ||
122 | // The start of an meta must be a simple path | ||
123 | match p.current() { | ||
124 | IDENT | T![::] | T![super] | T![self] | T![crate] => p.bump(), | ||
125 | T![=] => { | ||
126 | p.bump(); | ||
127 | match p.current() { | ||
128 | c if c.is_literal() => p.bump(), | ||
129 | T![true] | T![false] => p.bump(), | ||
130 | _ => {} | ||
131 | } | ||
132 | break; | ||
133 | } | ||
134 | _ => break, | ||
135 | } | 134 | } |
135 | |||
136 | expressions::stmt(p, expressions::StmtWithSemi::Optional); | ||
136 | } | 137 | } |
137 | } | ||
138 | 138 | ||
139 | m.complete(p, TOKEN_TREE); | 139 | m.complete(p, MACRO_STMTS); |
140 | } | 140 | } |
141 | 141 | ||
142 | pub(crate) fn item(p: &mut Parser) { | ||
143 | items::item_or_macro(p, true, items::ItemFlavor::Mod) | ||
144 | } | 142 | } |
145 | 143 | ||
146 | pub(crate) fn reparser( | 144 | pub(crate) fn reparser( |
@@ -180,7 +178,7 @@ impl BlockLike { | |||
180 | } | 178 | } |
181 | } | 179 | } |
182 | 180 | ||
183 | pub(crate) fn opt_visibility(p: &mut Parser) -> bool { | 181 | fn opt_visibility(p: &mut Parser) -> bool { |
184 | match p.current() { | 182 | match p.current() { |
185 | T![pub] => { | 183 | T![pub] => { |
186 | let m = p.start(); | 184 | let m = p.start(); |
diff --git a/crates/ra_parser/src/grammar/paths.rs b/crates/ra_parser/src/grammar/paths.rs index 07eb53b0c..28c35a67d 100644 --- a/crates/ra_parser/src/grammar/paths.rs +++ b/crates/ra_parser/src/grammar/paths.rs | |||
@@ -18,7 +18,7 @@ pub(super) fn use_path(p: &mut Parser) { | |||
18 | path(p, Mode::Use) | 18 | path(p, Mode::Use) |
19 | } | 19 | } |
20 | 20 | ||
21 | pub(super) fn type_path(p: &mut Parser) { | 21 | pub(crate) fn type_path(p: &mut Parser) { |
22 | path(p, Mode::Type) | 22 | path(p, Mode::Type) |
23 | } | 23 | } |
24 | 24 | ||
diff --git a/crates/ra_parser/src/grammar/patterns.rs b/crates/ra_parser/src/grammar/patterns.rs index eae70ab85..32cde7de6 100644 --- a/crates/ra_parser/src/grammar/patterns.rs +++ b/crates/ra_parser/src/grammar/patterns.rs | |||
@@ -4,7 +4,7 @@ pub(super) const PATTERN_FIRST: TokenSet = expressions::LITERAL_FIRST | |||
4 | .union(paths::PATH_FIRST) | 4 | .union(paths::PATH_FIRST) |
5 | .union(token_set![BOX_KW, REF_KW, MUT_KW, L_PAREN, L_BRACK, AMP, UNDERSCORE, MINUS]); | 5 | .union(token_set![BOX_KW, REF_KW, MUT_KW, L_PAREN, L_BRACK, AMP, UNDERSCORE, MINUS]); |
6 | 6 | ||
7 | pub(super) fn pattern(p: &mut Parser) { | 7 | pub(crate) fn pattern(p: &mut Parser) { |
8 | pattern_r(p, PAT_RECOVERY_SET); | 8 | pattern_r(p, PAT_RECOVERY_SET); |
9 | } | 9 | } |
10 | 10 | ||
diff --git a/crates/ra_parser/src/grammar/types.rs b/crates/ra_parser/src/grammar/types.rs index 29d173305..9e321b2a6 100644 --- a/crates/ra_parser/src/grammar/types.rs +++ b/crates/ra_parser/src/grammar/types.rs | |||
@@ -7,7 +7,7 @@ pub(super) const TYPE_FIRST: TokenSet = paths::PATH_FIRST.union(token_set![ | |||
7 | 7 | ||
8 | const TYPE_RECOVERY_SET: TokenSet = token_set![R_PAREN, COMMA]; | 8 | const TYPE_RECOVERY_SET: TokenSet = token_set![R_PAREN, COMMA]; |
9 | 9 | ||
10 | pub(super) fn type_(p: &mut Parser) { | 10 | pub(crate) fn type_(p: &mut Parser) { |
11 | type_with_bounds_cond(p, true); | 11 | type_with_bounds_cond(p, true); |
12 | } | 12 | } |
13 | 13 | ||
diff --git a/crates/ra_parser/src/lib.rs b/crates/ra_parser/src/lib.rs index 3d88be642..e494fc480 100644 --- a/crates/ra_parser/src/lib.rs +++ b/crates/ra_parser/src/lib.rs | |||
@@ -85,22 +85,22 @@ pub fn parse(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | |||
85 | 85 | ||
86 | /// Parse given tokens into the given sink as a path | 86 | /// Parse given tokens into the given sink as a path |
87 | pub fn parse_path(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | 87 | pub fn parse_path(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { |
88 | parse_from_tokens(token_source, tree_sink, grammar::path); | 88 | parse_from_tokens(token_source, tree_sink, grammar::fragments::path); |
89 | } | 89 | } |
90 | 90 | ||
91 | /// Parse given tokens into the given sink as a expression | 91 | /// Parse given tokens into the given sink as a expression |
92 | pub fn parse_expr(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | 92 | pub fn parse_expr(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { |
93 | parse_from_tokens(token_source, tree_sink, grammar::expr); | 93 | parse_from_tokens(token_source, tree_sink, grammar::fragments::expr); |
94 | } | 94 | } |
95 | 95 | ||
96 | /// Parse given tokens into the given sink as a ty | 96 | /// Parse given tokens into the given sink as a ty |
97 | pub fn parse_ty(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | 97 | pub fn parse_ty(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { |
98 | parse_from_tokens(token_source, tree_sink, grammar::type_); | 98 | parse_from_tokens(token_source, tree_sink, grammar::fragments::type_); |
99 | } | 99 | } |
100 | 100 | ||
101 | /// Parse given tokens into the given sink as a pattern | 101 | /// Parse given tokens into the given sink as a pattern |
102 | pub fn parse_pat(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | 102 | pub fn parse_pat(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { |
103 | parse_from_tokens(token_source, tree_sink, grammar::pattern); | 103 | parse_from_tokens(token_source, tree_sink, grammar::fragments::pattern); |
104 | } | 104 | } |
105 | 105 | ||
106 | /// Parse given tokens into the given sink as a statement | 106 | /// Parse given tokens into the given sink as a statement |
@@ -109,36 +109,34 @@ pub fn parse_stmt( | |||
109 | tree_sink: &mut dyn TreeSink, | 109 | tree_sink: &mut dyn TreeSink, |
110 | with_semi: bool, | 110 | with_semi: bool, |
111 | ) { | 111 | ) { |
112 | parse_from_tokens(token_source, tree_sink, |p| grammar::stmt(p, with_semi)); | 112 | parse_from_tokens(token_source, tree_sink, |p| grammar::fragments::stmt(p, with_semi)); |
113 | } | 113 | } |
114 | 114 | ||
115 | /// Parse given tokens into the given sink as a block | 115 | /// Parse given tokens into the given sink as a block |
116 | pub fn parse_block(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | 116 | pub fn parse_block(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { |
117 | parse_from_tokens(token_source, tree_sink, grammar::block); | 117 | parse_from_tokens(token_source, tree_sink, grammar::fragments::block); |
118 | } | 118 | } |
119 | 119 | ||
120 | pub fn parse_meta(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | 120 | pub fn parse_meta(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { |
121 | parse_from_tokens(token_source, tree_sink, grammar::meta_item); | 121 | parse_from_tokens(token_source, tree_sink, grammar::fragments::meta_item); |
122 | } | 122 | } |
123 | 123 | ||
124 | /// Parse given tokens into the given sink as an item | 124 | /// Parse given tokens into the given sink as an item |
125 | pub fn parse_item(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | 125 | pub fn parse_item(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { |
126 | parse_from_tokens(token_source, tree_sink, grammar::item); | 126 | parse_from_tokens(token_source, tree_sink, grammar::fragments::item); |
127 | } | 127 | } |
128 | 128 | ||
129 | /// Parse given tokens into the given sink as an visibility qualifier | 129 | /// Parse given tokens into the given sink as an visibility qualifier |
130 | pub fn parse_vis(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | 130 | pub fn parse_vis(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { |
131 | parse_from_tokens(token_source, tree_sink, |p| { | 131 | parse_from_tokens(token_source, tree_sink, grammar::fragments::opt_visibility); |
132 | grammar::opt_visibility(p); | ||
133 | }); | ||
134 | } | 132 | } |
135 | 133 | ||
136 | pub fn parse_macro_items(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | 134 | pub fn parse_macro_items(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { |
137 | parse_from_tokens(token_source, tree_sink, grammar::macro_items); | 135 | parse_from_tokens(token_source, tree_sink, grammar::fragments::macro_items); |
138 | } | 136 | } |
139 | 137 | ||
140 | pub fn parse_macro_stmts(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { | 138 | pub fn parse_macro_stmts(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) { |
141 | parse_from_tokens(token_source, tree_sink, grammar::macro_stmts); | 139 | parse_from_tokens(token_source, tree_sink, grammar::fragments::macro_stmts); |
142 | } | 140 | } |
143 | 141 | ||
144 | /// A parsing function for a specific braced-block. | 142 | /// A parsing function for a specific braced-block. |