WIP source map stuff
This commit is contained in:
parent
e42f0c644c
commit
d357876b16
@ -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,21 +1028,24 @@ 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() {
|
||||||
BinNumberSigil => {
|
t => match t.get() {
|
||||||
let digits = self.digits()?;
|
BinNumberSigil => {
|
||||||
let n = parse_binary(digits)?;
|
let digits = self.digits()?;
|
||||||
Ok(Expression(NatLiteral(n), None))
|
let n = parse_binary(digits)?;
|
||||||
},
|
Ok(Expression(NatLiteral(n), None))
|
||||||
HexLiteral(text) => {
|
},
|
||||||
let digits: String = text.chars().filter(|c| c.is_digit(16)).collect();
|
HexLiteral(text) => {
|
||||||
let n = parse_hex(digits)?;
|
let digits: String = text.chars().filter(|c| c.is_digit(16)).collect();
|
||||||
Ok(Expression(NatLiteral(n), None))
|
let n = parse_hex(digits)?;
|
||||||
},
|
Ok(Expression(NatLiteral(n), None))
|
||||||
_ => 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> {
|
||||||
use self::ExpressionType::*;
|
use self::ExpressionType::*;
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user