diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index b8e9bba..e10e265 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -246,14 +246,14 @@ impl TokenHandler { impl<'a> Parser<'a> { /// Create a new parser initialized with some tokens. - pub fn new(initial_input: Vec, source_map_pointer: &mut SourceMap) -> Parser { + pub fn new(initial_input: Vec, source_map: &mut SourceMap) -> Parser { Parser { token_handler: TokenHandler::new(initial_input), parse_record: vec![], parse_level: 0, restrictions: ParserRestrictions { no_struct_literal: false }, id_store: ItemIdStore::new(), - source_map: source_map_pointer, + source_map, } } diff --git a/schala-lang/language/src/parsing/test.rs b/schala-lang/language/src/parsing/test.rs index 1c74aa9..34d21bc 100644 --- a/schala-lang/language/src/parsing/test.rs +++ b/schala-lang/language/src/parsing/test.rs @@ -2,7 +2,6 @@ use ::std::rc::Rc; use std::str::FromStr; -use crate::util::quick_ast; use super::tokenize; use super::ParseResult; use crate::ast::*; diff --git a/schala-lang/language/src/schala.rs b/schala-lang/language/src/schala.rs index 17ff59a..8d7ed48 100644 --- a/schala-lang/language/src/schala.rs +++ b/schala-lang/language/src/schala.rs @@ -22,7 +22,6 @@ pub type SourceMapHandle = Rc>; pub struct Schala { source_reference: SourceReference, source_map: SourceMapHandle, - source_map_: SourceMap, state: eval::State<'static>, symbol_table: SymbolTableHandle, resolver: crate::scope_resolution::ScopeResolver<'static>, @@ -48,7 +47,6 @@ impl Schala { source_reference: SourceReference::new(), symbol_table: symbols.clone(), source_map: source_map.clone(), - source_map_: SourceMap::new(), resolver: crate::scope_resolution::ScopeResolver::new(symbols.clone()), state: eval::State::new(symbols), type_context: typechecking::TypeContext::new(), @@ -112,7 +110,8 @@ fn parsing(input: Vec, handle: &mut Schala, comp: Option<&mut use crate::parsing::Parser; use ParsingDebugType::*; - let mut parser = handle.active_parser.take().unwrap_or_else(|| Parser::new(input, &mut handle.source_map_)); + let ref mut source_map = handle.source_map.borrow_mut(); + let mut parser = handle.active_parser.take().unwrap_or_else(|| Parser::new(input, source_map)); let ast = parser.parse(); comp.map(|comp| { @@ -130,13 +129,13 @@ fn parsing(input: Vec, handle: &mut Schala, comp: Option<&mut }; comp.add_artifact(debug_info); }); - ast.map_err(|err| format_parse_error(err, handle)) + ast.map_err(|err| format_parse_error(err, &handle.source_reference)) } -fn format_parse_error(error: parsing::ParseError, handle: &mut Schala) -> String { +fn format_parse_error(error: parsing::ParseError, source_reference: &SourceReference) -> String { let line_num = error.token.location.line_num; let ch = error.token.location.char_num; - let line_from_program = handle.source_reference.get_line(line_num); + let line_from_program = source_reference.get_line(line_num); let location_pointer = format!("{}^", " ".repeat(ch)); let line_num_digits = format!("{}", line_num).chars().count();