aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/parsing
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-04-28 17:51:02 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-04-28 17:51:02 +0100
commit6618d1edc3edaad9ebdc216e6d7423ac9ac6a265 (patch)
tree6134e50e3b501e810c6da140257d7ccdca90602a /crates/ra_syntax/src/parsing
parent8138b1da4f1564913a1a22407c65e77aa5320d56 (diff)
parentd436ab05810c208b41a1b61896d3d87691cd9e99 (diff)
Merge #1213
1213: Make lexer produce only single character puncts r=matklad a=edwin0cheng As discussed in Zulip, this PR change `lexer` to produce only single char punct. * Remove producing `DOTDOTDOT, DOTDOTEQ, DOTDOT, COLONCOLON, EQEQ, FAT_ARROW, NEQ, THIN_ARROW` in lexer. * Add required code in parser to make sure everythings works fine. * Change some tests (Mainly because the `ast::token_tree` is different) Note: i think the use of `COLON` in rust is too overloaded :) Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/parsing')
-rw-r--r--crates/ra_syntax/src/parsing/lexer.rs71
1 files changed, 12 insertions, 59 deletions
diff --git a/crates/ra_syntax/src/parsing/lexer.rs b/crates/ra_syntax/src/parsing/lexer.rs
index 3ae42912c..a3791b503 100644
--- a/crates/ra_syntax/src/parsing/lexer.rs
+++ b/crates/ra_syntax/src/parsing/lexer.rs
@@ -88,65 +88,18 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind {
88 } 88 }
89 89
90 match c { 90 match c {
91 // Multi-byte tokens. 91 // Possiblily multi-byte tokens,
92 '.' => { 92 // but we only produce single byte token now
93 return match (ptr.current(), ptr.nth(1)) { 93 // DOTDOTDOT, DOTDOT, DOTDOTEQ, DOT
94 (Some('.'), Some('.')) => { 94 '.' => return DOT,
95 ptr.bump(); 95 // COLONCOLON COLON
96 ptr.bump(); 96 ':' => return COLON,
97 DOTDOTDOT 97 // EQEQ FATARROW EQ
98 } 98 '=' => return EQ,
99 (Some('.'), Some('=')) => { 99 // NEQ EXCL
100 ptr.bump(); 100 '!' => return EXCL,
101 ptr.bump(); 101 // THIN_ARROW MINUS
102 DOTDOTEQ 102 '-' => return MINUS,
103 }
104 (Some('.'), _) => {
105 ptr.bump();
106 DOTDOT
107 }
108 _ => DOT,
109 };
110 }
111 ':' => {
112 return match ptr.current() {
113 Some(':') => {
114 ptr.bump();
115 COLONCOLON
116 }
117 _ => COLON,
118 };
119 }
120 '=' => {
121 return match ptr.current() {
122 Some('=') => {
123 ptr.bump();
124 EQEQ
125 }
126 Some('>') => {
127 ptr.bump();
128 FAT_ARROW
129 }
130 _ => EQ,
131 };
132 }
133 '!' => {
134 return match ptr.current() {
135 Some('=') => {
136 ptr.bump();
137 NEQ
138 }
139 _ => EXCL,
140 };
141 }
142 '-' => {
143 return if ptr.at('>') {
144 ptr.bump();
145 THIN_ARROW
146 } else {
147 MINUS
148 };
149 }
150 103
151 // If the character is an ident start not followed by another single 104 // If the character is an ident start not followed by another single
152 // quote, then this is a lifetime name: 105 // quote, then this is a lifetime name: