iowo/crates/lang/src/parser/grammar/expression.rs

63 lines
1.5 KiB
Rust
Raw Normal View History

2024-04-24 19:37:52 +02:00
use crate::parser::{syntax_kind::SyntaxKind::*, CompletedMarker, Parser};
2024-04-24 11:07:38 +02:00
2024-04-24 19:37:52 +02:00
use self::{collection::collection, instruction::instr, lit::literal};
2024-04-24 11:07:38 +02:00
mod instruction;
mod lit;
2024-04-24 19:37:52 +02:00
mod collection {
use enumset::enum_set;
2024-04-24 11:07:38 +02:00
2024-04-24 19:37:52 +02:00
use crate::parser::{
syntax_kind::{SyntaxKind::*, TokenSet},
CompletedMarker, Parser,
};
use self::{attr_set::attr_set, matrix::matrix, vec::vec};
const COLLECTION_START: TokenSet = enum_set!(MAT_KW | L_BRACK | L_BRACE);
pub fn collection(p: &mut Parser) -> Option<CompletedMarker> {
if !COLLECTION_START.contains(p.current()) {
return None;
}
Some(match p.current() {
MAT_KW => matrix(p),
L_BRACK => vec(p),
L_BRACE => attr_set(p),
_ => unreachable!(),
})
}
mod matrix;
mod vec {
use crate::parser::{CompletedMarker, Parser};
pub fn vec(p: &mut Parser) -> CompletedMarker {
todo!()
}
}
mod attr_set {
use crate::parser::{CompletedMarker, Parser};
pub fn attr_set(p: &mut Parser) -> CompletedMarker {
todo!()
}
}
}
pub fn expression(p: &mut Parser) -> Option<CompletedMarker> {
2024-04-24 19:55:16 +02:00
let expr = p.start("expr");
2024-04-24 11:07:38 +02:00
2024-04-24 19:37:52 +02:00
if atom(p).or_else(|| instr(p)).is_none() {
expr.abandon(p);
return None;
}
Some(expr.complete(p, EXPR))
}
2024-04-24 11:07:38 +02:00
2024-04-24 19:37:52 +02:00
pub fn atom(p: &mut Parser) -> Option<CompletedMarker> {
literal(p).or_else(|| collection(p))
2024-04-24 11:07:38 +02:00
}