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.rs41
1 files changed, 23 insertions, 18 deletions
diff --git a/crates/syntax/src/validation.rs b/crates/syntax/src/validation.rs
index 0f9a5e8ae..62a37c50a 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::{BYTE, CHAR, 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,18 +121,19 @@ 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 if let Some(s) = literal.as_string() {
125 BYTE => { 125 if !s.is_raw() {
126 if let Some(Err(e)) = unquote(text, 2, '\'').map(unescape_byte) { 126 if let Some(without_quotes) = unquote(text, 1, '"') {
127 push_err(2, e); 127 unescape_literal(without_quotes, Mode::Str, &mut |range, char| {
128 } 128 if let Err(err) = char {
129 } 129 push_err(1, (range.start, err));
130 CHAR => { 130 }
131 if let Some(Err(e)) = unquote(text, 1, '\'').map(unescape_char) { 131 })
132 push_err(1, e);
133 } 132 }
134 } 133 }
135 BYTE_STRING => { 134 }
135 if let Some(s) = literal.as_byte_string() {
136 if !s.is_raw() {
136 if let Some(without_quotes) = unquote(text, 2, '"') { 137 if let Some(without_quotes) = unquote(text, 2, '"') {
137 unescape_byte_literal(without_quotes, Mode::ByteStr, &mut |range, char| { 138 unescape_byte_literal(without_quotes, Mode::ByteStr, &mut |range, char| {
138 if let Err(err) = char { 139 if let Err(err) = char {
@@ -141,13 +142,17 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
141 }) 142 })
142 } 143 }
143 } 144 }
144 STRING => { 145 }
145 if let Some(without_quotes) = unquote(text, 1, '"') { 146
146 unescape_literal(without_quotes, Mode::Str, &mut |range, char| { 147 match token.kind() {
147 if let Err(err) = char { 148 BYTE => {
148 push_err(1, (range.start, err)); 149 if let Some(Err(e)) = unquote(text, 2, '\'').map(unescape_byte) {
149 } 150 push_err(2, e);
150 }) 151 }
152 }
153 CHAR => {
154 if let Some(Err(e)) = unquote(text, 1, '\'').map(unescape_char) {
155 push_err(1, e);
151 } 156 }
152 } 157 }
153 _ => (), 158 _ => (),