diff --git a/parser/src/grammar_builder.rs b/parser/src/grammar_builder.rs index 8dac71f..4c844e9 100644 --- a/parser/src/grammar_builder.rs +++ b/parser/src/grammar_builder.rs @@ -3,8 +3,8 @@ use std::{collections::HashMap, sync::atomic::AtomicU32}; use anyhow::{ensure, Result}; use crate::api::{ - GenGrammarOptions, GrammarId, GrammarWithLexer, Node, NodeId, NodeProps, RegexId, RegexNode, - RegexSpec, TopLevelGrammar, + GenGrammarOptions, GenOptions, GrammarId, GrammarWithLexer, Node, NodeId, NodeProps, RegexId, + RegexNode, RegexSpec, TopLevelGrammar, }; #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] @@ -211,6 +211,23 @@ impl GrammarBuilder { }) } + pub fn gen_rx(&mut self, regex: &str, stop_regex: &str) -> NodeRef { + self.gen(GenOptions { + body_rx: RegexSpec::Regex(regex.to_string()), + stop_rx: RegexSpec::Regex(stop_regex.to_string()), + stop_capture_name: None, + lazy: None, + temperature: None, + }) + } + + pub fn gen(&mut self, data: GenOptions) -> NodeRef { + self.add_node(Node::Gen { + data, + props: NodeProps::default(), + }) + } + pub fn lexeme(&mut self, rx: RegexSpec, json_quoted: bool) -> NodeRef { self.add_node(Node::Lexeme { rx,