74 lines
1.5 KiB
Rust
74 lines
1.5 KiB
Rust
|
use {
|
||
|
std::iter::Peekable,
|
||
|
crate::{
|
||
|
lexer::{LTIRLexer, LTIRToken, LexError},
|
||
|
expr::LTExpr
|
||
|
}
|
||
|
};
|
||
|
|
||
|
#[derive(Clone, Debug)]
|
||
|
pub enum ParseError {
|
||
|
LexError(LexError),
|
||
|
UnexpectedClose,
|
||
|
UnexpectedEnd,
|
||
|
UnexpectedToken
|
||
|
}
|
||
|
|
||
|
pub fn parse_statement<It>(
|
||
|
tokens: &mut Peekable<LTIRLexer<It>>
|
||
|
) -> Result< crate::expr::Statement, ParseError >
|
||
|
where It: Iterator<Item = char>
|
||
|
{
|
||
|
Err(ParseError::UnexpectedEnd)
|
||
|
}
|
||
|
|
||
|
pub fn parse_block<It>(
|
||
|
tokens: &mut Peekable<LTIRLexer<It>>
|
||
|
) -> Result< crate::expr::LTExpr, ParseError >
|
||
|
where It: Iterator<Item = char>
|
||
|
{
|
||
|
Err(ParseError::UnexpectedEnd)
|
||
|
}
|
||
|
|
||
|
pub fn parse_expr<It>(
|
||
|
tokens: &mut Peekable<LTIRLexer<It>>
|
||
|
) -> Result< crate::expr::LTExpr, ParseError >
|
||
|
where It: Iterator<Item = char>
|
||
|
{
|
||
|
let mut children = Vec::new();
|
||
|
|
||
|
match tokens.next() {
|
||
|
Some(Ok(LTIRToken::ExprOpen)) => {
|
||
|
if let Ok(subexpr) = parse_expr( tokens ) {
|
||
|
|
||
|
} else {
|
||
|
|
||
|
}
|
||
|
/*
|
||
|
Err(ParseError::UnexpectedEnd)
|
||
|
*/
|
||
|
},
|
||
|
Some(Ok(LTIRToken::BlockOpen)) => {
|
||
|
/*
|
||
|
Err(ParseError::UnexpectedEnd)
|
||
|
*/
|
||
|
}
|
||
|
/*
|
||
|
_ => Err(ParseError::UnexpectedToken),
|
||
|
None => Err(ParseError::UnexpectedEnd)
|
||
|
*/
|
||
|
_ => {}
|
||
|
}
|
||
|
|
||
|
if children.len() > 0 {
|
||
|
let head = children.remove(0);
|
||
|
Ok(LTExpr::Application {
|
||
|
head: Box::new(head),
|
||
|
body: children
|
||
|
})
|
||
|
} else {
|
||
|
Err(ParseError::UnexpectedEnd)
|
||
|
}
|
||
|
}
|
||
|
|