parser wip
This commit is contained in:
parent
09e9e063ae
commit
ebc5f720bf
3 changed files with 277 additions and 0 deletions
src
73
src/parser.rs
Normal file
73
src/parser.rs
Normal file
|
@ -0,0 +1,73 @@
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue