diff --git a/src/lib.rs b/src/lib.rs index 0685e3f2ca..13872a3d9a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,8 +3,10 @@ extern crate unicode_xid; mod text; mod tree; mod lexer; +mod parser; pub mod syntax_kinds; pub use text::{TextUnit, TextRange}; pub use tree::{SyntaxKind, Token, FileBuilder, File, Node}; pub use lexer::{next_token, tokenize}; +pub use parser::parse; diff --git a/src/parser/mod.rs b/src/parser/mod.rs index da902e2b7e..7336c51363 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -1,5 +1,11 @@ -use {Token, File}; +use {Token, File, FileBuilder}; -pub fn parse(tokens: &[Token]) -> File { - unimplemented!() +use syntax_kinds::*; + + +pub fn parse(text: String, tokens: &[Token]) -> File { + let mut builder = FileBuilder::new(text); + builder.start_internal(FILE); + builder.finish_internal(); + builder.finish() } \ No newline at end of file diff --git a/tests/data/parser/0000_empty.txt b/tests/data/parser/0000_empty.txt index 843ea118d0..54be3e7bc9 100644 --- a/tests/data/parser/0000_empty.txt +++ b/tests/data/parser/0000_empty.txt @@ -1 +1 @@ -FILE@[0; 0) \ No newline at end of file +FILE@[0; 0) diff --git a/tests/parser.rs b/tests/parser.rs index f61b6830b6..e71b488523 100644 --- a/tests/parser.rs +++ b/tests/parser.rs @@ -7,7 +7,7 @@ use std::path::{PathBuf, Path}; use std::fs::read_dir; use std::fmt::Write; -use libsyntax2::{tokenize, Token, Node, File, FileBuilder}; +use libsyntax2::{tokenize, parse, Token, Node, File, FileBuilder}; #[test] fn parser_tests() { @@ -67,10 +67,3 @@ fn dump_tree(file: &File) -> String { } } } - -fn parse(text: String, tokens: &[Token]) -> File { - let mut builder = FileBuilder::new(text); - builder.start_internal(libsyntax2::syntax_kinds::FILE); - builder.finish_internal(); - builder.finish() -} \ No newline at end of file