aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-07-29 13:16:07 +0100
committerAleksey Kladov <[email protected]>2018-07-29 13:16:07 +0100
commit415c891d641fa305e7ddbbbcc78db990dd5d3564 (patch)
tree4b6e1e0aa4b5a732aeae8945e75c9bee3bbf1d65 /src/lib.rs
parentad188d4c3db34f035408afbdd6d2f3c308121f0a (diff)
Reorganize
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs37
1 files changed, 23 insertions, 14 deletions
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 @@
19extern crate unicode_xid; 19extern crate unicode_xid;
20extern crate text_unit; 20extern crate text_unit;
21 21
22mod tree;
23mod lexer; 22mod lexer;
24mod parser; 23mod parser;
25mod yellow; 24mod yellow;
25mod syntax_kinds;
26
27pub use {
28 text_unit::{TextRange, TextUnit},
29 syntax_kinds::SyntaxKind,
30 yellow::{SyntaxNode},
31 lexer::{tokenize, Token},
32};
33
34pub(crate) use {
35 yellow::SyntaxError
36};
37
38pub fn parse(text: String) -> SyntaxNode {
39 let tokens = tokenize(&text);
40 parser::parse::<yellow::GreenBuilder>(text, &tokens)
41}
26 42
27pub mod syntax_kinds;
28pub use text_unit::{TextRange, TextUnit};
29pub use tree::{SyntaxKind, Token};
30pub(crate) use tree::{Sink, GreenBuilder};
31pub use lexer::{next_token, tokenize};
32pub use yellow::SyntaxNode;
33pub(crate) use yellow::SError;
34pub use parser::{parse_green};
35 43
36/// Utilities for simple uses of the parser. 44/// Utilities for simple uses of the parser.
37pub mod utils { 45pub mod utils {
38 use std::fmt::Write; 46 use std::{
47 fmt::Write,
48 collections::BTreeSet
49 };
39 50
40 use {SyntaxNode}; 51 use {SyntaxNode, SyntaxError};
41 use std::collections::BTreeSet;
42 use SError;
43 52
44 /// Parse a file and create a string representation of the resulting parse tree. 53 /// Parse a file and create a string representation of the resulting parse tree.
45 pub fn dump_tree_green(syntax: &SyntaxNode) -> String { 54 pub fn dump_tree_green(syntax: &SyntaxNode) -> String {
@@ -48,7 +57,7 @@ pub mod utils {
48 go(syntax, &mut result, 0, &mut errors); 57 go(syntax, &mut result, 0, &mut errors);
49 return result; 58 return result;
50 59
51 fn go(node: &SyntaxNode, buff: &mut String, level: usize, errors: &mut BTreeSet<SError>) { 60 fn go(node: &SyntaxNode, buff: &mut String, level: usize, errors: &mut BTreeSet<SyntaxError>) {
52 buff.push_str(&String::from(" ").repeat(level)); 61 buff.push_str(&String::from(" ").repeat(level));
53 write!(buff, "{:?}\n", node).unwrap(); 62 write!(buff, "{:?}\n", node).unwrap();
54 let my_errors: Vec<_> = errors.iter().filter(|e| e.offset == node.range().start()) 63 let my_errors: Vec<_> = errors.iter().filter(|e| e.offset == node.range().start())