parser wip

This commit is contained in:
Michael Sippel 2024-05-09 20:13:10 +02:00
parent 09e9e063ae
commit ebc5f720bf
Signed by: senvas
GPG key ID: F96CF119C34B64A6
3 changed files with 277 additions and 0 deletions

73
src/parser.rs Normal file
View 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)
}
}