Start to add source map insertions

This commit is contained in:
greg 2019-10-23 02:37:42 -07:00
parent 129d9ec673
commit 82520aa28d
2 changed files with 9 additions and 2 deletions

View File

@ -371,7 +371,8 @@ impl Parser {
#[recursive_descent_method] #[recursive_descent_method]
fn statement(&mut self) -> ParseResult<Statement> { fn statement(&mut self) -> ParseResult<Statement> {
//TODO handle error recovery here //TODO handle error recovery here
let kind = match self.token_handler.peek().get_kind() { let tok = self.token_handler.peek();
let kind = match tok.get_kind() {
Keyword(Type) => self.type_declaration().map(|decl| { StatementKind::Declaration(decl) }), Keyword(Type) => self.type_declaration().map(|decl| { StatementKind::Declaration(decl) }),
Keyword(Func)=> self.func_declaration().map(|func| { StatementKind::Declaration(func) }), Keyword(Func)=> self.func_declaration().map(|func| { StatementKind::Declaration(func) }),
Keyword(Let) => self.binding_declaration().map(|decl| StatementKind::Declaration(decl)), Keyword(Let) => self.binding_declaration().map(|decl| StatementKind::Declaration(decl)),
@ -381,7 +382,9 @@ impl Parser {
Keyword(Module) => self.module_declaration().map(|spec| StatementKind::Module(spec)), Keyword(Module) => self.module_declaration().map(|spec| StatementKind::Module(spec)),
_ => self.expression().map(|expr| { StatementKind::Expression(expr) } ), _ => self.expression().map(|expr| { StatementKind::Expression(expr) } ),
}?; }?;
Ok(Statement { kind, id: self.id_store.fresh() }) let id = self.id_store.fresh();
self.source_map.add_location(&id, tok.location);
Ok(Statement { kind, id })
} }
#[recursive_descent_method] #[recursive_descent_method]

View File

@ -23,4 +23,8 @@ impl SourceMap {
pub fn new() -> SourceMap { pub fn new() -> SourceMap {
SourceMap { map: HashMap::new() } SourceMap { map: HashMap::new() }
} }
pub fn add_location(&mut self, id: &ItemId, loc: Location) {
self.map.insert(id.clone(), loc);
}
} }