diff options
Diffstat (limited to 'crates/syntax/src/validation.rs')
-rw-r--r-- | crates/syntax/src/validation.rs | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/crates/syntax/src/validation.rs b/crates/syntax/src/validation.rs index 62a37c50a..6f45149bf 100644 --- a/crates/syntax/src/validation.rs +++ b/crates/syntax/src/validation.rs | |||
@@ -4,7 +4,7 @@ mod block; | |||
4 | 4 | ||
5 | use crate::{ | 5 | use crate::{ |
6 | algo, ast, match_ast, AstNode, SyntaxError, | 6 | algo, ast, match_ast, AstNode, SyntaxError, |
7 | SyntaxKind::{BYTE, CHAR, CONST, FN, INT_NUMBER, TYPE_ALIAS}, | 7 | SyntaxKind::{CONST, FN, INT_NUMBER, TYPE_ALIAS}, |
8 | SyntaxNode, SyntaxToken, TextSize, T, | 8 | SyntaxNode, SyntaxToken, TextSize, T, |
9 | }; | 9 | }; |
10 | use rowan::Direction; | 10 | use rowan::Direction; |
@@ -121,41 +121,42 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) { | |||
121 | acc.push(SyntaxError::new_at_offset(rustc_unescape_error_to_string(err), off)); | 121 | acc.push(SyntaxError::new_at_offset(rustc_unescape_error_to_string(err), off)); |
122 | }; | 122 | }; |
123 | 123 | ||
124 | if let Some(s) = literal.as_string() { | 124 | match literal.kind() { |
125 | if !s.is_raw() { | 125 | ast::LiteralKind::String(s) => { |
126 | if let Some(without_quotes) = unquote(text, 1, '"') { | 126 | if !s.is_raw() { |
127 | unescape_literal(without_quotes, Mode::Str, &mut |range, char| { | 127 | if let Some(without_quotes) = unquote(text, 1, '"') { |
128 | if let Err(err) = char { | 128 | unescape_literal(without_quotes, Mode::Str, &mut |range, char| { |
129 | push_err(1, (range.start, err)); | 129 | if let Err(err) = char { |
130 | } | 130 | push_err(1, (range.start, err)); |
131 | }) | 131 | } |
132 | } | 132 | }) |
133 | } | 133 | } |
134 | } | ||
135 | if let Some(s) = literal.as_byte_string() { | ||
136 | if !s.is_raw() { | ||
137 | if let Some(without_quotes) = unquote(text, 2, '"') { | ||
138 | unescape_byte_literal(without_quotes, Mode::ByteStr, &mut |range, char| { | ||
139 | if let Err(err) = char { | ||
140 | push_err(2, (range.start, err)); | ||
141 | } | ||
142 | }) | ||
143 | } | 134 | } |
144 | } | 135 | } |
145 | } | 136 | ast::LiteralKind::ByteString(s) => { |
146 | 137 | if !s.is_raw() { | |
147 | match token.kind() { | 138 | if let Some(without_quotes) = unquote(text, 2, '"') { |
148 | BYTE => { | 139 | unescape_byte_literal(without_quotes, Mode::ByteStr, &mut |range, char| { |
149 | if let Some(Err(e)) = unquote(text, 2, '\'').map(unescape_byte) { | 140 | if let Err(err) = char { |
150 | push_err(2, e); | 141 | push_err(2, (range.start, err)); |
142 | } | ||
143 | }) | ||
144 | } | ||
151 | } | 145 | } |
152 | } | 146 | } |
153 | CHAR => { | 147 | ast::LiteralKind::Char => { |
154 | if let Some(Err(e)) = unquote(text, 1, '\'').map(unescape_char) { | 148 | if let Some(Err(e)) = unquote(text, 1, '\'').map(unescape_char) { |
155 | push_err(1, e); | 149 | push_err(1, e); |
156 | } | 150 | } |
157 | } | 151 | } |
158 | _ => (), | 152 | ast::LiteralKind::Byte => { |
153 | if let Some(Err(e)) = unquote(text, 2, '\'').map(unescape_byte) { | ||
154 | push_err(2, e); | ||
155 | } | ||
156 | } | ||
157 | ast::LiteralKind::IntNumber(_) | ||
158 | | ast::LiteralKind::FloatNumber(_) | ||
159 | | ast::LiteralKind::Bool(_) => {} | ||
159 | } | 160 | } |
160 | } | 161 | } |
161 | 162 | ||