Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
chumsky = "0.9.3"
itertools = "0.13.0"
serde = { version = "1.0.203", features = ["derive"] }
textwrap = "0.16.1"
unicode_categories = "0.1.1"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use chumsky::Parser as _;
use error::NorgParseError;

pub use crate::stage_1::stage_1;
use crate::stage_2::stage_2;
pub use crate::stage_2::stage_2;
use crate::stage_4::stage_4;

pub use crate::stage_2::ParagraphSegmentToken;
Expand Down
2 changes: 1 addition & 1 deletion src/snapshots/rust_norg__tests__ranged_verbatim_tags.snap
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ expression: examples
- first-parameter
- "#&*(&$!)"
- third-parameter
content: "function hello()\nprint(\"Hello World\")\nend hello()\n"
content: "function hello()\n print(\"Hello World\")\nend\n\nhello()\n"
4 changes: 1 addition & 3 deletions src/stage_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl std::fmt::Display for NorgToken {
Self::End(c) => write!(f, "{}end", c),
Self::Eof => f.write_char('\0'),
Self::Escape(c) => write!(f, "\\{}", c),
Self::Newlines(count) => f.write_str(&" ".repeat(*count as usize)),
Self::Newlines(count) => f.write_str(&"\n".repeat(*count as usize)),
Self::Regular(c) | Self::Special(c) => f.write_char(*c),
Self::SingleNewline => f.write_char('\n'),
Self::Whitespace(count) => f.write_str(&" ".repeat(*count as usize)),
Expand Down Expand Up @@ -61,13 +61,11 @@ pub fn stage_1() -> impl Parser<char, Vec<NorgToken>, Error = chumsky::error::Si
});

let newline = parse_newline
.then_ignore(ws.repeated())
.to(NorgToken::SingleNewline);

let newlines = parse_newline
.repeated()
.at_least(2)
.then_ignore(ws.repeated())
.map(|content| NorgToken::Newlines(content.len() as u16));

let special = one_of(SPECIAL_CHARS).map(NorgToken::Special);
Expand Down
5 changes: 3 additions & 2 deletions src/stage_3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::fmt::Write;
use chumsky::prelude::*;
use itertools::Itertools;
use serde::Serialize;
use textwrap::dedent;

use crate::stage_2::{NorgBlock, ParagraphSegmentToken, ParagraphTokenList};

Expand Down Expand Up @@ -141,7 +142,7 @@ fn paragraph_parser_opener_candidates_and_links() -> impl Parser<
.at_least(1),
)
.then_ignore(just(ParagraphSegmentToken::Special('`')))
.map(|content| ParagraphSegment::InlineVerbatim(content));
.map(ParagraphSegment::InlineVerbatim);

let anchor = just(ParagraphSegmentToken::Special('['))
.ignore_then(
Expand Down Expand Up @@ -717,7 +718,7 @@ pub fn stage_3(
NorgASTFlat::VerbatimRangedTag {
name: stringify_tokens_and_split(name),
parameters: parameters.unwrap_or_default().into_iter().map(|parameter| parameter.into_iter().map_into::<String>().collect()).collect(),
content: content.into_iter().map_into::<String>().collect(),
content: dedent(content.into_iter().map_into::<String>().collect::<String>().as_str()),
}
},
};
Expand Down