diff options
Diffstat (limited to 'crates/ra_syntax/src/validation')
-rw-r--r-- | crates/ra_syntax/src/validation/byte.rs | 14 | ||||
-rw-r--r-- | crates/ra_syntax/src/validation/byte_string.rs | 13 | ||||
-rw-r--r-- | crates/ra_syntax/src/validation/char.rs | 14 | ||||
-rw-r--r-- | crates/ra_syntax/src/validation/string.rs | 24 |
4 files changed, 45 insertions, 20 deletions
diff --git a/crates/ra_syntax/src/validation/byte.rs b/crates/ra_syntax/src/validation/byte.rs index 43c0d7edd..d0897eeed 100644 --- a/crates/ra_syntax/src/validation/byte.rs +++ b/crates/ra_syntax/src/validation/byte.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use crate::{ | 3 | use crate::{ |
4 | ast::{self, AstNode}, | 4 | ast::{self, AstNode}, |
5 | string_lexing::{self, CharComponentKind}, | 5 | string_lexing::{self, StringComponentKind}, |
6 | TextRange, | 6 | TextRange, |
7 | validation::char, | 7 | validation::char, |
8 | yellow::{ | 8 | yellow::{ |
@@ -27,6 +27,13 @@ pub(super) fn validate_byte_node(node: ast::Byte, errors: &mut Vec<SyntaxError>) | |||
27 | errors.push(SyntaxError::new(UnclosedByte, literal_range)); | 27 | errors.push(SyntaxError::new(UnclosedByte, literal_range)); |
28 | } | 28 | } |
29 | 29 | ||
30 | if let Some(range) = components.suffix { | ||
31 | errors.push(SyntaxError::new( | ||
32 | InvalidSuffix, | ||
33 | range + literal_range.start(), | ||
34 | )); | ||
35 | } | ||
36 | |||
30 | if len == 0 { | 37 | if len == 0 { |
31 | errors.push(SyntaxError::new(EmptyByte, literal_range)); | 38 | errors.push(SyntaxError::new(EmptyByte, literal_range)); |
32 | } | 39 | } |
@@ -38,11 +45,11 @@ pub(super) fn validate_byte_node(node: ast::Byte, errors: &mut Vec<SyntaxError>) | |||
38 | 45 | ||
39 | pub(super) fn validate_byte_component( | 46 | pub(super) fn validate_byte_component( |
40 | text: &str, | 47 | text: &str, |
41 | kind: CharComponentKind, | 48 | kind: StringComponentKind, |
42 | range: TextRange, | 49 | range: TextRange, |
43 | errors: &mut Vec<SyntaxError>, | 50 | errors: &mut Vec<SyntaxError>, |
44 | ) { | 51 | ) { |
45 | use self::CharComponentKind::*; | 52 | use self::StringComponentKind::*; |
46 | match kind { | 53 | match kind { |
47 | AsciiEscape => validate_byte_escape(text, range, errors), | 54 | AsciiEscape => validate_byte_escape(text, range, errors), |
48 | AsciiCodeEscape => validate_byte_code_escape(text, range, errors), | 55 | AsciiCodeEscape => validate_byte_code_escape(text, range, errors), |
@@ -63,6 +70,7 @@ pub(super) fn validate_byte_component( | |||
63 | errors.push(SyntaxError::new(ByteOutOfRange, range)); | 70 | errors.push(SyntaxError::new(ByteOutOfRange, range)); |
64 | } | 71 | } |
65 | } | 72 | } |
73 | IgnoreNewline => { /* always valid */ } | ||
66 | } | 74 | } |
67 | } | 75 | } |
68 | 76 | ||
diff --git a/crates/ra_syntax/src/validation/byte_string.rs b/crates/ra_syntax/src/validation/byte_string.rs index 7b830e97c..f7a4fb156 100644 --- a/crates/ra_syntax/src/validation/byte_string.rs +++ b/crates/ra_syntax/src/validation/byte_string.rs | |||
@@ -17,21 +17,28 @@ pub(crate) fn validate_byte_string_node(node: ast::ByteString, errors: &mut Vec< | |||
17 | let range = component.range + literal_range.start(); | 17 | let range = component.range + literal_range.start(); |
18 | 18 | ||
19 | match component.kind { | 19 | match component.kind { |
20 | StringComponentKind::Char(kind) => { | 20 | StringComponentKind::IgnoreNewline => { /* always valid */ } |
21 | _ => { | ||
21 | // Chars must escape \t, \n and \r codepoints, but strings don't | 22 | // Chars must escape \t, \n and \r codepoints, but strings don't |
22 | let text = &literal_text[component.range]; | 23 | let text = &literal_text[component.range]; |
23 | match text { | 24 | match text { |
24 | "\t" | "\n" | "\r" => { /* always valid */ } | 25 | "\t" | "\n" | "\r" => { /* always valid */ } |
25 | _ => byte::validate_byte_component(text, kind, range, errors), | 26 | _ => byte::validate_byte_component(text, component.kind, range, errors), |
26 | } | 27 | } |
27 | } | 28 | } |
28 | StringComponentKind::IgnoreNewline => { /* always valid */ } | ||
29 | } | 29 | } |
30 | } | 30 | } |
31 | 31 | ||
32 | if !components.has_closing_quote { | 32 | if !components.has_closing_quote { |
33 | errors.push(SyntaxError::new(UnclosedString, literal_range)); | 33 | errors.push(SyntaxError::new(UnclosedString, literal_range)); |
34 | } | 34 | } |
35 | |||
36 | if let Some(range) = components.suffix { | ||
37 | errors.push(SyntaxError::new( | ||
38 | InvalidSuffix, | ||
39 | range + literal_range.start(), | ||
40 | )); | ||
41 | } | ||
35 | } | 42 | } |
36 | 43 | ||
37 | #[cfg(test)] | 44 | #[cfg(test)] |
diff --git a/crates/ra_syntax/src/validation/char.rs b/crates/ra_syntax/src/validation/char.rs index 4728c85e6..19cd3830f 100644 --- a/crates/ra_syntax/src/validation/char.rs +++ b/crates/ra_syntax/src/validation/char.rs | |||
@@ -6,7 +6,7 @@ use arrayvec::ArrayString; | |||
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
8 | ast::{self, AstNode}, | 8 | ast::{self, AstNode}, |
9 | string_lexing::{self, CharComponentKind}, | 9 | string_lexing::{self, StringComponentKind}, |
10 | TextRange, | 10 | TextRange, |
11 | yellow::{ | 11 | yellow::{ |
12 | SyntaxError, | 12 | SyntaxError, |
@@ -30,6 +30,13 @@ pub(super) fn validate_char_node(node: ast::Char, errors: &mut Vec<SyntaxError>) | |||
30 | errors.push(SyntaxError::new(UnclosedChar, literal_range)); | 30 | errors.push(SyntaxError::new(UnclosedChar, literal_range)); |
31 | } | 31 | } |
32 | 32 | ||
33 | if let Some(range) = components.suffix { | ||
34 | errors.push(SyntaxError::new( | ||
35 | InvalidSuffix, | ||
36 | range + literal_range.start(), | ||
37 | )); | ||
38 | } | ||
39 | |||
33 | if len == 0 { | 40 | if len == 0 { |
34 | errors.push(SyntaxError::new(EmptyChar, literal_range)); | 41 | errors.push(SyntaxError::new(EmptyChar, literal_range)); |
35 | } | 42 | } |
@@ -41,12 +48,12 @@ pub(super) fn validate_char_node(node: ast::Char, errors: &mut Vec<SyntaxError>) | |||
41 | 48 | ||
42 | pub(super) fn validate_char_component( | 49 | pub(super) fn validate_char_component( |
43 | text: &str, | 50 | text: &str, |
44 | kind: CharComponentKind, | 51 | kind: StringComponentKind, |
45 | range: TextRange, | 52 | range: TextRange, |
46 | errors: &mut Vec<SyntaxError>, | 53 | errors: &mut Vec<SyntaxError>, |
47 | ) { | 54 | ) { |
48 | // Validate escapes | 55 | // Validate escapes |
49 | use self::CharComponentKind::*; | 56 | use self::StringComponentKind::*; |
50 | match kind { | 57 | match kind { |
51 | AsciiEscape => validate_ascii_escape(text, range, errors), | 58 | AsciiEscape => validate_ascii_escape(text, range, errors), |
52 | AsciiCodeEscape => validate_ascii_code_escape(text, range, errors), | 59 | AsciiCodeEscape => validate_ascii_code_escape(text, range, errors), |
@@ -57,6 +64,7 @@ pub(super) fn validate_char_component( | |||
57 | errors.push(SyntaxError::new(UnescapedCodepoint, range)); | 64 | errors.push(SyntaxError::new(UnescapedCodepoint, range)); |
58 | } | 65 | } |
59 | } | 66 | } |
67 | StringComponentKind::IgnoreNewline => { /* always valid */ } | ||
60 | } | 68 | } |
61 | } | 69 | } |
62 | 70 | ||
diff --git a/crates/ra_syntax/src/validation/string.rs b/crates/ra_syntax/src/validation/string.rs index 089879d15..1371bb1f0 100644 --- a/crates/ra_syntax/src/validation/string.rs +++ b/crates/ra_syntax/src/validation/string.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use crate::{ | 1 | use crate::{ |
2 | ast::{self, AstNode}, | 2 | ast::{self, AstNode}, |
3 | string_lexing::{self, StringComponentKind}, | 3 | string_lexing, |
4 | yellow::{ | 4 | yellow::{ |
5 | SyntaxError, | 5 | SyntaxError, |
6 | SyntaxErrorKind::*, | 6 | SyntaxErrorKind::*, |
@@ -16,22 +16,24 @@ pub(crate) fn validate_string_node(node: ast::String, errors: &mut Vec<SyntaxErr | |||
16 | for component in &mut components { | 16 | for component in &mut components { |
17 | let range = component.range + literal_range.start(); | 17 | let range = component.range + literal_range.start(); |
18 | 18 | ||
19 | match component.kind { | 19 | // Chars must escape \t, \n and \r codepoints, but strings don't |
20 | StringComponentKind::Char(kind) => { | 20 | let text = &literal_text[component.range]; |
21 | // Chars must escape \t, \n and \r codepoints, but strings don't | 21 | match text { |
22 | let text = &literal_text[component.range]; | 22 | "\t" | "\n" | "\r" => { /* always valid */ } |
23 | match text { | 23 | _ => char::validate_char_component(text, component.kind, range, errors), |
24 | "\t" | "\n" | "\r" => { /* always valid */ } | ||
25 | _ => char::validate_char_component(text, kind, range, errors), | ||
26 | } | ||
27 | } | ||
28 | StringComponentKind::IgnoreNewline => { /* always valid */ } | ||
29 | } | 24 | } |
30 | } | 25 | } |
31 | 26 | ||
32 | if !components.has_closing_quote { | 27 | if !components.has_closing_quote { |
33 | errors.push(SyntaxError::new(UnclosedString, literal_range)); | 28 | errors.push(SyntaxError::new(UnclosedString, literal_range)); |
34 | } | 29 | } |
30 | |||
31 | if let Some(range) = components.suffix { | ||
32 | errors.push(SyntaxError::new( | ||
33 | InvalidSuffix, | ||
34 | range + literal_range.start(), | ||
35 | )); | ||
36 | } | ||
35 | } | 37 | } |
36 | 38 | ||
37 | #[cfg(test)] | 39 | #[cfg(test)] |