schala/src/parser.rs

53 lines
1019 B
Rust
Raw Normal View History

2015-12-25 02:03:11 -08:00
use tokenizer::Token;
2015-12-24 22:01:59 -08:00
2016-01-10 01:15:34 -08:00
#[derive(Debug, Clone)]
pub enum ASTNode {
ExprNode(Expression),
FuncNode(Function),
}
#[derive(Debug, Clone)]
pub struct Function {
pub prototype: Prototype,
pub body: Expression
}
#[derive(Debug, Clone)]
pub struct Prototype {
pub name: String,
pub args: Vec<String>
}
#[derive(Debug, Clone)]
pub enum Expression {
Literal(f64),
Variable(String),
BinExp(String, Box<Expression>, Box<Expression>),
Call(String, Vec<Expression>),
}
pub type AST = Vec<ASTNode>;
//TODO make this support incomplete parses
pub type ParseResult<T> = Result<T, ParseError>;
2015-12-24 22:01:59 -08:00
#[derive(Debug)]
2016-01-10 01:15:34 -08:00
pub struct ParseError {
pub msg: String
}
2016-01-10 01:15:34 -08:00
impl ParseError {
fn new<T>(msg: &str) -> ParseResult<T> {
Err(ParseError { msg: msg.to_string() })
}
}
2015-12-25 02:03:11 -08:00
2016-01-10 01:15:34 -08:00
pub fn parse(tokens: &[Token], parsed_tree: &[ASTNode]) -> ParseResult<AST> {
let rest = tokens.to_vec().reverse();
let mut ast = parsed_tree.to_vec();
ParseError::new("Parsing not implemented")
2015-12-25 02:03:11 -08:00
}
2016-01-10 01:15:34 -08:00