diff --git a/src/lib.rs b/src/lib.rs index c711372..256a2dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -309,6 +309,7 @@ fn compile_machine_policies_internal( fn get_policies(input_files: Vec<&str>) -> Result, CascadeErrors> { let mut errors = CascadeErrors::new(); let mut policies: Vec = Vec::new(); + let parser = parser::PolicyParser::new(); for f in input_files { let policy_str = match std::fs::read_to_string(f) { Ok(s) => s, @@ -317,7 +318,7 @@ fn get_policies(input_files: Vec<&str>) -> Result, CascadeErrors continue; } }; - let p = match parse_policy(&policy_str) { + let p = match parse_policy(&parser, &policy_str) { Ok(p) => p, Err(evec) => { for e in evec { @@ -332,13 +333,13 @@ fn get_policies(input_files: Vec<&str>) -> Result, CascadeErrors errors.into_result(policies) } -fn parse_policy( - policy: &str, -) -> Result, Vec>> { +fn parse_policy<'a>( + parser: &parser::PolicyParser, + policy: &'a str, +) -> Result, Vec, ParseErrorMsg>>> +{ let mut errors = Vec::new(); - // TODO: Probably should only construct once - // Why though? - let parse_res = parser::PolicyParser::new().parse(&mut errors, policy); + let parse_res = parser.parse(&mut errors, policy); // errors is a vec of ErrorRecovery. ErrorRecovery is a struct wrapping a ParseError // and a sequence of discarded characters. We don't need those characters, so we just // remove the wrapping.