From c258b4fdb0e421813330c2428985c4537c787582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Ochagav=C3=ADa?= Date: Sun, 11 Nov 2018 20:27:00 +0100 Subject: Add validator for byte --- 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 2e9ae263a..75236153d 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -372,6 +372,43 @@ impl> BreakExprNode { impl<'a> BreakExpr<'a> {} +// Byte +#[derive(Debug, Clone, Copy,)] +pub struct ByteNode = OwnedRoot> { + pub(crate) syntax: SyntaxNode, +} +pub type Byte<'a> = ByteNode>; + +impl, R2: TreeRoot> PartialEq> for ByteNode { + fn eq(&self, other: &ByteNode) -> bool { self.syntax == other.syntax } +} +impl> Eq for ByteNode {} +impl> Hash for ByteNode { + fn hash(&self, state: &mut H) { self.syntax.hash(state) } +} + +impl<'a> AstNode<'a> for Byte<'a> { + fn cast(syntax: SyntaxNodeRef<'a>) -> Option { + match syntax.kind() { + BYTE => Some(Byte { syntax }), + _ => None, + } + } + fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } +} + +impl> ByteNode { + pub fn borrowed(&self) -> Byte { + ByteNode { syntax: self.syntax.borrowed() } + } + pub fn owned(&self) -> ByteNode { + ByteNode { syntax: self.syntax.owned() } + } +} + + +impl<'a> Byte<'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 f20714ede..686b5cf04 100644 --- a/crates/ra_syntax/src/ast/mod.rs +++ b/crates/ra_syntax/src/ast/mod.rs @@ -134,6 +134,12 @@ impl<'a> Char<'a> { } } +impl<'a> Byte<'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