aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast
diff options
context:
space:
mode:
authorAdolfo OchagavĂ­a <[email protected]>2018-11-11 19:27:00 +0000
committerAdolfo OchagavĂ­a <[email protected]>2018-11-11 19:27:00 +0000
commitc258b4fdb0e421813330c2428985c4537c787582 (patch)
treee53263f28c0cd07911a1e9c9ef6538c8ff0227fd /crates/ra_syntax/src/ast
parenta4f7d7a7cd85a5b9b64a935dd84ad493b6860236 (diff)
Add validator for byte
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs37
-rw-r--r--crates/ra_syntax/src/ast/mod.rs6
2 files changed, 43 insertions, 0 deletions
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<R: TreeRoot<RaTypes>> BreakExprNode<R> {
372 372
373impl<'a> BreakExpr<'a> {} 373impl<'a> BreakExpr<'a> {}
374 374
375// Byte
376#[derive(Debug, Clone, Copy,)]
377pub struct ByteNode<R: TreeRoot<RaTypes> = OwnedRoot> {
378 pub(crate) syntax: SyntaxNode<R>,
379}
380pub type Byte<'a> = ByteNode<RefRoot<'a>>;
381
382impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ByteNode<R1>> for ByteNode<R2> {
383 fn eq(&self, other: &ByteNode<R1>) -> bool { self.syntax == other.syntax }
384}
385impl<R: TreeRoot<RaTypes>> Eq for ByteNode<R> {}
386impl<R: TreeRoot<RaTypes>> Hash for ByteNode<R> {
387 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
388}
389
390impl<'a> AstNode<'a> for Byte<'a> {
391 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
392 match syntax.kind() {
393 BYTE => Some(Byte { syntax }),
394 _ => None,
395 }
396 }
397 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
398}
399
400impl<R: TreeRoot<RaTypes>> ByteNode<R> {
401 pub fn borrowed(&self) -> Byte {
402 ByteNode { syntax: self.syntax.borrowed() }
403 }
404 pub fn owned(&self) -> ByteNode {
405 ByteNode { syntax: self.syntax.owned() }
406 }
407}
408
409
410impl<'a> Byte<'a> {}
411
375// CallExpr 412// CallExpr
376#[derive(Debug, Clone, Copy,)] 413#[derive(Debug, Clone, Copy,)]
377pub struct CallExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { 414pub struct CallExprNode<R: TreeRoot<RaTypes> = 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> {
134 } 134 }
135} 135}
136 136
137impl<'a> Byte<'a> {
138 pub fn text(&self) -> &SmolStr {
139 &self.syntax().leaf_text().unwrap()
140 }
141}
142
137impl<'a> String<'a> { 143impl<'a> String<'a> {
138 pub fn text(&self) -> &SmolStr { 144 pub fn text(&self) -> &SmolStr {
139 &self.syntax().leaf_text().unwrap() 145 &self.syntax().leaf_text().unwrap()