diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 37 |
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 @@ | |||
19 | extern crate unicode_xid; | 19 | extern crate unicode_xid; |
20 | extern crate text_unit; | 20 | extern crate text_unit; |
21 | 21 | ||
22 | mod tree; | ||
23 | mod lexer; | 22 | mod lexer; |
24 | mod parser; | 23 | mod parser; |
25 | mod yellow; | 24 | mod yellow; |
25 | mod syntax_kinds; | ||
26 | |||
27 | pub use { | ||
28 | text_unit::{TextRange, TextUnit}, | ||
29 | syntax_kinds::SyntaxKind, | ||
30 | yellow::{SyntaxNode}, | ||
31 | lexer::{tokenize, Token}, | ||
32 | }; | ||
33 | |||
34 | pub(crate) use { | ||
35 | yellow::SyntaxError | ||
36 | }; | ||
37 | |||
38 | pub fn parse(text: String) -> SyntaxNode { | ||
39 | let tokens = tokenize(&text); | ||
40 | parser::parse::<yellow::GreenBuilder>(text, &tokens) | ||
41 | } | ||
26 | 42 | ||
27 | pub mod syntax_kinds; | ||
28 | pub use text_unit::{TextRange, TextUnit}; | ||
29 | pub use tree::{SyntaxKind, Token}; | ||
30 | pub(crate) use tree::{Sink, GreenBuilder}; | ||
31 | pub use lexer::{next_token, tokenize}; | ||
32 | pub use yellow::SyntaxNode; | ||
33 | pub(crate) use yellow::SError; | ||
34 | pub use parser::{parse_green}; | ||
35 | 43 | ||
36 | /// Utilities for simple uses of the parser. | 44 | /// Utilities for simple uses of the parser. |
37 | pub mod utils { | 45 | pub 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()) |