fix: lexer, parser align, create parser example

This commit is contained in:
Artemy Egorov 2024-08-12 13:20:46 +03:00
parent 9592a8ffba
commit 50f5c7fe19
7 changed files with 132 additions and 32 deletions

View file

@ -96,8 +96,8 @@ row [
this is codeblock
}
# {# Text} Text after "`# " not modified
code "markdown" {# this is codeblock}
# {# Text} Text after "{#" not modified
code "markdown" {# this is codeblock}
]]
[[
@ -125,14 +125,14 @@ row [
# Element
# Description
# ]
table {
+| Tag | Description |
| h | Heading |
| p | Paragraph |
| img | Image |
| link | Link |
| btn | Button |
| ul | Unordered list |
| br | Line break |
+| quantity | 7 |
}
# table {
# +| Tag | Description |
# | h | Heading |
# | p | Paragraph |
# | img | Image |
# | link | Link |
# | btn | Button |
# | ul | Unordered list |
# | br | Line break |
# +| quantity | 7 |
# }

View file

@ -15,7 +15,7 @@ fn main() {
}
Err(e) => e.into_iter().for_each(|e| {
Report::build(ReportKind::Error, src_file, e.span().start)
.with_code("Compiler")
.with_code("Lexer")
.with_message(e.to_string().clone())
.with_label(
Label::new((src_file, e.span().into_range()))

32
examples/daleth_parser.rs Normal file
View file

@ -0,0 +1,32 @@
use ariadne::{Color, Label, Report, ReportKind, Source};
use chumsky::{input::Input, Parser};
use dalet::daleth::{lexer::lexer, parser::parser};
fn main() {
let src_file = "daleth.dlth";
let src = include_str!("./daleth.dlth");
let lexed = lexer().parse(src).unwrap();
let parsed = parser().parse(lexed.as_slice().spanned((0..src.len()).into()));
match parsed.into_result() {
Ok(t) => {
println!("{:#?}", t);
// println!("{}", format(&t));
}
Err(e) => e.into_iter().for_each(|e| {
// println!("{:#}", )
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_color(Color::Red),
)
.finish()
.print((src_file, Source::from(&src)))
.unwrap()
}),
};
}