Skip to content

Document the design of FileBuilder #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ mod parser;
#[allow(missing_docs)]
pub mod syntax_kinds;
pub use text::{TextRange, TextUnit};
pub use tree::{File, FileBuilder, Node, Sink, SyntaxKind, Token};
pub use tree::{File, Node, SyntaxKind, Token};
pub(crate) use tree::{FileBuilder, Sink};
pub use lexer::{next_token, tokenize};
pub use parser::parse;

Expand Down
16 changes: 11 additions & 5 deletions src/tree/file_builder.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
// FIXME(CAD97): I don't understand this mod well enough to stub out docs for the public symbols yet
#![allow(missing_docs)]

//! This module provides a way to construct a `File`.
//! It is intended to be completely decoupled from the
//! parser, so as to allow to evolve the tree representation
//! and the parser algorithm independently.
//!
//! The `Sink` trait is the bridge between the parser and the
//! tree builder: the parser produces a stream of events like
//! `start node`, `finish node`, and `FileBuilder` converts
//! this stream to a real tree.
use {SyntaxKind, TextRange, TextUnit};
use super::{File, NodeData, NodeIdx, SyntaxErrorData};

pub trait Sink {
pub(crate) trait Sink {
fn leaf(&mut self, kind: SyntaxKind, len: TextUnit);
fn start_internal(&mut self, kind: SyntaxKind);
fn finish_internal(&mut self);
fn error(&mut self) -> ErrorBuilder;
}

#[derive(Debug)]
pub struct FileBuilder {
pub(crate) struct FileBuilder {
text: String,
nodes: Vec<NodeData>,
errors: Vec<SyntaxErrorData>,
Expand Down
2 changes: 1 addition & 1 deletion src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::fmt;
use std::cmp;

mod file_builder;
pub use self::file_builder::{FileBuilder, Sink};
pub(crate) use self::file_builder::{FileBuilder, Sink};

/// The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT_DEF`.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
Expand Down