From 9b5bbab104d8ba445143f6f3a9e4149b40c29ae5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Ochagav=C3=ADa?= Date: Sun, 4 Nov 2018 15:06:38 +0100 Subject: Add character literal parsing and validation --- crates/ra_syntax/src/ast/generated.rs | 34 ++++++++++++++++++++++++++++++++++ crates/ra_syntax/src/ast/mod.rs | 6 ++++++ 2 files changed, 40 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 f77795d05..75769a4e9 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -409,6 +409,40 @@ impl<'a> AstNode<'a> for CastExpr<'a> { impl<'a> CastExpr<'a> {} +// Char + +#[derive(Debug, Clone)] +pub struct CharNode(SyntaxNode); + +impl CharNode { + pub fn ast(&self) -> Char { + Char::cast(self.0.borrowed()).unwrap() + } +} + +impl<'a> From> for CharNode { + fn from(ast: Char<'a>) -> CharNode { + let syntax = ast.syntax().owned(); + CharNode(syntax) + } +} +#[derive(Debug, Clone, Copy)] +pub struct Char<'a> { + syntax: SyntaxNodeRef<'a>, +} + +impl<'a> AstNode<'a> for Char<'a> { + fn cast(syntax: SyntaxNodeRef<'a>) -> Option { + match syntax.kind() { + CHAR => Some(Char { syntax }), + _ => None, + } + } + fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } +} + +impl<'a> Char<'a> {} + // Comment #[derive(Debug, Clone)] diff --git a/crates/ra_syntax/src/ast/mod.rs b/crates/ra_syntax/src/ast/mod.rs index 688ffff47..4355531d0 100644 --- a/crates/ra_syntax/src/ast/mod.rs +++ b/crates/ra_syntax/src/ast/mod.rs @@ -123,6 +123,12 @@ impl<'a> Lifetime<'a> { } } +impl<'a> Char<'a> { + pub fn text(&self) -> &SmolStr { + &self.syntax().leaf_text().unwrap() + } +} + impl<'a> Comment<'a> { pub fn text(&self) -> &SmolStr { self.syntax().leaf_text().unwrap() -- cgit v1.2.3