diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-11-06 20:10:15 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-11-06 20:10:15 +0000 |
commit | fe13a4aeb1fd33aeda2d884b2691b23b0ca5daee (patch) | |
tree | ba8b0ad89c0b87339b7a4d65bd8b51b0c5f99a5c /crates/syntax | |
parent | 1faa9559fe3d731856c4e7e83b40d186f1a21f9e (diff) | |
parent | 6725dcf847300b9cddcbb061b159317113860f31 (diff) |
Merge #6484
6484: Minor, cleanup style r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/syntax')
-rw-r--r-- | crates/syntax/src/parsing/lexer.rs | 114 |
1 files changed, 64 insertions, 50 deletions
diff --git a/crates/syntax/src/parsing/lexer.rs b/crates/syntax/src/parsing/lexer.rs index 7e38c32cc..5674ecb84 100644 --- a/crates/syntax/src/parsing/lexer.rs +++ b/crates/syntax/src/parsing/lexer.rs | |||
@@ -3,7 +3,7 @@ | |||
3 | 3 | ||
4 | use std::convert::TryInto; | 4 | use std::convert::TryInto; |
5 | 5 | ||
6 | use rustc_lexer::{LiteralKind as LK, RawStrError}; | 6 | use rustc_lexer::RawStrError; |
7 | 7 | ||
8 | use crate::{ | 8 | use crate::{ |
9 | SyntaxError, | 9 | SyntaxError, |
@@ -185,63 +185,77 @@ fn rustc_token_kind_to_syntax_kind( | |||
185 | return (syntax_kind, None); | 185 | return (syntax_kind, None); |
186 | 186 | ||
187 | fn match_literal_kind(kind: &rustc_lexer::LiteralKind) -> (SyntaxKind, Option<&'static str>) { | 187 | fn match_literal_kind(kind: &rustc_lexer::LiteralKind) -> (SyntaxKind, Option<&'static str>) { |
188 | #[rustfmt::skip] | 188 | let mut err = ""; |
189 | let syntax_kind = match *kind { | 189 | let syntax_kind = match *kind { |
190 | LK::Int { empty_int: false, .. } => INT_NUMBER, | 190 | rustc_lexer::LiteralKind::Int { empty_int, base: _ } => { |
191 | LK::Int { empty_int: true, .. } => { | 191 | if empty_int { |
192 | return (INT_NUMBER, Some("Missing digits after the integer base prefix")) | 192 | err = "Missing digits after the integer base prefix"; |
193 | } | ||
194 | INT_NUMBER | ||
193 | } | 195 | } |
194 | 196 | rustc_lexer::LiteralKind::Float { empty_exponent, base: _ } => { | |
195 | LK::Float { empty_exponent: false, .. } => FLOAT_NUMBER, | 197 | if empty_exponent { |
196 | LK::Float { empty_exponent: true, .. } => { | 198 | err = "Missing digits after the exponent symbol"; |
197 | return (FLOAT_NUMBER, Some("Missing digits after the exponent symbol")) | 199 | } |
200 | FLOAT_NUMBER | ||
198 | } | 201 | } |
199 | 202 | rustc_lexer::LiteralKind::Char { terminated } => { | |
200 | LK::Char { terminated: true } => CHAR, | 203 | if !terminated { |
201 | LK::Char { terminated: false } => { | 204 | err = "Missing trailing `'` symbol to terminate the character literal"; |
202 | return (CHAR, Some("Missing trailing `'` symbol to terminate the character literal")) | 205 | } |
206 | CHAR | ||
203 | } | 207 | } |
204 | 208 | rustc_lexer::LiteralKind::Byte { terminated } => { | |
205 | LK::Byte { terminated: true } => BYTE, | 209 | if !terminated { |
206 | LK::Byte { terminated: false } => { | 210 | err = "Missing trailing `'` symbol to terminate the byte literal"; |
207 | return (BYTE, Some("Missing trailing `'` symbol to terminate the byte literal")) | 211 | } |
212 | BYTE | ||
208 | } | 213 | } |
209 | 214 | rustc_lexer::LiteralKind::Str { terminated } => { | |
210 | LK::Str { terminated: true } => STRING, | 215 | if !terminated { |
211 | LK::Str { terminated: false } => { | 216 | err = "Missing trailing `\"` symbol to terminate the string literal"; |
212 | return (STRING, Some("Missing trailing `\"` symbol to terminate the string literal")) | 217 | } |
218 | STRING | ||
213 | } | 219 | } |
214 | 220 | rustc_lexer::LiteralKind::ByteStr { terminated } => { | |
215 | 221 | if !terminated { | |
216 | LK::ByteStr { terminated: true } => BYTE_STRING, | 222 | err = "Missing trailing `\"` symbol to terminate the byte string literal"; |
217 | LK::ByteStr { terminated: false } => { | 223 | } |
218 | return (BYTE_STRING, Some("Missing trailing `\"` symbol to terminate the byte string literal")) | 224 | BYTE_STRING |
225 | } | ||
226 | rustc_lexer::LiteralKind::RawStr { err: raw_str_err, .. } => { | ||
227 | if let Some(raw_str_err) = raw_str_err { | ||
228 | err = match raw_str_err { | ||
229 | RawStrError::InvalidStarter { .. } => "Missing `\"` symbol after `#` symbols to begin the raw string literal", | ||
230 | RawStrError::NoTerminator { expected, found, .. } => if expected == found { | ||
231 | "Missing trailing `\"` to terminate the raw string literal" | ||
232 | } else { | ||
233 | "Missing trailing `\"` with `#` symbols to terminate the raw string literal" | ||
234 | }, | ||
235 | RawStrError::TooManyDelimiters { .. } => "Too many `#` symbols: raw strings may be delimited by up to 65535 `#` symbols", | ||
236 | }; | ||
237 | }; | ||
238 | RAW_STRING | ||
239 | } | ||
240 | rustc_lexer::LiteralKind::RawByteStr { err: raw_str_err, .. } => { | ||
241 | if let Some(raw_str_err) = raw_str_err { | ||
242 | err = match raw_str_err { | ||
243 | RawStrError::InvalidStarter { .. } => "Missing `\"` symbol after `#` symbols to begin the raw byte string literal", | ||
244 | RawStrError::NoTerminator { expected, found, .. } => if expected == found { | ||
245 | "Missing trailing `\"` to terminate the raw byte string literal" | ||
246 | } else { | ||
247 | "Missing trailing `\"` with `#` symbols to terminate the raw byte string literal" | ||
248 | }, | ||
249 | RawStrError::TooManyDelimiters { .. } => "Too many `#` symbols: raw byte strings may be delimited by up to 65535 `#` symbols", | ||
250 | }; | ||
251 | }; | ||
252 | |||
253 | RAW_BYTE_STRING | ||
219 | } | 254 | } |
220 | |||
221 | LK::RawStr { err, .. } => match err { | ||
222 | None => RAW_STRING, | ||
223 | Some(RawStrError::InvalidStarter { .. }) => return (RAW_STRING, Some("Missing `\"` symbol after `#` symbols to begin the raw string literal")), | ||
224 | Some(RawStrError::NoTerminator { expected, found, .. }) => if expected == found { | ||
225 | return (RAW_STRING, Some("Missing trailing `\"` to terminate the raw string literal")) | ||
226 | } else { | ||
227 | return (RAW_STRING, Some("Missing trailing `\"` with `#` symbols to terminate the raw string literal")) | ||
228 | |||
229 | }, | ||
230 | Some(RawStrError::TooManyDelimiters { .. }) => return (RAW_STRING, Some("Too many `#` symbols: raw strings may be delimited by up to 65535 `#` symbols")), | ||
231 | }, | ||
232 | LK::RawByteStr { err, .. } => match err { | ||
233 | None => RAW_BYTE_STRING, | ||
234 | Some(RawStrError::InvalidStarter { .. }) => return (RAW_BYTE_STRING, Some("Missing `\"` symbol after `#` symbols to begin the raw byte string literal")), | ||
235 | Some(RawStrError::NoTerminator { expected, found, .. }) => if expected == found { | ||
236 | return (RAW_BYTE_STRING, Some("Missing trailing `\"` to terminate the raw byte string literal")) | ||
237 | } else { | ||
238 | return (RAW_BYTE_STRING, Some("Missing trailing `\"` with `#` symbols to terminate the raw byte string literal")) | ||
239 | |||
240 | }, | ||
241 | Some(RawStrError::TooManyDelimiters { .. }) => return (RAW_BYTE_STRING, Some("Too many `#` symbols: raw byte strings may be delimited by up to 65535 `#` symbols")), | ||
242 | }, | ||
243 | }; | 255 | }; |
244 | 256 | ||
245 | (syntax_kind, None) | 257 | let err = if err.is_empty() { None } else { Some(err) }; |
258 | |||
259 | (syntax_kind, err) | ||
246 | } | 260 | } |
247 | } | 261 | } |