mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-29 04:24:43 +00:00
Fix: ParserRunner::eval
parsing with default cfgs
This commit is contained in:
parent
fb3e42c57b
commit
15e7f8c5ad
2 changed files with 9 additions and 5 deletions
|
@ -159,8 +159,10 @@ impl Compiler {
|
||||||
pub fn compile(&mut self, src: Str, mode: &str) -> Result<CodeObj, CompileErrors> {
|
pub fn compile(&mut self, src: Str, mode: &str) -> Result<CodeObj, CompileErrors> {
|
||||||
log!("{GREEN}[DEBUG] the compiling process has started.{RESET}");
|
log!("{GREEN}[DEBUG] the compiling process has started.{RESET}");
|
||||||
let mut dynamic = true;
|
let mut dynamic = true;
|
||||||
let mut parser = ParserRunner::new(self.cfg.copy());
|
let mut cfg = self.cfg.copy();
|
||||||
let ast = parser.parse_from_str(src)?;
|
cfg.input = Input::Str(src);
|
||||||
|
let mut parser = ParserRunner::new(cfg);
|
||||||
|
let ast = parser.parse()?;
|
||||||
if ast.is_empty() {
|
if ast.is_empty() {
|
||||||
return Ok(CodeObj::empty(
|
return Ok(CodeObj::empty(
|
||||||
vec![],
|
vec![],
|
||||||
|
|
|
@ -295,7 +295,8 @@ impl Runnable for ParserRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eval(&mut self, src: Str) -> Result<String, ParserRunnerErrors> {
|
fn eval(&mut self, src: Str) -> Result<String, ParserRunnerErrors> {
|
||||||
let ast = Self::parse_from_str(src)?;
|
self.cfg.input = Input::Str(src);
|
||||||
|
let ast = self.parse()?;
|
||||||
Ok(format!("{ast}"))
|
Ok(format!("{ast}"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -314,9 +315,10 @@ impl ParserRunner {
|
||||||
self.parse_token_stream(ts)
|
self.parse_token_stream(ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_from_str(src: Str) -> Result<AST, ParserRunnerErrors> {
|
/// Parses with default configuration
|
||||||
|
pub fn parse_with_default_config(input: Input) -> Result<AST, ParserRunnerErrors> {
|
||||||
let mut cfg = ErgConfig::default();
|
let mut cfg = ErgConfig::default();
|
||||||
cfg.input = Input::Str(src);
|
cfg.input = input;
|
||||||
let mut self_ = Self::new(cfg);
|
let mut self_ = Self::new(cfg);
|
||||||
self_.parse()
|
self_.parse()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue