Add parsing func using input content

instead of self.input()
This commit is contained in:
GreasySlug 2022-09-10 17:02:20 +09:00
parent f836453761
commit 663d39da5d

View file

@ -195,8 +195,7 @@ impl Runnable for ParserRunner {
}
fn eval(&mut self, src: Str) -> Result<String, ParserRunnerErrors> {
self.cfg.input = Input::Str(src);
let ast = self.parse()?;
let ast = self.parse_with_input(src)?;
Ok(format!("{ast}"))
}
}
@ -222,6 +221,15 @@ impl ParserRunner {
let mut self_ = Self::new(cfg);
self_.parse()
}
fn parse_with_input(&mut self, src: Str) -> Result<AST, ParserRunnerErrors> {
let ts = Lexer::new(Input::Str(src))
.lex()
.map_err(|errs| ParserRunnerErrors::convert(self.input(), errs))?;
Parser::new(ts)
.parse(Str::ever(self.cfg.module))
.map_err(|errs| ParserRunnerErrors::convert(self.input(), errs))
}
}
impl Parser {