From 82520aa28d1212b8649a6720f94de3df2d34977a Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 23 Oct 2019 02:37:42 -0700 Subject: [PATCH] Start to add source map insertions --- schala-lang/language/src/parsing.rs | 7 +++++-- schala-lang/language/src/source_map.rs | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index fbc8fcd..8ab3f09 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -371,7 +371,8 @@ impl Parser { #[recursive_descent_method] fn statement(&mut self) -> ParseResult { //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(Func)=> self.func_declaration().map(|func| { StatementKind::Declaration(func) }), 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)), _ => 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] diff --git a/schala-lang/language/src/source_map.rs b/schala-lang/language/src/source_map.rs index 64f38ba..43e8319 100644 --- a/schala-lang/language/src/source_map.rs +++ b/schala-lang/language/src/source_map.rs @@ -23,4 +23,8 @@ impl SourceMap { pub fn new() -> SourceMap { SourceMap { map: HashMap::new() } } + + pub fn add_location(&mut self, id: &ItemId, loc: Location) { + self.map.insert(id.clone(), loc); + } }