From 73ded3c63ca2522b7bb6ca8eb7834c5adc1a3511 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 27 Dec 2018 14:42:46 +0300 Subject: dedupe literal parsers --- crates/ra_syntax/src/validation/char.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'crates/ra_syntax/src/validation/char.rs') diff --git a/crates/ra_syntax/src/validation/char.rs b/crates/ra_syntax/src/validation/char.rs index 4728c85e6..deb5b0a9e 100644 --- a/crates/ra_syntax/src/validation/char.rs +++ b/crates/ra_syntax/src/validation/char.rs @@ -6,7 +6,7 @@ use arrayvec::ArrayString; use crate::{ ast::{self, AstNode}, - string_lexing::{self, CharComponentKind}, + string_lexing::{self, StringComponentKind}, TextRange, yellow::{ SyntaxError, @@ -41,12 +41,12 @@ pub(super) fn validate_char_node(node: ast::Char, errors: &mut Vec) pub(super) fn validate_char_component( text: &str, - kind: CharComponentKind, + kind: StringComponentKind, range: TextRange, errors: &mut Vec, ) { // Validate escapes - use self::CharComponentKind::*; + use self::StringComponentKind::*; match kind { AsciiEscape => validate_ascii_escape(text, range, errors), AsciiCodeEscape => validate_ascii_code_escape(text, range, errors), @@ -57,6 +57,7 @@ pub(super) fn validate_char_component( errors.push(SyntaxError::new(UnescapedCodepoint, range)); } } + StringComponentKind::IgnoreNewline => { /* always valid */ } } } -- cgit v1.2.3 From 359e70d1b20402ca9cc8731909daecfab598e55d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 27 Dec 2018 15:03:18 +0300 Subject: support literal suffixes --- crates/ra_syntax/src/validation/char.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'crates/ra_syntax/src/validation/char.rs') diff --git a/crates/ra_syntax/src/validation/char.rs b/crates/ra_syntax/src/validation/char.rs index deb5b0a9e..50184aaf8 100644 --- a/crates/ra_syntax/src/validation/char.rs +++ b/crates/ra_syntax/src/validation/char.rs @@ -30,6 +30,10 @@ pub(super) fn validate_char_node(node: ast::Char, errors: &mut Vec) errors.push(SyntaxError::new(UnclosedChar, literal_range)); } + if let Some(range) = components.suffix { + errors.push(SyntaxError::new(InvalidSuffix, range)); + } + if len == 0 { errors.push(SyntaxError::new(EmptyChar, literal_range)); } -- cgit v1.2.3 From 49b0fe20ab6aa752df3764908b7c21f4b1827e52 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 27 Dec 2018 15:10:30 +0300 Subject: fix suffix ranges --- crates/ra_syntax/src/validation/char.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'crates/ra_syntax/src/validation/char.rs') diff --git a/crates/ra_syntax/src/validation/char.rs b/crates/ra_syntax/src/validation/char.rs index 50184aaf8..19cd3830f 100644 --- a/crates/ra_syntax/src/validation/char.rs +++ b/crates/ra_syntax/src/validation/char.rs @@ -31,7 +31,10 @@ pub(super) fn validate_char_node(node: ast::Char, errors: &mut Vec) } if let Some(range) = components.suffix { - errors.push(SyntaxError::new(InvalidSuffix, range)); + errors.push(SyntaxError::new( + InvalidSuffix, + range + literal_range.start(), + )); } if len == 0 { -- cgit v1.2.3