more parsing
This commit is contained in:
parent
0999cbe28e
commit
935185ed92
@ -10,7 +10,7 @@ pub enum ASTNode {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Function {
|
pub struct Function {
|
||||||
pub prototype: Prototype,
|
pub prototype: Prototype,
|
||||||
pub body: Vec<ASTNode>,
|
pub body: Vec<Expression>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -127,9 +127,9 @@ impl Parser {
|
|||||||
use tokenizer::Token::*;
|
use tokenizer::Token::*;
|
||||||
expect!(self, Fn, "Expected 'fn'");
|
expect!(self, Fn, "Expected 'fn'");
|
||||||
let prototype = try!(self.prototype());
|
let prototype = try!(self.prototype());
|
||||||
let body = try!(self.body());
|
let body: Vec<Expression> = try!(self.body());
|
||||||
expect!(self, Keyword(Kw::End), "Expected 'end'");
|
expect!(self, Keyword(Kw::End), "Expected 'end'");
|
||||||
Ok(ASTNode::FuncNode(Function { prototype: prototype, body: vec!(ASTNode::ExprNode(body))} ))
|
Ok(ASTNode::FuncNode(Function { prototype: prototype, body: body } ))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prototype(&mut self) -> ParseResult<Prototype> {
|
fn prototype(&mut self) -> ParseResult<Prototype> {
|
||||||
@ -166,10 +166,10 @@ impl Parser {
|
|||||||
Ok(args)
|
Ok(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn body(&mut self) -> ParseResult<Expression> {
|
fn body(&mut self) -> ParseResult<Vec<Expression>> {
|
||||||
use tokenizer::Token::*;
|
use tokenizer::Token::*;
|
||||||
self.next();
|
self.next();
|
||||||
Ok(Expression::Number(101.01))
|
Ok(vec!(Expression::Number(101.01)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expression(&mut self) -> ParseResult<ASTNode> {
|
fn expression(&mut self) -> ParseResult<ASTNode> {
|
||||||
|
Loading…
Reference in New Issue
Block a user