diff options
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | crates/ra_syntax/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_syntax/src/lib.rs | 1 | ||||
-rw-r--r-- | crates/ra_syntax/src/utils.rs | 36 | ||||
-rw-r--r-- | crates/ra_syntax/src/validation.rs | 6 |
5 files changed, 6 insertions, 39 deletions
diff --git a/Cargo.lock b/Cargo.lock index fd1fb5ea5..555efdfb9 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -671,6 +671,7 @@ dependencies = [ | |||
671 | name = "ra_syntax" | 671 | name = "ra_syntax" |
672 | version = "0.1.0" | 672 | version = "0.1.0" |
673 | dependencies = [ | 673 | dependencies = [ |
674 | "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", | ||
674 | "drop_bomb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", | 675 | "drop_bomb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", |
675 | "itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)", | 676 | "itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)", |
676 | "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", | 677 | "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", |
diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml index de4b25e67..0f709026f 100644 --- a/crates/ra_syntax/Cargo.toml +++ b/crates/ra_syntax/Cargo.toml | |||
@@ -8,6 +8,7 @@ description = "Comment and whitespace preserving parser for the Rust langauge" | |||
8 | repository = "https://github.com/rust-analyzer/rust-analyzer" | 8 | repository = "https://github.com/rust-analyzer/rust-analyzer" |
9 | 9 | ||
10 | [dependencies] | 10 | [dependencies] |
11 | arrayvec = "0.4.7" | ||
11 | unicode-xid = "0.1.0" | 12 | unicode-xid = "0.1.0" |
12 | itertools = "0.7.8" | 13 | itertools = "0.7.8" |
13 | drop_bomb = "0.1.4" | 14 | drop_bomb = "0.1.4" |
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 123002825..319fb947d 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs | |||
@@ -20,6 +20,7 @@ | |||
20 | #![allow(missing_docs)] | 20 | #![allow(missing_docs)] |
21 | //#![warn(unreachable_pub)] // rust-lang/rust#47816 | 21 | //#![warn(unreachable_pub)] // rust-lang/rust#47816 |
22 | 22 | ||
23 | extern crate arrayvec; | ||
23 | extern crate drop_bomb; | 24 | extern crate drop_bomb; |
24 | extern crate itertools; | 25 | extern crate itertools; |
25 | extern crate parking_lot; | 26 | extern crate parking_lot; |
diff --git a/crates/ra_syntax/src/utils.rs b/crates/ra_syntax/src/utils.rs index 5bef4a639..cad9544be 100644 --- a/crates/ra_syntax/src/utils.rs +++ b/crates/ra_syntax/src/utils.rs | |||
@@ -1,6 +1,5 @@ | |||
1 | use crate::{File, SyntaxKind, SyntaxNodeRef, WalkEvent}; | 1 | use crate::{File, SyntaxKind, SyntaxNodeRef, WalkEvent}; |
2 | use std::fmt::Write; | 2 | use std::fmt::Write; |
3 | use std::ops::Deref; | ||
4 | use std::str; | 3 | use std::str; |
5 | 4 | ||
6 | /// Parse a file and create a string representation of the resulting parse tree. | 5 | /// Parse a file and create a string representation of the resulting parse tree. |
@@ -80,38 +79,3 @@ pub(crate) fn validate_block_structure(root: SyntaxNodeRef) { | |||
80 | } | 79 | } |
81 | } | 80 | } |
82 | } | 81 | } |
83 | |||
84 | #[derive(Debug)] | ||
85 | pub struct MutAsciiString<'a> { | ||
86 | buf: &'a mut [u8], | ||
87 | len: usize, | ||
88 | } | ||
89 | |||
90 | impl<'a> MutAsciiString<'a> { | ||
91 | pub fn new(buf: &'a mut [u8]) -> MutAsciiString<'a> { | ||
92 | MutAsciiString { buf, len: 0 } | ||
93 | } | ||
94 | |||
95 | pub fn as_str(&self) -> &str { | ||
96 | str::from_utf8(&self.buf[..self.len]).unwrap() | ||
97 | } | ||
98 | |||
99 | pub fn len(&self) -> usize { | ||
100 | self.len | ||
101 | } | ||
102 | |||
103 | pub fn push(&mut self, c: char) { | ||
104 | assert!(self.len() < self.buf.len()); | ||
105 | assert!(c.is_ascii()); | ||
106 | |||
107 | self.buf[self.len] = c as u8; | ||
108 | self.len += 1; | ||
109 | } | ||
110 | } | ||
111 | |||
112 | impl<'a> Deref for MutAsciiString<'a> { | ||
113 | type Target = str; | ||
114 | fn deref(&self) -> &str { | ||
115 | self.as_str() | ||
116 | } | ||
117 | } | ||
diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs index a2509dc90..61cf83c84 100644 --- a/crates/ra_syntax/src/validation.rs +++ b/crates/ra_syntax/src/validation.rs | |||
@@ -1,11 +1,12 @@ | |||
1 | use std::u32; | 1 | use std::u32; |
2 | 2 | ||
3 | use arrayvec::ArrayString; | ||
4 | |||
3 | use crate::{ | 5 | use crate::{ |
4 | algo::visit::{visitor_ctx, VisitorCtx}, | 6 | algo::visit::{visitor_ctx, VisitorCtx}, |
5 | ast::{self, AstNode}, | 7 | ast::{self, AstNode}, |
6 | File, | 8 | File, |
7 | string_lexing::{self, CharComponentKind}, | 9 | string_lexing::{self, CharComponentKind}, |
8 | utils::MutAsciiString, | ||
9 | yellow::{ | 10 | yellow::{ |
10 | SyntaxError, | 11 | SyntaxError, |
11 | SyntaxErrorKind::*, | 12 | SyntaxErrorKind::*, |
@@ -76,8 +77,7 @@ fn validate_char(node: ast::Char, errors: &mut Vec<SyntaxError>) { | |||
76 | return; | 77 | return; |
77 | } | 78 | } |
78 | 79 | ||
79 | let mut buf = &mut [0; 6]; | 80 | let mut code = ArrayString::<[_; 6]>::new(); |
80 | let mut code = MutAsciiString::new(buf); | ||
81 | let mut closed = false; | 81 | let mut closed = false; |
82 | for c in text[3..].chars() { | 82 | for c in text[3..].chars() { |
83 | assert!(!closed, "no characters after escape is closed"); | 83 | assert!(!closed, "no characters after escape is closed"); |