From c56db92d1f9b1a24de24cefd996c43c7b988b4c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Ochagav=C3=ADa?= Date: Tue, 6 Nov 2018 17:05:06 +0100 Subject: Finish implementing char validation --- crates/ra_syntax/src/yellow/syntax_error.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'crates/ra_syntax/src/yellow') diff --git a/crates/ra_syntax/src/yellow/syntax_error.rs b/crates/ra_syntax/src/yellow/syntax_error.rs index f3df6bc15..9aed9e81e 100644 --- a/crates/ra_syntax/src/yellow/syntax_error.rs +++ b/crates/ra_syntax/src/yellow/syntax_error.rs @@ -69,6 +69,14 @@ pub enum SyntaxErrorKind { LongChar, EmptyAsciiEscape, InvalidAsciiEscape, + TooShortAsciiCodeEscape, + AsciiCodeEscapeOutOfRange, + MalformedAsciiCodeEscape, + UnclosedUnicodeEscape, + MalformedUnicodeEscape, + EmptyUnicodeEcape, + OverlongUnicodeEscape, + UnicodeEscapeOutOfRange, } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -83,6 +91,14 @@ impl fmt::Display for SyntaxErrorKind { EmptyChar => write!(f, "Empty char literal"), UnclosedChar => write!(f, "Unclosed char literal"), LongChar => write!(f, "Char literal should be one character long"), + TooShortAsciiCodeEscape => write!(f, "Escape sequence should have two digits"), + AsciiCodeEscapeOutOfRange => write!(f, "Escape sequence should be between \\x00 and \\x7F"), + MalformedAsciiCodeEscape => write!(f, "Escape sequence should be a hexadecimal number"), + UnclosedUnicodeEscape => write!(f, "Missing `}}`"), + MalformedUnicodeEscape => write!(f, "Malformed unicode escape sequence"), + EmptyUnicodeEcape => write!(f, "Empty unicode escape sequence"), + OverlongUnicodeEscape => write!(f, "Unicode escape sequence should have at most 6 digits"), + UnicodeEscapeOutOfRange => write!(f, "Unicode escape code should be at most 0x10FFFF"), ParseError(msg) => write!(f, "{}", msg.0), } } -- cgit v1.2.3 From 94796e6447c8af9d7444164c2175ca5dae4a563e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Ochagav=C3=ADa?= Date: Wed, 7 Nov 2018 11:35:33 +0100 Subject: Add lots of tests --- crates/ra_syntax/src/yellow/syntax_error.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'crates/ra_syntax/src/yellow') diff --git a/crates/ra_syntax/src/yellow/syntax_error.rs b/crates/ra_syntax/src/yellow/syntax_error.rs index 9aed9e81e..e2e660975 100644 --- a/crates/ra_syntax/src/yellow/syntax_error.rs +++ b/crates/ra_syntax/src/yellow/syntax_error.rs @@ -34,6 +34,10 @@ impl SyntaxError { } } + pub fn kind(&self) -> SyntaxErrorKind { + self.kind.clone() + } + pub fn location(&self) -> Location { self.location.clone() } @@ -64,6 +68,7 @@ impl fmt::Display for SyntaxError { #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum SyntaxErrorKind { ParseError(ParseError), + UnescapedCodepoint, EmptyChar, UnclosedChar, LongChar, @@ -86,6 +91,7 @@ impl fmt::Display for SyntaxErrorKind { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { use self::SyntaxErrorKind::*; match self { + UnescapedCodepoint => write!(f, "This codepoint should always be escaped"), EmptyAsciiEscape => write!(f, "Empty escape sequence"), InvalidAsciiEscape => write!(f, "Invalid escape sequence"), EmptyChar => write!(f, "Empty char literal"), -- cgit v1.2.3 From e37ba706ccc435346c35042c2b6c4b483494268b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Ochagav=C3=ADa?= Date: Wed, 7 Nov 2018 11:41:42 +0100 Subject: cargo format --- crates/ra_syntax/src/yellow/syntax_error.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'crates/ra_syntax/src/yellow') diff --git a/crates/ra_syntax/src/yellow/syntax_error.rs b/crates/ra_syntax/src/yellow/syntax_error.rs index e2e660975..c524adf39 100644 --- a/crates/ra_syntax/src/yellow/syntax_error.rs +++ b/crates/ra_syntax/src/yellow/syntax_error.rs @@ -98,12 +98,16 @@ impl fmt::Display for SyntaxErrorKind { UnclosedChar => write!(f, "Unclosed char literal"), LongChar => write!(f, "Char literal should be one character long"), TooShortAsciiCodeEscape => write!(f, "Escape sequence should have two digits"), - AsciiCodeEscapeOutOfRange => write!(f, "Escape sequence should be between \\x00 and \\x7F"), + AsciiCodeEscapeOutOfRange => { + write!(f, "Escape sequence should be between \\x00 and \\x7F") + } MalformedAsciiCodeEscape => write!(f, "Escape sequence should be a hexadecimal number"), UnclosedUnicodeEscape => write!(f, "Missing `}}`"), MalformedUnicodeEscape => write!(f, "Malformed unicode escape sequence"), EmptyUnicodeEcape => write!(f, "Empty unicode escape sequence"), - OverlongUnicodeEscape => write!(f, "Unicode escape sequence should have at most 6 digits"), + OverlongUnicodeEscape => { + write!(f, "Unicode escape sequence should have at most 6 digits") + } UnicodeEscapeOutOfRange => write!(f, "Unicode escape code should be at most 0x10FFFF"), ParseError(msg) => write!(f, "{}", msg.0), } -- cgit v1.2.3