diff --git a/compiler/erg_compiler/compile.rs b/compiler/erg_compiler/compile.rs index beee924b..cb904aca 100644 --- a/compiler/erg_compiler/compile.rs +++ b/compiler/erg_compiler/compile.rs @@ -159,8 +159,10 @@ impl Compiler { pub fn compile(&mut self, src: Str, mode: &str) -> Result { log!("{GREEN}[DEBUG] the compiling process has started.{RESET}"); let mut dynamic = true; - let mut parser = ParserRunner::new(self.cfg.copy()); - let ast = parser.parse_from_str(src)?; + let mut cfg = self.cfg.copy(); + cfg.input = Input::Str(src); + let mut parser = ParserRunner::new(cfg); + let ast = parser.parse()?; if ast.is_empty() { return Ok(CodeObj::empty( vec![], diff --git a/compiler/erg_parser/parse.rs b/compiler/erg_parser/parse.rs index 2be6a26d..8dc2f35b 100644 --- a/compiler/erg_parser/parse.rs +++ b/compiler/erg_parser/parse.rs @@ -295,7 +295,8 @@ impl Runnable for ParserRunner { } fn eval(&mut self, src: Str) -> Result { - let ast = Self::parse_from_str(src)?; + self.cfg.input = Input::Str(src); + let ast = self.parse()?; Ok(format!("{ast}")) } } @@ -314,9 +315,10 @@ impl ParserRunner { self.parse_token_stream(ts) } - pub fn parse_from_str(src: Str) -> Result { + /// Parses with default configuration + pub fn parse_with_default_config(input: Input) -> Result { let mut cfg = ErgConfig::default(); - cfg.input = Input::Str(src); + cfg.input = input; let mut self_ = Self::new(cfg); self_.parse() }