From 30cd4d5acb7dfd40cea264a926d1c89f0c3522c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Ochagav=C3=ADa?= Date: Sun, 11 Nov 2018 20:41:43 +0100 Subject: Validate byte string literals --- crates/ra_syntax/src/ast/generated.rs | 37 +++++++++++++++++++++++++++++++++++ crates/ra_syntax/src/ast/mod.rs | 6 ++++++ 2 files changed, 43 insertions(+) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 75236153d..bf056131e 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -409,6 +409,43 @@ impl> ByteNode { impl<'a> Byte<'a> {} +// ByteString +#[derive(Debug, Clone, Copy,)] +pub struct ByteStringNode = OwnedRoot> { + pub(crate) syntax: SyntaxNode, +} +pub type ByteString<'a> = ByteStringNode>; + +impl, R2: TreeRoot> PartialEq> for ByteStringNode { + fn eq(&self, other: &ByteStringNode) -> bool { self.syntax == other.syntax } +} +impl> Eq for ByteStringNode {} +impl> Hash for ByteStringNode { + fn hash(&self, state: &mut H) { self.syntax.hash(state) } +} + +impl<'a> AstNode<'a> for ByteString<'a> { + fn cast(syntax: SyntaxNodeRef<'a>) -> Option { + match syntax.kind() { + BYTE_STRING => Some(ByteString { syntax }), + _ => None, + } + } + fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } +} + +impl> ByteStringNode { + pub fn borrowed(&self) -> ByteString { + ByteStringNode { syntax: self.syntax.borrowed() } + } + pub fn owned(&self) -> ByteStringNode { + ByteStringNode { syntax: self.syntax.owned() } + } +} + + +impl<'a> ByteString<'a> {} + // CallExpr #[derive(Debug, Clone, Copy,)] pub struct CallExprNode = OwnedRoot> { diff --git a/crates/ra_syntax/src/ast/mod.rs b/crates/ra_syntax/src/ast/mod.rs index 686b5cf04..7077e3492 100644 --- a/crates/ra_syntax/src/ast/mod.rs +++ b/crates/ra_syntax/src/ast/mod.rs @@ -140,6 +140,12 @@ impl<'a> Byte<'a> { } } +impl<'a> ByteString<'a> { + pub fn text(&self) -> &SmolStr { + &self.syntax().leaf_text().unwrap() + } +} + impl<'a> String<'a> { pub fn text(&self) -> &SmolStr { &self.syntax().leaf_text().unwrap() -- cgit v1.2.3