mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-29 20:34:44 +00:00
Add parsing func using input content
instead of self.input()
This commit is contained in:
parent
f836453761
commit
663d39da5d
1 changed files with 10 additions and 2 deletions
|
@ -195,8 +195,7 @@ impl Runnable for ParserRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eval(&mut self, src: Str) -> Result<String, ParserRunnerErrors> {
|
fn eval(&mut self, src: Str) -> Result<String, ParserRunnerErrors> {
|
||||||
self.cfg.input = Input::Str(src);
|
let ast = self.parse_with_input(src)?;
|
||||||
let ast = self.parse()?;
|
|
||||||
Ok(format!("{ast}"))
|
Ok(format!("{ast}"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -222,6 +221,15 @@ impl ParserRunner {
|
||||||
let mut self_ = Self::new(cfg);
|
let mut self_ = Self::new(cfg);
|
||||||
self_.parse()
|
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 {
|
impl Parser {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue