Populate the name field on elements.
This commit is contained in:
@@ -14,11 +14,14 @@ use nom::combinator::opt;
|
||||
use nom::combinator::peek;
|
||||
use nom::combinator::recognize;
|
||||
use nom::combinator::verify;
|
||||
use nom::multi::many0;
|
||||
use nom::multi::many_till;
|
||||
use nom::multi::separated_list1;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
use super::keyword::affiliated_keyword;
|
||||
use super::org_source::OrgSource;
|
||||
use super::util::get_name;
|
||||
use crate::context::parser_with_context;
|
||||
use crate::context::ContextElement;
|
||||
use crate::context::ContextMatcher;
|
||||
@@ -50,6 +53,7 @@ pub(crate) fn verse_block<'b, 'g, 'r, 's>(
|
||||
context: RefContext<'b, 'g, 'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, VerseBlock<'s>> {
|
||||
let (input, affiliated_keywords) = many0(affiliated_keyword)(input)?;
|
||||
let (remaining, _) = lesser_block_begin("verse")(context, input)?;
|
||||
let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?;
|
||||
let (remaining, _nl) = recognize(tuple((space0, line_ending)))(remaining)?;
|
||||
@@ -93,7 +97,7 @@ pub(crate) fn verse_block<'b, 'g, 'r, 's>(
|
||||
remaining,
|
||||
VerseBlock {
|
||||
source: source.into(),
|
||||
name: None, // TODO
|
||||
name: get_name(&affiliated_keywords),
|
||||
data: parameters.map(|parameters| Into::<&str>::into(parameters)),
|
||||
children,
|
||||
},
|
||||
@@ -105,6 +109,7 @@ pub(crate) fn comment_block<'b, 'g, 'r, 's>(
|
||||
context: RefContext<'b, 'g, 'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, CommentBlock<'s>> {
|
||||
let (input, affiliated_keywords) = many0(affiliated_keyword)(input)?;
|
||||
let (remaining, _) = lesser_block_begin("comment")(context, input)?;
|
||||
let (remaining, _parameters) = opt(tuple((space1, data)))(remaining)?;
|
||||
let (remaining, _nl) = recognize(tuple((space0, line_ending)))(remaining)?;
|
||||
@@ -129,7 +134,7 @@ pub(crate) fn comment_block<'b, 'g, 'r, 's>(
|
||||
remaining,
|
||||
CommentBlock {
|
||||
source: source.into(),
|
||||
name: None, // TODO
|
||||
name: get_name(&affiliated_keywords),
|
||||
contents: contents.into(),
|
||||
},
|
||||
))
|
||||
@@ -140,6 +145,7 @@ pub(crate) fn example_block<'b, 'g, 'r, 's>(
|
||||
context: RefContext<'b, 'g, 'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, ExampleBlock<'s>> {
|
||||
let (input, affiliated_keywords) = many0(affiliated_keyword)(input)?;
|
||||
let (remaining, _) = lesser_block_begin("example")(context, input)?;
|
||||
let (remaining, parameters) = opt(tuple((space1, example_switches)))(remaining)?;
|
||||
let (remaining, _nl) = recognize(tuple((space0, line_ending)))(remaining)?;
|
||||
@@ -183,7 +189,7 @@ pub(crate) fn example_block<'b, 'g, 'r, 's>(
|
||||
remaining,
|
||||
ExampleBlock {
|
||||
source: source.into(),
|
||||
name: None, // TODO
|
||||
name: get_name(&affiliated_keywords),
|
||||
switches,
|
||||
number_lines,
|
||||
preserve_indent,
|
||||
@@ -200,6 +206,7 @@ pub(crate) fn export_block<'b, 'g, 'r, 's>(
|
||||
context: RefContext<'b, 'g, 'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, ExportBlock<'s>> {
|
||||
let (input, affiliated_keywords) = many0(affiliated_keyword)(input)?;
|
||||
let (remaining, _) = lesser_block_begin("export")(context, input)?;
|
||||
// https://orgmode.org/worg/org-syntax.html#Blocks claims that export blocks must have a single word for data but testing shows no data and multi-word data still parses as an export block.
|
||||
let (remaining, parameters) = opt(tuple((space1, data)))(remaining)?;
|
||||
@@ -229,7 +236,7 @@ pub(crate) fn export_block<'b, 'g, 'r, 's>(
|
||||
remaining,
|
||||
ExportBlock {
|
||||
source: source.into(),
|
||||
name: None, // TODO
|
||||
name: get_name(&affiliated_keywords),
|
||||
data: parameters.map(|parameters| Into::<&str>::into(parameters)),
|
||||
contents: contents.into(),
|
||||
},
|
||||
@@ -241,6 +248,7 @@ pub(crate) fn src_block<'b, 'g, 'r, 's>(
|
||||
context: RefContext<'b, 'g, 'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, SrcBlock<'s>> {
|
||||
let (input, affiliated_keywords) = many0(affiliated_keyword)(input)?;
|
||||
let (remaining, _) = lesser_block_begin("src")(context, input)?;
|
||||
// https://orgmode.org/worg/org-syntax.html#Blocks claims that data is mandatory and must follow the LANGUAGE SWITCHES ARGUMENTS pattern but testing has shown that no data and incorrect data here will still parse to a src block.
|
||||
let (remaining, language) = opt(map(tuple((space1, switch_word(true))), |(_, language)| {
|
||||
@@ -289,7 +297,7 @@ pub(crate) fn src_block<'b, 'g, 'r, 's>(
|
||||
remaining,
|
||||
SrcBlock {
|
||||
source: source.into(),
|
||||
name: None, // TODO
|
||||
name: get_name(&affiliated_keywords),
|
||||
language: language.map(Into::<&str>::into),
|
||||
switches,
|
||||
parameters: parameters.map(Into::<&str>::into),
|
||||
|
||||
Reference in New Issue
Block a user