prism_parser/
lib.rs

1use std::sync::LazyLock;
2
3use grammar::from_action_result::parse_grammarfile;
4
5use crate::core::cache::Allocs;
6use crate::error::aggregate_error::AggregatedParseError;
7use crate::error::error_printer::ErrorLabel;
8use crate::error::ParseError;
9use crate::grammar::from_action_result::parse_rule_action;
10use crate::grammar::GrammarFile;
11use crate::parser::parser_instance::run_parser_rule;
12
13pub mod core;
14pub mod error;
15pub mod grammar;
16pub mod parser;
17
18pub static META_GRAMMAR: LazyLock<GrammarFile<'static, 'static>> = LazyLock::new(|| {
19    let meta_grammar = include_bytes!("../resources/bootstrap.bincode");
20    bincode::deserialize(meta_grammar).unwrap()
21});
22
23pub fn parse_grammar<'grm, E: ParseError<L = ErrorLabel<'grm>> + 'grm>(
24    grammar: &'grm str,
25    allocs: Allocs<'grm>,
26) -> Result<GrammarFile<'grm, 'grm>, AggregatedParseError<'grm, E>> {
27    run_parser_rule(&META_GRAMMAR, "toplevel", grammar, |ar, _| {
28        parse_grammarfile(ar, grammar, allocs, |ar, src| {
29            parse_rule_action(ar, src, allocs)
30        })
31        .expect("Grammars parsed by the meta grammar should have a legal AST.")
32    })
33}