Fix functin parsing
This commit is contained in:
parent
db1e188fdb
commit
fff9cb7d25
@ -88,6 +88,14 @@ macro_rules! expect {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_delimiter(token: &Token) -> bool {
|
||||||
|
use tokenizer::Token::*;
|
||||||
|
match *token {
|
||||||
|
Newline | Semicolon => true,
|
||||||
|
_ => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Parser {
|
impl Parser {
|
||||||
fn program(&mut self) -> ParseResult<AST> {
|
fn program(&mut self) -> ParseResult<AST> {
|
||||||
use tokenizer::Token::*;
|
use tokenizer::Token::*;
|
||||||
@ -99,7 +107,7 @@ impl Parser {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let result: ParseResult<ASTNode> = match cur_tok {
|
let result: ParseResult<ASTNode> = match cur_tok {
|
||||||
Newline | Semicolon => { self.next(); continue},
|
ref t if is_delimiter(&t) => { self.next(); continue},
|
||||||
_ => self.statement()
|
_ => self.statement()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -117,7 +125,7 @@ impl Parser {
|
|||||||
let cur_tok: Token = self.peek().unwrap().clone();
|
let cur_tok: Token = self.peek().unwrap().clone();
|
||||||
let node: ASTNode = match cur_tok {
|
let node: ASTNode = match cur_tok {
|
||||||
Keyword(Kw::Fn) => try!(self.declaration()),
|
Keyword(Kw::Fn) => try!(self.declaration()),
|
||||||
_ => try!(self.expression())
|
_ => ASTNode::ExprNode(try!(self.expression())),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(node)
|
Ok(node)
|
||||||
@ -168,18 +176,27 @@ impl Parser {
|
|||||||
|
|
||||||
fn body(&mut self) -> ParseResult<Vec<Expression>> {
|
fn body(&mut self) -> ParseResult<Vec<Expression>> {
|
||||||
use tokenizer::Token::*;
|
use tokenizer::Token::*;
|
||||||
self.next();
|
let mut exprs = Vec::new();
|
||||||
Ok(vec!(Expression::Number(101.01)))
|
loop {
|
||||||
|
match self.peek() {
|
||||||
|
Some(ref t) if is_delimiter(t) => { self.next(); continue},
|
||||||
|
Some(Keyword(Kw::End)) => break,
|
||||||
|
_ => {
|
||||||
|
let expr = try!(self.expression());
|
||||||
|
exprs.push(expr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(exprs)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expression(&mut self) -> ParseResult<ASTNode> {
|
fn expression(&mut self) -> ParseResult<Expression> {
|
||||||
use tokenizer::Token::*;
|
use tokenizer::Token::*;
|
||||||
let expr: Expression = match self.next() {
|
let expr: Expression = match self.next() {
|
||||||
Some(Identifier(s)) => Expression::StringLiteral(s),
|
Some(Identifier(s)) => Expression::StringLiteral(s),
|
||||||
Some(x) => panic!("lol tryinna parse {:?}", x),
|
_ => panic!("bad expression parse"),
|
||||||
None => panic!("FUCK")
|
|
||||||
};
|
};
|
||||||
Ok(ASTNode::ExprNode(expr))
|
Ok(expr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user