Start to add source map insertions
This commit is contained in:
parent
129d9ec673
commit
82520aa28d
@ -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]
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user