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