aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-27 08:01:31 +0100
committerAleksey Kladov <[email protected]>2018-08-27 08:01:31 +0100
commit8b0298ce095b6dd635f7ed35dc97f1874157040b (patch)
tree3d6f941f7612ba1800c1e2f9fbb0a94761999be7 /crates/libsyntax2/src
parent9b69c7df194d5f9081698745ed20414d7c7c2f1c (diff)
scopes
Diffstat (limited to 'crates/libsyntax2/src')
-rw-r--r--crates/libsyntax2/src/algo/mod.rs2
-rw-r--r--crates/libsyntax2/src/ast/generated.rs26
-rw-r--r--crates/libsyntax2/src/grammar.ron9
-rw-r--r--crates/libsyntax2/src/yellow/mod.rs2
-rw-r--r--crates/libsyntax2/src/yellow/syntax.rs10
5 files changed, 44 insertions, 5 deletions
diff --git a/crates/libsyntax2/src/algo/mod.rs b/crates/libsyntax2/src/algo/mod.rs
index 2640d60ea..7287f5bb2 100644
--- a/crates/libsyntax2/src/algo/mod.rs
+++ b/crates/libsyntax2/src/algo/mod.rs
@@ -119,7 +119,7 @@ fn common_ancestor<'a>(n1: SyntaxNodeRef<'a>, n2: SyntaxNodeRef<'a>) -> SyntaxNo
119 panic!("Can't find common ancestor of {:?} and {:?}", n1, n2) 119 panic!("Can't find common ancestor of {:?} and {:?}", n1, n2)
120} 120}
121 121
122fn generate<T>(seed: Option<T>, step: impl Fn(&T) -> Option<T>) -> impl Iterator<Item=T> { 122pub fn generate<T>(seed: Option<T>, step: impl Fn(&T) -> Option<T>) -> impl Iterator<Item=T> {
123 ::itertools::unfold(seed, move |slot| { 123 ::itertools::unfold(seed, move |slot| {
124 slot.take().map(|curr| { 124 slot.take().map(|curr| {
125 *slot = step(&curr); 125 *slot = step(&curr);
diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs
index 6926c0535..b937fe5a2 100644
--- a/crates/libsyntax2/src/ast/generated.rs
+++ b/crates/libsyntax2/src/ast/generated.rs
@@ -383,6 +383,24 @@ impl<'a> AstNode<'a> for Expr<'a> {
383 383
384impl<'a> Expr<'a> {} 384impl<'a> Expr<'a> {}
385 385
386// ExprStmt
387#[derive(Debug, Clone, Copy)]
388pub struct ExprStmt<'a> {
389 syntax: SyntaxNodeRef<'a>,
390}
391
392impl<'a> AstNode<'a> for ExprStmt<'a> {
393 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
394 match syntax.kind() {
395 EXPR_STMT => Some(ExprStmt { syntax }),
396 _ => None,
397 }
398 }
399 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
400}
401
402impl<'a> ExprStmt<'a> {}
403
386// FieldExpr 404// FieldExpr
387#[derive(Debug, Clone, Copy)] 405#[derive(Debug, Clone, Copy)]
388pub struct FieldExpr<'a> { 406pub struct FieldExpr<'a> {
@@ -442,6 +460,10 @@ impl<'a> FnDef<'a> {
442 pub fn param_list(self) -> Option<ParamList<'a>> { 460 pub fn param_list(self) -> Option<ParamList<'a>> {
443 super::child_opt(self) 461 super::child_opt(self)
444 } 462 }
463
464 pub fn body(self) -> Option<Block<'a>> {
465 super::child_opt(self)
466 }
445} 467}
446 468
447// FnPointerType 469// FnPointerType
@@ -626,6 +648,10 @@ impl<'a> LetStmt<'a> {
626 pub fn pat(self) -> Option<Pat<'a>> { 648 pub fn pat(self) -> Option<Pat<'a>> {
627 super::child_opt(self) 649 super::child_opt(self)
628 } 650 }
651
652 pub fn initializer(self) -> Option<Expr<'a>> {
653 super::child_opt(self)
654 }
629} 655}
630 656
631// LoopExpr 657// LoopExpr
diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron
index 3a125ace6..aa2742b3e 100644
--- a/crates/libsyntax2/src/grammar.ron
+++ b/crates/libsyntax2/src/grammar.ron
@@ -248,7 +248,8 @@ Grammar(
248 "AttrsOwner", 248 "AttrsOwner",
249 ], 249 ],
250 options: [ 250 options: [
251 ["param_list", "ParamList"] 251 ["param_list", "ParamList"],
252 ["body", "Block"],
252 ], 253 ],
253 ), 254 ),
254 "StructDef": ( 255 "StructDef": (
@@ -431,7 +432,11 @@ Grammar(
431 "TypeParamList": ( collections: [ ["type_params", "TypeParam" ] ]), 432 "TypeParamList": ( collections: [ ["type_params", "TypeParam" ] ]),
432 "TypeParam": ( traits: ["NameOwner"] ), 433 "TypeParam": ( traits: ["NameOwner"] ),
433 "WhereClause": (), 434 "WhereClause": (),
434 "LetStmt": ( options: [ ["pat", "Pat"] ]), 435 "ExprStmt": (),
436 "LetStmt": ( options: [
437 ["pat", "Pat"],
438 ["initializer", "Expr"],
439 ]),
435 "Block": ( 440 "Block": (
436 collections: [ 441 collections: [
437 ["let_stmts", "LetStmt"], 442 ["let_stmts", "LetStmt"],
diff --git a/crates/libsyntax2/src/yellow/mod.rs b/crates/libsyntax2/src/yellow/mod.rs
index 3c4510fe7..b94c794fe 100644
--- a/crates/libsyntax2/src/yellow/mod.rs
+++ b/crates/libsyntax2/src/yellow/mod.rs
@@ -66,7 +66,7 @@ impl SyntaxRoot {
66 } 66 }
67} 67}
68 68
69#[derive(Clone, Copy, PartialEq, Eq, Debug)] 69#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
70pub(crate) struct RedPtr(ptr::NonNull<RedNode>); 70pub(crate) struct RedPtr(ptr::NonNull<RedNode>);
71 71
72unsafe impl Send for RedPtr {} 72unsafe impl Send for RedPtr {}
diff --git a/crates/libsyntax2/src/yellow/syntax.rs b/crates/libsyntax2/src/yellow/syntax.rs
index 0045598d4..75b6cb7dc 100644
--- a/crates/libsyntax2/src/yellow/syntax.rs
+++ b/crates/libsyntax2/src/yellow/syntax.rs
@@ -1,4 +1,7 @@
1use std::{fmt, sync::Arc}; 1use std::{
2 fmt, sync::Arc,
3 hash::{Hasher, Hash},
4};
2 5
3use smol_str::SmolStr; 6use smol_str::SmolStr;
4 7
@@ -27,6 +30,11 @@ impl<R1: TreeRoot, R2: TreeRoot> PartialEq<SyntaxNode<R1>> for SyntaxNode<R2> {
27} 30}
28 31
29impl<R: TreeRoot> Eq for SyntaxNode<R> {} 32impl<R: TreeRoot> Eq for SyntaxNode<R> {}
33impl<R: TreeRoot> Hash for SyntaxNode<R> {
34 fn hash<H: Hasher>(&self, state: &mut H) {
35 self.red.hash(state)
36 }
37}
30 38
31pub type SyntaxNodeRef<'a> = SyntaxNode<RefRoot<'a>>; 39pub type SyntaxNodeRef<'a> = SyntaxNode<RefRoot<'a>>;
32 40