feat: formatter

TODO: fix tags with optional body formatter
This commit is contained in:
Artemy Egorov 2024-08-09 18:24:42 +03:00
parent dfe50cd0f4
commit 74f42aa314
12 changed files with 281 additions and 71 deletions

View file

@ -1,6 +1,6 @@
use dalet::{
daletpack::*,
typed::{Hl, TNArg, Tag::*},
typed::{Hl, TNullArg, Tag::*},
};
use flate2::Compression;
use std::io::Write;
@ -41,7 +41,7 @@ fn main() {
]
.into()),
Br,
Code("Hello world".into(), TNArg::Null),
Code("Hello world".into(), TNullArg::Null),
Br,
Ul(vec![
El("abc".into()),

View file

@ -5,7 +5,8 @@
# {~n text} - n is number of minimum spaces to add after trimming with indent
# for each line
#
# {# text} - input not modified
# {#text} - input not modified
#
#
# tag syntax
#
@ -19,6 +20,13 @@
# tag argument
#
# Tags without body and argument also supported
#
#
# custom no tag syntax
#
# {-text} - paragraph, text indent is trimmed
# [[tags]] - element tag with body of multiple tags
# text - element tag with text body
meta "title": Daleth syntax concept
meta "description": This document describes Daleth syntax and some tags
@ -27,19 +35,19 @@ h1: TxtDot revolution
p: TxtDot is a cool project
# If no tag is specified, then the 'el' tag is placed
This is element
br
# if no tag is specified but a '{}' is present, then the 'p' tag is placed
# '\n' is deleted only in this format. If a break line is needed in a paragraph, use ' \n'.
{
# if no tag is specified but a '{- text}' is present, then the 'p' tag is placed
# '\n' is deleted in this format. If a break line is needed in a paragraph, use ' \n'.
{-
Check Dalet too
This is one paragraph
}
{ This is another paragraph }
{- This is another paragraph ({- text\}) }
# ( ) for argument
row "center" [
link "https://github.com/txtdot/txtdot": Homepage
btn "https://example.com/donate" [
@ -51,7 +59,9 @@ row "center" [
# [] for multiple tags
row [
[
# if no tag is specified but a '[[]]' is present, then the 'el' tag
# with multiple tags body placed
[[
h2: Features
ul [
@ -65,13 +75,12 @@ row [
Some kind of Material Design 3
Customization with plugins, see @txtdot/sdk and @txtdot/plugins
]
]]
]
[
[[
h2: Running
[
[[
h3: Dev
# {} for multiline strings, indent is automatically trimmed
@ -87,25 +96,23 @@ row [
# {# Text} Text after "`# " not modified
code "markdown" {# this is codeblock}
]
]]
[
[[
h3: Production
code {
npm install
npm run build
npm run start
}
]
]]
[
[[
h3: Docker
code: docker compose up -d
]
]]
]
]]
]
# Table has custom format if text used

View file

@ -1,6 +1,6 @@
use ariadne::{Color, Label, Report, ReportKind, Source};
use chumsky::Parser;
use dalet::daleth::lexer::lexer;
use dalet::daleth::{format::format, lexer::lexer};
fn main() {
let src_file = "daleth.dlth";
@ -9,7 +9,10 @@ fn main() {
let parsed = lexer().parse(src);
match parsed.into_result() {
Ok(t) => println!("{:#?}", t),
Ok(t) => {
println!("{:#?}", t);
println!("{}", format(&t));
}
Err(e) => e.into_iter().for_each(|e| {
Report::build(ReportKind::Error, src_file, e.span().start)
.with_code("Compiler")
@ -23,5 +26,5 @@ fn main() {
.print((src_file, Source::from(&src)))
.unwrap()
}),
}
};
}