WIP source map stuff

This commit is contained in:
greg 2018-11-16 04:12:07 -08:00
parent e42f0c644c
commit d357876b16
2 changed files with 38 additions and 19 deletions

View File

@ -6,6 +6,7 @@ use tokenizing::*;
use tokenizing::Kw::*; use tokenizing::Kw::*;
use tokenizing::TokenType::*; use tokenizing::TokenType::*;
use source_map::{SourceMap, SourceData};
use ast::*; use ast::*;
use builtin::{BinOp, PrefixOp}; use builtin::{BinOp, PrefixOp};
@ -90,8 +91,12 @@ impl Parser {
self.token_handler.next() self.token_handler.next()
} }
fn next_with_metadata(&mut self) -> Token { fn next_with_map(&mut self) -> SourceMap<TokenType> {
self.token_handler.next_with_metadata() let tt = self.next();
SourceMap {
node: tt,
data: SourceData { line_number: 420, char_idx: 69 }
}
} }
pub fn parse(&mut self) -> ParseResult<AST> { pub fn parse(&mut self) -> ParseResult<AST> {
@ -1023,7 +1028,8 @@ impl Parser {
#[recursive_descent_method] #[recursive_descent_method]
fn int_literal(&mut self) -> ParseResult<Expression> { fn int_literal(&mut self) -> ParseResult<Expression> {
use self::ExpressionType::*; use self::ExpressionType::*;
match self.next_with_metadata().get_token_type() { match self.next_with_map() {
t => match t.get() {
BinNumberSigil => { BinNumberSigil => {
let digits = self.digits()?; let digits = self.digits()?;
let n = parse_binary(digits)?; let n = parse_binary(digits)?;
@ -1037,6 +1043,8 @@ impl Parser {
_ => return ParseError::new("Expected '0x' or '0b'"), _ => return ParseError::new("Expected '0x' or '0b'"),
} }
} }
}
#[recursive_descent_method] #[recursive_descent_method]
fn float_literal(&mut self) -> ParseResult<Expression> { fn float_literal(&mut self) -> ParseResult<Expression> {

View File

@ -1,12 +1,23 @@
#[derive(Debug, Clone)]
pub struct SourceMap<T> { pub struct SourceMap<T> {
node: T, pub node: T,
data: SourceData pub data: SourceData
} }
struct SourceData { impl<T> SourceMap<T> {
line_number: usize, pub fn get(&self) -> &T {
char_idx: usize &self.node
}
pub fn get_source_data(&self) -> SourceData {
So
}
#[derive(Debug, Clone)]
pub struct SourceData {
pub line_number: usize,
pub char_idx: usize
} }