fix: errors

This commit is contained in:
Artemy Egorov 2024-08-12 17:46:57 +03:00
parent 50f5c7fe19
commit ebc47a2c27
2 changed files with 58 additions and 20 deletions

View file

@ -1,5 +1,5 @@
use ariadne::{Color, Label, Report, ReportKind, Source};
use chumsky::{input::Input, Parser};
use chumsky::{error::RichReason, input::Input, Parser};
use dalet::daleth::{lexer::lexer, parser::parser};
fn main() {
@ -12,16 +12,19 @@ fn main() {
match parsed.into_result() {
Ok(t) => {
println!("{:#?}", t);
// println!("{}", format(&t));
}
Err(e) => e.into_iter().for_each(|e| {
// println!("{:#}", )
let msg = match e.reason() {
RichReason::Many(errs) => errs[0].to_string(),
_ => e.to_string(),
};
Report::build(ReportKind::Error, src_file, e.span().start)
.with_code("Parser")
.with_message(e.to_string())
.with_label(
Label::new((src_file, e.span().into_range()))
.with_message(e.to_string())
.with_message(&msg)
.with_color(Color::Red),
)
.finish()

View file

@ -26,44 +26,78 @@ pub fn tag<'tokens, 'src: 'tokens>(
.clone()
.repeated()
.collect()
.delimited_by(just(Token::LSquare), just(Token::RSquare));
.delimited_by(just(Token::LSquare), just(Token::RSquare))
.labelled("Tags body");
let text_body = select! {
Token::TextBody(t) => t.to_owned(),
Token::MLText(t) => trim_indent(t).to_owned(),
Token::MLMSText(n, t) => set_spaces(t, n).to_owned(),
Token::MLRText(t) => t.to_owned()
};
}
.labelled("Text body");
let nnbody = text_body
.map(NNBody::Text)
.or(tags_body.clone().map(NNBody::Tags));
.or(tags_body.clone().map(NNBody::Tags))
.labelled("Not null body");
let body = text_body
.map(Body::Text)
.or(tags_body.clone().map(Body::Tags))
.or_not()
.to(Body::Null);
.to(Body::Null)
.labelled("Body");
let num_arg = select! {
Token::NumberArgument(n) => n
};
}
.labelled("Number argument");
let text_arg = select! {
Token::TextArgument(t) => t.to_owned()
};
}
.labelled("Text argument");
let nnarg = text_arg.map(NNArg::Text).or(num_arg.map(NNArg::Number));
let nnarg = text_arg
.map(NNArg::Text)
.or(num_arg.map(NNArg::Number))
.labelled("Not null argument");
let tnullarg = text_arg
.map(TNullArg::Text)
.or_not()
.map(|v| v.unwrap_or(TNullArg::Null));
let hlarg = num_arg.try_map(|n, s| Hl::try_from(n).map_err(|e| Rich::custom(s, e)));
let alignarg = choice((
just(Token::TextArgument("start")).to(AlignArg::Start),
just(Token::TextArgument("center")).to(AlignArg::Start),
just(Token::TextArgument("end")).to(AlignArg::Start),
.map(|v| v.unwrap_or(TNullArg::Null))
.labelled("Text or null argument");
let hlarg = num_arg
.validate(|n, e, emmiter| match Hl::try_from(n) {
Ok(l) => l,
Err(_) => {
emmiter.emit(Rich::custom(
e.span(),
"Heading level must be between 1 and 6",
));
Hl::One
}
})
.labelled("Heading level argument");
let alignarg = text_arg
.clone()
.validate(|t, e, emmiter| match t.as_str() {
"start" => AlignArg::Start,
"center" => AlignArg::Center,
"end" => AlignArg::End,
_ => {
emmiter.emit(Rich::custom(
e.span(),
"Expected 'start', 'center' or 'end'",
));
AlignArg::Start
}
})
.labelled("Align argument");
let el = just(Token::El).ignore_then(nnbody.clone()).map(El);
let h = just(Token::H)
@ -141,7 +175,8 @@ pub fn tag<'tokens, 'src: 'tokens>(
let paragraph = select! {
Token::Paragraph(t) => P(NNBody::Text(t.replace("\n", " ").trim().to_owned()))
};
}
.labelled("Paragraph");
choice((
el, h, p, br, ul, ol, row, link, navlink, btn, navbtn, img, table, tcol, tpcol, hr, b,