lang: basic attrset parser

This commit is contained in:
Schrottkatze 2024-04-30 10:18:59 +02:00
parent 9af71ed3f4
commit db2643359c
Signed by: schrottkatze
SSH key fingerprint: SHA256:hXb3t1vINBFCiDCmhRABHX5ocdbLiKyCdKI4HK2Rbbc

View file

@ -1,5 +1,45 @@
use crate::parser::{CompletedMarker, Parser};
use crate::parser::{
error::SyntaxError,
grammar::expression::{atom, expression},
CompletedMarker, Marker, Parser,
SyntaxKind::*,
};
pub fn attr_set(p: &mut Parser) -> CompletedMarker {
todo!()
let start = p.start("attr_set_start");
assert!(p.eat(L_BRACE));
loop {
if attr(p).is_some() {
// TODO: handle others
if p.eat(COMMA) {
continue;
} else if p.eat(R_BRACE) {
return start.complete(p, ATTR_SET);
}
// TODO: check for newline and stuff following that for recov of others
} else if p.eat(R_BRACE) {
return start.complete(p, ATTR_SET);
}
}
}
fn attr(p: &mut Parser) -> Option<CompletedMarker> {
if p.at(IDENT) {
let attr_start = p.start("attr");
let attr_name_start = p.start("attr_name");
p.do_bump();
attr_name_start.complete(p, ATTR_NAME);
// TODO: handle comma, expr/atom, other
p.eat(COLON);
// TODO: handle failed expr parser too
let attr_value = p.start("attr_value");
let _ = expression(p);
attr_value.complete(p, ATTR_VALUE);
Some(attr_start.complete(p, ATTR))
} else {
None
}
}