diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-01-28 08:18:47 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-01-28 08:18:47 +0000 |
commit | 092f9a6b98a1b0b4724888f7b24bac6f6c5c1b79 (patch) | |
tree | 9fe5ea35bcbda21c5fc1e059279ec885848634c0 /src | |
parent | aff82e5ee1d587b858e7237511e611bb8cc61cf3 (diff) | |
parent | 1417f26f820bd6428b528c3dc6127fabb084115a (diff) |
Merge #17
17: Document the design of `FileBuilder` r=matklad a=matklad
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 3 | ||||
-rw-r--r-- | src/tree/file_builder.rs | 16 | ||||
-rw-r--r-- | src/tree/mod.rs | 2 |
3 files changed, 14 insertions, 7 deletions
diff --git a/src/lib.rs b/src/lib.rs index ad333582c..0ea8f6a63 100644 --- a/src/lib.rs +++ b/src/lib.rs | |||
@@ -24,7 +24,8 @@ mod parser; | |||
24 | 24 | ||
25 | pub mod syntax_kinds; | 25 | pub mod syntax_kinds; |
26 | pub use text::{TextRange, TextUnit}; | 26 | pub use text::{TextRange, TextUnit}; |
27 | pub use tree::{File, FileBuilder, Node, Sink, SyntaxKind, Token}; | 27 | pub use tree::{File, Node, SyntaxKind, Token}; |
28 | pub(crate) use tree::{FileBuilder, Sink}; | ||
28 | pub use lexer::{next_token, tokenize}; | 29 | pub use lexer::{next_token, tokenize}; |
29 | pub use parser::parse; | 30 | pub use parser::parse; |
30 | 31 | ||
diff --git a/src/tree/file_builder.rs b/src/tree/file_builder.rs index 738705f02..47038496d 100644 --- a/src/tree/file_builder.rs +++ b/src/tree/file_builder.rs | |||
@@ -1,10 +1,16 @@ | |||
1 | // FIXME(CAD97): I don't understand this mod well enough to stub out docs for the public symbols yet | 1 | //! This module provides a way to construct a `File`. |
2 | #![allow(missing_docs)] | 2 | //! It is intended to be completely decoupled from the |
3 | 3 | //! parser, so as to allow to evolve the tree representation | |
4 | //! and the parser algorithm independently. | ||
5 | //! | ||
6 | //! The `Sink` trait is the bridge between the parser and the | ||
7 | //! tree builder: the parser produces a stream of events like | ||
8 | //! `start node`, `finish node`, and `FileBuilder` converts | ||
9 | //! this stream to a real tree. | ||
4 | use {SyntaxKind, TextRange, TextUnit}; | 10 | use {SyntaxKind, TextRange, TextUnit}; |
5 | use super::{File, NodeData, NodeIdx, SyntaxErrorData}; | 11 | use super::{File, NodeData, NodeIdx, SyntaxErrorData}; |
6 | 12 | ||
7 | pub trait Sink { | 13 | pub(crate) trait Sink { |
8 | fn leaf(&mut self, kind: SyntaxKind, len: TextUnit); | 14 | fn leaf(&mut self, kind: SyntaxKind, len: TextUnit); |
9 | fn start_internal(&mut self, kind: SyntaxKind); | 15 | fn start_internal(&mut self, kind: SyntaxKind); |
10 | fn finish_internal(&mut self); | 16 | fn finish_internal(&mut self); |
@@ -12,7 +18,7 @@ pub trait Sink { | |||
12 | } | 18 | } |
13 | 19 | ||
14 | #[derive(Debug)] | 20 | #[derive(Debug)] |
15 | pub struct FileBuilder { | 21 | pub(crate) struct FileBuilder { |
16 | text: String, | 22 | text: String, |
17 | nodes: Vec<NodeData>, | 23 | nodes: Vec<NodeData>, |
18 | errors: Vec<SyntaxErrorData>, | 24 | errors: Vec<SyntaxErrorData>, |
diff --git a/src/tree/mod.rs b/src/tree/mod.rs index 43bda480d..795f23f42 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs | |||
@@ -4,7 +4,7 @@ use std::fmt; | |||
4 | use std::cmp; | 4 | use std::cmp; |
5 | 5 | ||
6 | mod file_builder; | 6 | mod file_builder; |
7 | pub use self::file_builder::{FileBuilder, Sink}; | 7 | pub(crate) use self::file_builder::{FileBuilder, Sink}; |
8 | 8 | ||
9 | pub use syntax_kinds::SyntaxKind; | 9 | pub use syntax_kinds::SyntaxKind; |
10 | 10 | ||