2017-12-29 20:33:04 +00:00
|
|
|
extern crate unicode_xid;
|
|
|
|
|
2017-12-28 21:56:36 +00:00
|
|
|
mod text;
|
|
|
|
mod tree;
|
|
|
|
mod lexer;
|
2017-12-31 20:34:29 +00:00
|
|
|
mod parser;
|
2017-12-28 21:56:36 +00:00
|
|
|
|
|
|
|
pub mod syntax_kinds;
|
2017-12-31 14:54:33 +00:00
|
|
|
pub use text::{TextUnit, TextRange};
|
2017-12-31 21:13:56 +00:00
|
|
|
pub use tree::{SyntaxKind, Token, FileBuilder, Sink, File, Node};
|
2017-12-31 14:54:33 +00:00
|
|
|
pub use lexer::{next_token, tokenize};
|
2017-12-31 20:34:29 +00:00
|
|
|
pub use parser::parse;
|
2018-01-21 23:12:26 +00:00
|
|
|
|
|
|
|
pub mod utils {
|
|
|
|
use std::fmt::Write;
|
|
|
|
|
|
|
|
use {File, Node};
|
|
|
|
|
|
|
|
pub fn dump_tree(file: &File) -> String {
|
|
|
|
let mut result = String::new();
|
|
|
|
go(file.root(), &mut result, 0);
|
|
|
|
return result;
|
|
|
|
|
|
|
|
fn go(node: Node, buff: &mut String, level: usize) {
|
|
|
|
buff.push_str(&String::from(" ").repeat(level));
|
|
|
|
write!(buff, "{:?}\n", node).unwrap();
|
|
|
|
let my_errors = node.errors().filter(|e| e.after_child().is_none());
|
|
|
|
let parent_errors = node.parent().into_iter()
|
|
|
|
.flat_map(|n| n.errors())
|
|
|
|
.filter(|e| e.after_child() == Some(node));
|
|
|
|
|
|
|
|
for err in my_errors {
|
|
|
|
buff.push_str(&String::from(" ").repeat(level));
|
|
|
|
write!(buff, "err: `{}`\n", err.message()).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
for child in node.children() {
|
|
|
|
go(child, buff, level + 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
for err in parent_errors {
|
|
|
|
buff.push_str(&String::from(" ").repeat(level));
|
|
|
|
write!(buff, "err: `{}`\n", err.message()).unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|