From 39024fdc14703e3936f88d9ec938aad55085d05a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 31 Dec 2017 23:27:36 +0300 Subject: Parser test boilerplate --- src/bin/gen.rs | 14 ++++++++++---- src/lib.rs | 2 +- src/syntax_kinds.rs | 4 +++- 3 files changed, 14 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/bin/gen.rs b/src/bin/gen.rs index 4acf381e3..f5a66d9f2 100644 --- a/src/bin/gen.rs +++ b/src/bin/gen.rs @@ -17,7 +17,8 @@ fn main() { #[derive(Deserialize)] struct Grammar { - syntax_kinds: Vec, + tokens: Vec, + nodes: Vec, } impl Grammar { @@ -31,7 +32,12 @@ impl Grammar { acc.push_str("// Generated from grammar.ron\n"); acc.push_str("use tree::{SyntaxKind, SyntaxInfo};\n"); acc.push_str("\n"); - for (idx, kind) in self.syntax_kinds.iter().enumerate() { + + let syntax_kinds: Vec<&String> = + self.tokens.iter().chain(self.nodes.iter()) + .collect(); + + for (idx, kind) in syntax_kinds.iter().enumerate() { let sname = scream(kind); write!( acc, @@ -40,8 +46,8 @@ impl Grammar { ).unwrap(); } acc.push_str("\n"); - write!(acc, "static INFOS: [SyntaxInfo; {}] = [\n", self.syntax_kinds.len()).unwrap(); - for kind in self.syntax_kinds.iter() { + write!(acc, "static INFOS: [SyntaxInfo; {}] = [\n", syntax_kinds.len()).unwrap(); + for kind in syntax_kinds.iter() { let sname = scream(kind); write!( acc, diff --git a/src/lib.rs b/src/lib.rs index 82213e2b3..0685e3f2c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,5 +6,5 @@ mod lexer; pub mod syntax_kinds; pub use text::{TextUnit, TextRange}; -pub use tree::{SyntaxKind, Token}; +pub use tree::{SyntaxKind, Token, FileBuilder, File, Node}; pub use lexer::{next_token, tokenize}; diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index ec2a036b9..b83f48dd8 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs @@ -52,8 +52,9 @@ pub const THIN_ARROW: SyntaxKind = SyntaxKind(47); pub const COMMENT: SyntaxKind = SyntaxKind(48); pub const DOC_COMMENT: SyntaxKind = SyntaxKind(49); pub const SHEBANG: SyntaxKind = SyntaxKind(50); +pub const FILE: SyntaxKind = SyntaxKind(51); -static INFOS: [SyntaxInfo; 51] = [ +static INFOS: [SyntaxInfo; 52] = [ SyntaxInfo { name: "ERROR" }, SyntaxInfo { name: "IDENT" }, SyntaxInfo { name: "UNDERSCORE" }, @@ -105,6 +106,7 @@ static INFOS: [SyntaxInfo; 51] = [ SyntaxInfo { name: "COMMENT" }, SyntaxInfo { name: "DOC_COMMENT" }, SyntaxInfo { name: "SHEBANG" }, + SyntaxInfo { name: "FILE" }, ]; pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo { -- cgit v1.2.3