From 415c891d641fa305e7ddbbbcc78db990dd5d3564 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 29 Jul 2018 15:16:07 +0300 Subject: Reorganize --- src/lib.rs | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 619ad62e5..4260e22e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,27 +19,36 @@ extern crate unicode_xid; extern crate text_unit; -mod tree; mod lexer; mod parser; mod yellow; +mod syntax_kinds; + +pub use { + text_unit::{TextRange, TextUnit}, + syntax_kinds::SyntaxKind, + yellow::{SyntaxNode}, + lexer::{tokenize, Token}, +}; + +pub(crate) use { + yellow::SyntaxError +}; + +pub fn parse(text: String) -> SyntaxNode { + let tokens = tokenize(&text); + parser::parse::(text, &tokens) +} -pub mod syntax_kinds; -pub use text_unit::{TextRange, TextUnit}; -pub use tree::{SyntaxKind, Token}; -pub(crate) use tree::{Sink, GreenBuilder}; -pub use lexer::{next_token, tokenize}; -pub use yellow::SyntaxNode; -pub(crate) use yellow::SError; -pub use parser::{parse_green}; /// Utilities for simple uses of the parser. pub mod utils { - use std::fmt::Write; + use std::{ + fmt::Write, + collections::BTreeSet + }; - use {SyntaxNode}; - use std::collections::BTreeSet; - use SError; + use {SyntaxNode, SyntaxError}; /// Parse a file and create a string representation of the resulting parse tree. pub fn dump_tree_green(syntax: &SyntaxNode) -> String { @@ -48,7 +57,7 @@ pub mod utils { go(syntax, &mut result, 0, &mut errors); return result; - fn go(node: &SyntaxNode, buff: &mut String, level: usize, errors: &mut BTreeSet) { + fn go(node: &SyntaxNode, buff: &mut String, level: usize, errors: &mut BTreeSet) { buff.push_str(&String::from(" ").repeat(level)); write!(buff, "{:?}\n", node).unwrap(); let my_errors: Vec<_> = errors.iter().filter(|e| e.offset == node.range().start()) -- cgit v1.2.3