mirror of
https://github.com/fluencelabs/lalrpop
synced 2025-03-16 17:00:53 +00:00
Merge pull request #208 from wieczyk/issue203_enable_constructing_lr1_states_via_envvar
Enabling lane-table-algorithm via environment variable
This commit is contained in:
commit
6f12cfe41b
@ -8,29 +8,41 @@ use lr1::first;
|
||||
use lr1::lane_table::*;
|
||||
use lr1::lookahead::*;
|
||||
use std::rc::Rc;
|
||||
use std::env;
|
||||
use tls::Tls;
|
||||
|
||||
#[cfg(test)]
|
||||
mod test;
|
||||
|
||||
fn build_lr1_states_legacy<'grammar>(grammar: &'grammar Grammar, start: NonterminalString) -> LR1Result<'grammar>
|
||||
{
|
||||
let eof = TokenSet::eof();
|
||||
let mut lr1: LR<'grammar, TokenSet> = LR::new(grammar, start, eof);
|
||||
lr1.set_permit_early_stop(true);
|
||||
lr1.build_states()
|
||||
}
|
||||
|
||||
type ConstructionFunction<'grammar> = fn(&'grammar Grammar, NonterminalString) -> LR1Result<'grammar> ;
|
||||
|
||||
pub fn build_lr1_states<'grammar>(grammar: &'grammar Grammar,
|
||||
start: NonterminalString)
|
||||
-> LR1Result<'grammar>
|
||||
{
|
||||
// this is just here to squash dead code warnings while work on
|
||||
// lane-table proceeds
|
||||
if false {
|
||||
let _ = build_lane_table_states(grammar, start);
|
||||
}
|
||||
|
||||
let (method_name, method_fn) = match env::var("LALRPOP_LANE_TABLE") {
|
||||
Ok(ref s) if s == "enabled" => {
|
||||
("lane", build_lane_table_states as ConstructionFunction)
|
||||
}
|
||||
_ => {
|
||||
("legacy", build_lr1_states_legacy as ConstructionFunction)
|
||||
}
|
||||
};
|
||||
|
||||
profile! {
|
||||
&Tls::session(),
|
||||
"LR(1) state construction",
|
||||
format!("LR(1) state construction ({})", method_name),
|
||||
{
|
||||
let eof = TokenSet::eof();
|
||||
let mut lr1: LR<'grammar, TokenSet> = LR::new(grammar, start, eof);
|
||||
lr1.set_permit_early_stop(true);
|
||||
lr1.build_states()
|
||||
method_fn(grammar, start)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user