Skip to content

Commit

Permalink
Add gen() to GrammarBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal committed Nov 20, 2024
1 parent fdd515e commit 6e199da
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions parser/src/grammar_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6e199da

Please sign in to comment.