aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/yellow
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-11-07 11:09:40 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-11-07 11:09:40 +0000
commit2e2445444abcde9fc2f50c70a8157958f7d5ddd8 (patch)
tree8c667fc65a65c0e7978add07b72ec532a4b6eb7b /crates/ra_syntax/src/yellow
parenta46a07eca33f951b3d445e49dcbff3c53962a8e0 (diff)
parent433a8061910a388f777b839eb67f2582f91b6c7a (diff)
Merge #207
207: Finish implementing char validation r=aochagavia a=aochagavia The only thing missing right now are good integration tests (and maybe more descriptive error messages) Co-authored-by: Adolfo OchagavĂ­a <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/yellow')
-rw-r--r--crates/ra_syntax/src/yellow/syntax_error.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/yellow/syntax_error.rs b/crates/ra_syntax/src/yellow/syntax_error.rs
index f3df6bc15..c524adf39 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 {
34 } 34 }
35 } 35 }
36 36
37 pub fn kind(&self) -> SyntaxErrorKind {
38 self.kind.clone()
39 }
40
37 pub fn location(&self) -> Location { 41 pub fn location(&self) -> Location {
38 self.location.clone() 42 self.location.clone()
39 } 43 }
@@ -64,11 +68,20 @@ impl fmt::Display for SyntaxError {
64#[derive(Debug, Clone, PartialEq, Eq, Hash)] 68#[derive(Debug, Clone, PartialEq, Eq, Hash)]
65pub enum SyntaxErrorKind { 69pub enum SyntaxErrorKind {
66 ParseError(ParseError), 70 ParseError(ParseError),
71 UnescapedCodepoint,
67 EmptyChar, 72 EmptyChar,
68 UnclosedChar, 73 UnclosedChar,
69 LongChar, 74 LongChar,
70 EmptyAsciiEscape, 75 EmptyAsciiEscape,
71 InvalidAsciiEscape, 76 InvalidAsciiEscape,
77 TooShortAsciiCodeEscape,
78 AsciiCodeEscapeOutOfRange,
79 MalformedAsciiCodeEscape,
80 UnclosedUnicodeEscape,
81 MalformedUnicodeEscape,
82 EmptyUnicodeEcape,
83 OverlongUnicodeEscape,
84 UnicodeEscapeOutOfRange,
72} 85}
73 86
74#[derive(Debug, Clone, PartialEq, Eq, Hash)] 87#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -78,11 +91,24 @@ impl fmt::Display for SyntaxErrorKind {
78 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 91 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
79 use self::SyntaxErrorKind::*; 92 use self::SyntaxErrorKind::*;
80 match self { 93 match self {
94 UnescapedCodepoint => write!(f, "This codepoint should always be escaped"),
81 EmptyAsciiEscape => write!(f, "Empty escape sequence"), 95 EmptyAsciiEscape => write!(f, "Empty escape sequence"),
82 InvalidAsciiEscape => write!(f, "Invalid escape sequence"), 96 InvalidAsciiEscape => write!(f, "Invalid escape sequence"),
83 EmptyChar => write!(f, "Empty char literal"), 97 EmptyChar => write!(f, "Empty char literal"),
84 UnclosedChar => write!(f, "Unclosed char literal"), 98 UnclosedChar => write!(f, "Unclosed char literal"),
85 LongChar => write!(f, "Char literal should be one character long"), 99 LongChar => write!(f, "Char literal should be one character long"),
100 TooShortAsciiCodeEscape => write!(f, "Escape sequence should have two digits"),
101 AsciiCodeEscapeOutOfRange => {
102 write!(f, "Escape sequence should be between \\x00 and \\x7F")
103 }
104 MalformedAsciiCodeEscape => write!(f, "Escape sequence should be a hexadecimal number"),
105 UnclosedUnicodeEscape => write!(f, "Missing `}}`"),
106 MalformedUnicodeEscape => write!(f, "Malformed unicode escape sequence"),
107 EmptyUnicodeEcape => write!(f, "Empty unicode escape sequence"),
108 OverlongUnicodeEscape => {
109 write!(f, "Unicode escape sequence should have at most 6 digits")
110 }
111 UnicodeEscapeOutOfRange => write!(f, "Unicode escape code should be at most 0x10FFFF"),
86 ParseError(msg) => write!(f, "{}", msg.0), 112 ParseError(msg) => write!(f, "{}", msg.0),
87 } 113 }
88 } 114 }