aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/validation.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/validation.rs')
-rw-r--r--crates/ra_syntax/src/validation.rs91
1 files changed, 87 insertions, 4 deletions
diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs
index e03c02d1b..1f904434e 100644
--- a/crates/ra_syntax/src/validation.rs
+++ b/crates/ra_syntax/src/validation.rs
@@ -1,16 +1,99 @@
1mod unescape;
2
3mod block; 1mod block;
4mod field_expr; 2mod field_expr;
5 3
4use ra_rustc_lexer::unescape;
5
6use crate::{ 6use crate::{
7 algo::visit::{visitor_ctx, VisitorCtx}, 7 algo::visit::{visitor_ctx, VisitorCtx},
8 ast, SyntaxError, 8 ast, SyntaxError, SyntaxErrorKind,
9 SyntaxKind::{BYTE, BYTE_STRING, CHAR, STRING}, 9 SyntaxKind::{BYTE, BYTE_STRING, CHAR, STRING},
10 SyntaxNode, TextUnit, T, 10 SyntaxNode, TextUnit, T,
11}; 11};
12 12
13pub(crate) use unescape::EscapeError; 13#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
14pub enum EscapeError {
15 ZeroChars,
16 MoreThanOneChar,
17 LoneSlash,
18 InvalidEscape,
19 BareCarriageReturn,
20 EscapeOnlyChar,
21 TooShortHexEscape,
22 InvalidCharInHexEscape,
23 OutOfRangeHexEscape,
24 NoBraceInUnicodeEscape,
25 InvalidCharInUnicodeEscape,
26 EmptyUnicodeEscape,
27 UnclosedUnicodeEscape,
28 LeadingUnderscoreUnicodeEscape,
29 OverlongUnicodeEscape,
30 LoneSurrogateUnicodeEscape,
31 OutOfRangeUnicodeEscape,
32 UnicodeEscapeInByte,
33 NonAsciiCharInByte,
34}
35
36impl From<ra_rustc_lexer::unescape::EscapeError> for EscapeError {
37 fn from(err: ra_rustc_lexer::unescape::EscapeError) -> Self {
38 match err {
39 ra_rustc_lexer::unescape::EscapeError::ZeroChars => EscapeError::ZeroChars,
40 ra_rustc_lexer::unescape::EscapeError::MoreThanOneChar => EscapeError::MoreThanOneChar,
41 ra_rustc_lexer::unescape::EscapeError::LoneSlash => EscapeError::LoneSlash,
42 ra_rustc_lexer::unescape::EscapeError::InvalidEscape => EscapeError::InvalidEscape,
43 ra_rustc_lexer::unescape::EscapeError::BareCarriageReturn
44 | ra_rustc_lexer::unescape::EscapeError::BareCarriageReturnInRawString => {
45 EscapeError::BareCarriageReturn
46 }
47 ra_rustc_lexer::unescape::EscapeError::EscapeOnlyChar => EscapeError::EscapeOnlyChar,
48 ra_rustc_lexer::unescape::EscapeError::TooShortHexEscape => {
49 EscapeError::TooShortHexEscape
50 }
51 ra_rustc_lexer::unescape::EscapeError::InvalidCharInHexEscape => {
52 EscapeError::InvalidCharInHexEscape
53 }
54 ra_rustc_lexer::unescape::EscapeError::OutOfRangeHexEscape => {
55 EscapeError::OutOfRangeHexEscape
56 }
57 ra_rustc_lexer::unescape::EscapeError::NoBraceInUnicodeEscape => {
58 EscapeError::NoBraceInUnicodeEscape
59 }
60 ra_rustc_lexer::unescape::EscapeError::InvalidCharInUnicodeEscape => {
61 EscapeError::InvalidCharInUnicodeEscape
62 }
63 ra_rustc_lexer::unescape::EscapeError::EmptyUnicodeEscape => {
64 EscapeError::EmptyUnicodeEscape
65 }
66 ra_rustc_lexer::unescape::EscapeError::UnclosedUnicodeEscape => {
67 EscapeError::UnclosedUnicodeEscape
68 }
69 ra_rustc_lexer::unescape::EscapeError::LeadingUnderscoreUnicodeEscape => {
70 EscapeError::LeadingUnderscoreUnicodeEscape
71 }
72 ra_rustc_lexer::unescape::EscapeError::OverlongUnicodeEscape => {
73 EscapeError::OverlongUnicodeEscape
74 }
75 ra_rustc_lexer::unescape::EscapeError::LoneSurrogateUnicodeEscape => {
76 EscapeError::LoneSurrogateUnicodeEscape
77 }
78 ra_rustc_lexer::unescape::EscapeError::OutOfRangeUnicodeEscape => {
79 EscapeError::OutOfRangeUnicodeEscape
80 }
81 ra_rustc_lexer::unescape::EscapeError::UnicodeEscapeInByte => {
82 EscapeError::UnicodeEscapeInByte
83 }
84 ra_rustc_lexer::unescape::EscapeError::NonAsciiCharInByte
85 | ra_rustc_lexer::unescape::EscapeError::NonAsciiCharInByteString => {
86 EscapeError::NonAsciiCharInByte
87 }
88 }
89 }
90}
91
92impl From<ra_rustc_lexer::unescape::EscapeError> for SyntaxErrorKind {
93 fn from(err: ra_rustc_lexer::unescape::EscapeError) -> Self {
94 SyntaxErrorKind::EscapeError(err.into())
95 }
96}
14 97
15pub(crate) fn validate(root: &SyntaxNode) -> Vec<SyntaxError> { 98pub(crate) fn validate(root: &SyntaxNode) -> Vec<SyntaxError> {
16 let mut errors = Vec::new(); 99 let mut errors = Vec::new();