Rejiggering some things with the SourceMap pointer in Parser
This commit is contained in:
parent
5bb1a245c4
commit
11a9a60a34
@ -246,14 +246,14 @@ impl TokenHandler {
|
||||
|
||||
impl<'a> Parser<'a> {
|
||||
/// Create a new parser initialized with some tokens.
|
||||
pub fn new(initial_input: Vec<Token>, source_map_pointer: &mut SourceMap) -> Parser {
|
||||
pub fn new(initial_input: Vec<Token>, 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,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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::*;
|
||||
|
@ -22,7 +22,6 @@ pub type SourceMapHandle = Rc<RefCell<source_map::SourceMap>>;
|
||||
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<tokenizing::Token>, 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<tokenizing::Token>, 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();
|
||||
|
Loading…
Reference in New Issue
Block a user