Fix headlines parsing and count depth from 0

This commit is contained in:
Renaud Casenave-Péré 2023-01-05 23:02:21 +01:00
parent e65618de08
commit bb9a2da276

View file

@ -50,7 +50,7 @@ namespace sextant
struct headline_depth
{
static constexpr auto rule = dsl::list(dsl::capture(dsl::lit_c<'*'>)) + dsl::ascii::space;
static constexpr auto rule = dsl::list(dsl::capture(dsl::lit_c<'*'>)) + dsl::ascii::blank;
static constexpr auto value = lexy::as_string<std::string>;
};
@ -58,10 +58,10 @@ namespace sextant
{
static constexpr auto rule = dsl::p<headline_depth> + dsl::p<line>;
static constexpr auto value = lexy::callback<cl_object>([](std::string&& depth, lexy::nullopt&&) {
return ast_funcall("MAKE-ORG-HEADLINE", depth.size(), "", depth, "");
return ast_funcall("MAKE-ORG-HEADLINE", depth.size() - 1, "", depth, "");
},
[](std::string&& depth, text_line&& line) {
return ast_funcall ("MAKE-ORG-HEADLINE", depth.size(), to_u32string(line.text), to_u32string(depth + " " + line.text), line.eol);
return ast_funcall ("MAKE-ORG-HEADLINE", depth.size() - 1, to_u32string(line.text), to_u32string(depth + " " + line.text), line.eol);
});
};