diff options
author | Aleksey Kladov <[email protected]> | 2018-11-07 15:38:43 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-11-07 15:42:36 +0000 |
commit | 2ed1514df3f8837ccebdbbfdadbe89e79b4a4365 (patch) | |
tree | 82af1d514d9865db4e2cc163a7ffa601a7c294db /crates/ra_syntax/src | |
parent | f8b36bbc3b968754b71844d942286e81415627b8 (diff) |
rename ROOT -> SOURCE_FILE
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 86 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar.ron | 4 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar/mod.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/lib.rs | 11 | ||||
-rw-r--r-- | crates/ra_syntax/src/parser_impl/event.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/syntax_kinds/generated.rs | 4 |
6 files changed, 54 insertions, 55 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 8cf3222f7..5b5f71ee7 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -3016,49 +3016,6 @@ impl<R: TreeRoot<RaTypes>> ReturnExprNode<R> { | |||
3016 | 3016 | ||
3017 | impl<'a> ReturnExpr<'a> {} | 3017 | impl<'a> ReturnExpr<'a> {} |
3018 | 3018 | ||
3019 | // Root | ||
3020 | #[derive(Debug, Clone, Copy,)] | ||
3021 | pub struct RootNode<R: TreeRoot<RaTypes> = OwnedRoot> { | ||
3022 | pub(crate) syntax: SyntaxNode<R>, | ||
3023 | } | ||
3024 | pub type Root<'a> = RootNode<RefRoot<'a>>; | ||
3025 | |||
3026 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<RootNode<R1>> for RootNode<R2> { | ||
3027 | fn eq(&self, other: &RootNode<R1>) -> bool { self.syntax == other.syntax } | ||
3028 | } | ||
3029 | impl<R: TreeRoot<RaTypes>> Eq for RootNode<R> {} | ||
3030 | impl<R: TreeRoot<RaTypes>> Hash for RootNode<R> { | ||
3031 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3032 | } | ||
3033 | |||
3034 | impl<'a> AstNode<'a> for Root<'a> { | ||
3035 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | ||
3036 | match syntax.kind() { | ||
3037 | ROOT => Some(Root { syntax }), | ||
3038 | _ => None, | ||
3039 | } | ||
3040 | } | ||
3041 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | ||
3042 | } | ||
3043 | |||
3044 | impl<R: TreeRoot<RaTypes>> RootNode<R> { | ||
3045 | pub fn borrowed(&self) -> Root { | ||
3046 | RootNode { syntax: self.syntax.borrowed() } | ||
3047 | } | ||
3048 | pub fn owned(&self) -> RootNode { | ||
3049 | RootNode { syntax: self.syntax.owned() } | ||
3050 | } | ||
3051 | } | ||
3052 | |||
3053 | |||
3054 | impl<'a> ast::ModuleItemOwner<'a> for Root<'a> {} | ||
3055 | impl<'a> ast::FnDefOwner<'a> for Root<'a> {} | ||
3056 | impl<'a> Root<'a> { | ||
3057 | pub fn modules(self) -> impl Iterator<Item = Module<'a>> + 'a { | ||
3058 | super::children(self) | ||
3059 | } | ||
3060 | } | ||
3061 | |||
3062 | // SelfParam | 3019 | // SelfParam |
3063 | #[derive(Debug, Clone, Copy,)] | 3020 | #[derive(Debug, Clone, Copy,)] |
3064 | pub struct SelfParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3021 | pub struct SelfParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
@@ -3170,6 +3127,49 @@ impl<R: TreeRoot<RaTypes>> SliceTypeNode<R> { | |||
3170 | 3127 | ||
3171 | impl<'a> SliceType<'a> {} | 3128 | impl<'a> SliceType<'a> {} |
3172 | 3129 | ||
3130 | // SourceFile | ||
3131 | #[derive(Debug, Clone, Copy,)] | ||
3132 | pub struct SourceFileNode<R: TreeRoot<RaTypes> = OwnedRoot> { | ||
3133 | pub(crate) syntax: SyntaxNode<R>, | ||
3134 | } | ||
3135 | pub type SourceFile<'a> = SourceFileNode<RefRoot<'a>>; | ||
3136 | |||
3137 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<SourceFileNode<R1>> for SourceFileNode<R2> { | ||
3138 | fn eq(&self, other: &SourceFileNode<R1>) -> bool { self.syntax == other.syntax } | ||
3139 | } | ||
3140 | impl<R: TreeRoot<RaTypes>> Eq for SourceFileNode<R> {} | ||
3141 | impl<R: TreeRoot<RaTypes>> Hash for SourceFileNode<R> { | ||
3142 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3143 | } | ||
3144 | |||
3145 | impl<'a> AstNode<'a> for SourceFile<'a> { | ||
3146 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | ||
3147 | match syntax.kind() { | ||
3148 | SOURCE_FILE => Some(SourceFile { syntax }), | ||
3149 | _ => None, | ||
3150 | } | ||
3151 | } | ||
3152 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | ||
3153 | } | ||
3154 | |||
3155 | impl<R: TreeRoot<RaTypes>> SourceFileNode<R> { | ||
3156 | pub fn borrowed(&self) -> SourceFile { | ||
3157 | SourceFileNode { syntax: self.syntax.borrowed() } | ||
3158 | } | ||
3159 | pub fn owned(&self) -> SourceFileNode { | ||
3160 | SourceFileNode { syntax: self.syntax.owned() } | ||
3161 | } | ||
3162 | } | ||
3163 | |||
3164 | |||
3165 | impl<'a> ast::ModuleItemOwner<'a> for SourceFile<'a> {} | ||
3166 | impl<'a> ast::FnDefOwner<'a> for SourceFile<'a> {} | ||
3167 | impl<'a> SourceFile<'a> { | ||
3168 | pub fn modules(self) -> impl Iterator<Item = Module<'a>> + 'a { | ||
3169 | super::children(self) | ||
3170 | } | ||
3171 | } | ||
3172 | |||
3173 | // StaticDef | 3173 | // StaticDef |
3174 | #[derive(Debug, Clone, Copy,)] | 3174 | #[derive(Debug, Clone, Copy,)] |
3175 | pub struct StaticDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3175 | pub struct StaticDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index 1fa25dc4d..a92844415 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron | |||
@@ -116,7 +116,7 @@ Grammar( | |||
116 | "SHEBANG", | 116 | "SHEBANG", |
117 | ], | 117 | ], |
118 | nodes: [ | 118 | nodes: [ |
119 | "ROOT", | 119 | "SOURCE_FILE", |
120 | 120 | ||
121 | "STRUCT_DEF", | 121 | "STRUCT_DEF", |
122 | "ENUM_DEF", | 122 | "ENUM_DEF", |
@@ -239,7 +239,7 @@ Grammar( | |||
239 | "ARG_LIST", | 239 | "ARG_LIST", |
240 | ], | 240 | ], |
241 | ast: { | 241 | ast: { |
242 | "Root": ( | 242 | "SourceFile": ( |
243 | traits: [ "ModuleItemOwner", "FnDefOwner" ], | 243 | traits: [ "ModuleItemOwner", "FnDefOwner" ], |
244 | collections: [ | 244 | collections: [ |
245 | ["modules", "Module"], | 245 | ["modules", "Module"], |
diff --git a/crates/ra_syntax/src/grammar/mod.rs b/crates/ra_syntax/src/grammar/mod.rs index 95c437983..06a37d648 100644 --- a/crates/ra_syntax/src/grammar/mod.rs +++ b/crates/ra_syntax/src/grammar/mod.rs | |||
@@ -53,7 +53,7 @@ pub(crate) fn root(p: &mut Parser) { | |||
53 | let m = p.start(); | 53 | let m = p.start(); |
54 | p.eat(SHEBANG); | 54 | p.eat(SHEBANG); |
55 | items::mod_contents(p, false); | 55 | items::mod_contents(p, false); |
56 | m.complete(p, ROOT); | 56 | m.complete(p, SOURCE_FILE); |
57 | } | 57 | } |
58 | 58 | ||
59 | #[derive(Clone, Copy, PartialEq, Eq)] | 59 | #[derive(Clone, Copy, PartialEq, Eq)] |
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 9f8066c70..330f68053 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs | |||
@@ -61,9 +61,8 @@ pub use crate::{ | |||
61 | 61 | ||
62 | use crate::yellow::GreenNode; | 62 | use crate::yellow::GreenNode; |
63 | 63 | ||
64 | // TODO: pick a single name for everything. SourceFileNode maybe? | 64 | /// `SourceFileNode` represents a parse tree for a single Rust file. |
65 | /// File represents a parse tree for a single Rust file. | 65 | pub use crate::ast::SourceFileNode; |
66 | pub type SourceFileNode = ast::RootNode; | ||
67 | 66 | ||
68 | impl SourceFileNode { | 67 | impl SourceFileNode { |
69 | fn new(green: GreenNode, errors: Vec<SyntaxError>) -> SourceFileNode { | 68 | fn new(green: GreenNode, errors: Vec<SyntaxError>) -> SourceFileNode { |
@@ -71,8 +70,8 @@ impl SourceFileNode { | |||
71 | if cfg!(debug_assertions) { | 70 | if cfg!(debug_assertions) { |
72 | utils::validate_block_structure(root.borrowed()); | 71 | utils::validate_block_structure(root.borrowed()); |
73 | } | 72 | } |
74 | assert_eq!(root.kind(), SyntaxKind::ROOT); | 73 | assert_eq!(root.kind(), SyntaxKind::SOURCE_FILE); |
75 | ast::RootNode { syntax: root } | 74 | ast::SourceFileNode { syntax: root } |
76 | } | 75 | } |
77 | pub fn parse(text: &str) -> SourceFileNode { | 76 | pub fn parse(text: &str) -> SourceFileNode { |
78 | let tokens = tokenize(&text); | 77 | let tokens = tokenize(&text); |
@@ -94,7 +93,7 @@ impl SourceFileNode { | |||
94 | SourceFileNode::parse(&text) | 93 | SourceFileNode::parse(&text) |
95 | } | 94 | } |
96 | /// Typed AST representation of the parse tree. | 95 | /// Typed AST representation of the parse tree. |
97 | pub fn ast(&self) -> ast::Root { | 96 | pub fn ast(&self) -> ast::SourceFile { |
98 | self.borrowed() | 97 | self.borrowed() |
99 | } | 98 | } |
100 | /// Untyped homogeneous representation of the parse tree. | 99 | /// Untyped homogeneous representation of the parse tree. |
diff --git a/crates/ra_syntax/src/parser_impl/event.rs b/crates/ra_syntax/src/parser_impl/event.rs index bf9c1cef0..3d8b062d5 100644 --- a/crates/ra_syntax/src/parser_impl/event.rs +++ b/crates/ra_syntax/src/parser_impl/event.rs | |||
@@ -172,7 +172,7 @@ impl<'a, S: Sink> EventProcessor<'a, S> { | |||
172 | } | 172 | } |
173 | 173 | ||
174 | fn start(&mut self, kind: SyntaxKind) { | 174 | fn start(&mut self, kind: SyntaxKind) { |
175 | if kind == ROOT { | 175 | if kind == SOURCE_FILE { |
176 | self.sink.start_internal(kind); | 176 | self.sink.start_internal(kind); |
177 | return; | 177 | return; |
178 | } | 178 | } |
diff --git a/crates/ra_syntax/src/syntax_kinds/generated.rs b/crates/ra_syntax/src/syntax_kinds/generated.rs index 6568f1a37..c43a8bf65 100644 --- a/crates/ra_syntax/src/syntax_kinds/generated.rs +++ b/crates/ra_syntax/src/syntax_kinds/generated.rs | |||
@@ -117,7 +117,7 @@ pub enum SyntaxKind { | |||
117 | RAW_BYTE_STRING, | 117 | RAW_BYTE_STRING, |
118 | COMMENT, | 118 | COMMENT, |
119 | SHEBANG, | 119 | SHEBANG, |
120 | ROOT, | 120 | SOURCE_FILE, |
121 | STRUCT_DEF, | 121 | STRUCT_DEF, |
122 | ENUM_DEF, | 122 | ENUM_DEF, |
123 | FN_DEF, | 123 | FN_DEF, |
@@ -378,7 +378,7 @@ impl SyntaxKind { | |||
378 | RAW_BYTE_STRING => &SyntaxInfo { name: "RAW_BYTE_STRING" }, | 378 | RAW_BYTE_STRING => &SyntaxInfo { name: "RAW_BYTE_STRING" }, |
379 | COMMENT => &SyntaxInfo { name: "COMMENT" }, | 379 | COMMENT => &SyntaxInfo { name: "COMMENT" }, |
380 | SHEBANG => &SyntaxInfo { name: "SHEBANG" }, | 380 | SHEBANG => &SyntaxInfo { name: "SHEBANG" }, |
381 | ROOT => &SyntaxInfo { name: "ROOT" }, | 381 | SOURCE_FILE => &SyntaxInfo { name: "SOURCE_FILE" }, |
382 | STRUCT_DEF => &SyntaxInfo { name: "STRUCT_DEF" }, | 382 | STRUCT_DEF => &SyntaxInfo { name: "STRUCT_DEF" }, |
383 | ENUM_DEF => &SyntaxInfo { name: "ENUM_DEF" }, | 383 | ENUM_DEF => &SyntaxInfo { name: "ENUM_DEF" }, |
384 | FN_DEF => &SyntaxInfo { name: "FN_DEF" }, | 384 | FN_DEF => &SyntaxInfo { name: "FN_DEF" }, |