From 6e199da4d1c4ef7b604e0cd9ca63f6afa5b4080a Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Wed, 20 Nov 2024 09:04:00 -0800 Subject: [PATCH] Add gen() to GrammarBuilder --- parser/src/grammar_builder.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) 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,