From 2ed1514df3f8837ccebdbbfdadbe89e79b4a4365 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 7 Nov 2018 18:38:43 +0300 Subject: rename ROOT -> SOURCE_FILE --- crates/ra_syntax/src/ast/generated.rs | 86 +++++++++++++------------- crates/ra_syntax/src/grammar.ron | 4 +- crates/ra_syntax/src/grammar/mod.rs | 2 +- crates/ra_syntax/src/lib.rs | 11 ++-- crates/ra_syntax/src/parser_impl/event.rs | 2 +- crates/ra_syntax/src/syntax_kinds/generated.rs | 4 +- 6 files changed, 54 insertions(+), 55 deletions(-) (limited to 'crates/ra_syntax/src') 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> ReturnExprNode { impl<'a> ReturnExpr<'a> {} -// Root -#[derive(Debug, Clone, Copy,)] -pub struct RootNode = OwnedRoot> { - pub(crate) syntax: SyntaxNode, -} -pub type Root<'a> = RootNode>; - -impl, R2: TreeRoot> PartialEq> for RootNode { - fn eq(&self, other: &RootNode) -> bool { self.syntax == other.syntax } -} -impl> Eq for RootNode {} -impl> Hash for RootNode { - fn hash(&self, state: &mut H) { self.syntax.hash(state) } -} - -impl<'a> AstNode<'a> for Root<'a> { - fn cast(syntax: SyntaxNodeRef<'a>) -> Option { - match syntax.kind() { - ROOT => Some(Root { syntax }), - _ => None, - } - } - fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } -} - -impl> RootNode { - pub fn borrowed(&self) -> Root { - RootNode { syntax: self.syntax.borrowed() } - } - pub fn owned(&self) -> RootNode { - RootNode { syntax: self.syntax.owned() } - } -} - - -impl<'a> ast::ModuleItemOwner<'a> for Root<'a> {} -impl<'a> ast::FnDefOwner<'a> for Root<'a> {} -impl<'a> Root<'a> { - pub fn modules(self) -> impl Iterator> + 'a { - super::children(self) - } -} - // SelfParam #[derive(Debug, Clone, Copy,)] pub struct SelfParamNode = OwnedRoot> { @@ -3170,6 +3127,49 @@ impl> SliceTypeNode { impl<'a> SliceType<'a> {} +// SourceFile +#[derive(Debug, Clone, Copy,)] +pub struct SourceFileNode = OwnedRoot> { + pub(crate) syntax: SyntaxNode, +} +pub type SourceFile<'a> = SourceFileNode>; + +impl, R2: TreeRoot> PartialEq> for SourceFileNode { + fn eq(&self, other: &SourceFileNode) -> bool { self.syntax == other.syntax } +} +impl> Eq for SourceFileNode {} +impl> Hash for SourceFileNode { + fn hash(&self, state: &mut H) { self.syntax.hash(state) } +} + +impl<'a> AstNode<'a> for SourceFile<'a> { + fn cast(syntax: SyntaxNodeRef<'a>) -> Option { + match syntax.kind() { + SOURCE_FILE => Some(SourceFile { syntax }), + _ => None, + } + } + fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } +} + +impl> SourceFileNode { + pub fn borrowed(&self) -> SourceFile { + SourceFileNode { syntax: self.syntax.borrowed() } + } + pub fn owned(&self) -> SourceFileNode { + SourceFileNode { syntax: self.syntax.owned() } + } +} + + +impl<'a> ast::ModuleItemOwner<'a> for SourceFile<'a> {} +impl<'a> ast::FnDefOwner<'a> for SourceFile<'a> {} +impl<'a> SourceFile<'a> { + pub fn modules(self) -> impl Iterator> + 'a { + super::children(self) + } +} + // StaticDef #[derive(Debug, Clone, Copy,)] pub struct StaticDefNode = 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( "SHEBANG", ], nodes: [ - "ROOT", + "SOURCE_FILE", "STRUCT_DEF", "ENUM_DEF", @@ -239,7 +239,7 @@ Grammar( "ARG_LIST", ], ast: { - "Root": ( + "SourceFile": ( traits: [ "ModuleItemOwner", "FnDefOwner" ], collections: [ ["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) { let m = p.start(); p.eat(SHEBANG); items::mod_contents(p, false); - m.complete(p, ROOT); + m.complete(p, SOURCE_FILE); } #[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::{ use crate::yellow::GreenNode; -// TODO: pick a single name for everything. SourceFileNode maybe? -/// File represents a parse tree for a single Rust file. -pub type SourceFileNode = ast::RootNode; +/// `SourceFileNode` represents a parse tree for a single Rust file. +pub use crate::ast::SourceFileNode; impl SourceFileNode { fn new(green: GreenNode, errors: Vec) -> SourceFileNode { @@ -71,8 +70,8 @@ impl SourceFileNode { if cfg!(debug_assertions) { utils::validate_block_structure(root.borrowed()); } - assert_eq!(root.kind(), SyntaxKind::ROOT); - ast::RootNode { syntax: root } + assert_eq!(root.kind(), SyntaxKind::SOURCE_FILE); + ast::SourceFileNode { syntax: root } } pub fn parse(text: &str) -> SourceFileNode { let tokens = tokenize(&text); @@ -94,7 +93,7 @@ impl SourceFileNode { SourceFileNode::parse(&text) } /// Typed AST representation of the parse tree. - pub fn ast(&self) -> ast::Root { + pub fn ast(&self) -> ast::SourceFile { self.borrowed() } /// 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> { } fn start(&mut self, kind: SyntaxKind) { - if kind == ROOT { + if kind == SOURCE_FILE { self.sink.start_internal(kind); return; } 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 { RAW_BYTE_STRING, COMMENT, SHEBANG, - ROOT, + SOURCE_FILE, STRUCT_DEF, ENUM_DEF, FN_DEF, @@ -378,7 +378,7 @@ impl SyntaxKind { RAW_BYTE_STRING => &SyntaxInfo { name: "RAW_BYTE_STRING" }, COMMENT => &SyntaxInfo { name: "COMMENT" }, SHEBANG => &SyntaxInfo { name: "SHEBANG" }, - ROOT => &SyntaxInfo { name: "ROOT" }, + SOURCE_FILE => &SyntaxInfo { name: "SOURCE_FILE" }, STRUCT_DEF => &SyntaxInfo { name: "STRUCT_DEF" }, ENUM_DEF => &SyntaxInfo { name: "ENUM_DEF" }, FN_DEF => &SyntaxInfo { name: "FN_DEF" }, -- cgit v1.2.3