Separate babel call out to its own parser.
This commit is contained in:
parent
f49a1853ad
commit
343af41f78
@ -2416,6 +2416,7 @@ fn compare_babel_call<'b, 's>(
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compare value
|
||||||
let value = unquote(
|
let value = unquote(
|
||||||
get_property(emacs, ":value")?
|
get_property(emacs, ":value")?
|
||||||
.ok_or("Emacs keywords should have a :value")?
|
.ok_or("Emacs keywords should have a :value")?
|
||||||
|
59
src/parser/babel_call.rs
Normal file
59
src/parser/babel_call.rs
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
use nom::bytes::complete::tag;
|
||||||
|
use nom::bytes::complete::tag_no_case;
|
||||||
|
use nom::character::complete::anychar;
|
||||||
|
use nom::character::complete::space0;
|
||||||
|
use nom::combinator::consumed;
|
||||||
|
use nom::combinator::peek;
|
||||||
|
use nom::combinator::recognize;
|
||||||
|
use nom::multi::many0;
|
||||||
|
use nom::multi::many_till;
|
||||||
|
use nom::sequence::tuple;
|
||||||
|
use nom::InputTake;
|
||||||
|
|
||||||
|
use super::keyword::affiliated_keyword;
|
||||||
|
use super::util::get_name;
|
||||||
|
use super::OrgSource;
|
||||||
|
use crate::context::RefContext;
|
||||||
|
use crate::error::Res;
|
||||||
|
use crate::parser::util::get_consumed;
|
||||||
|
use crate::parser::util::org_line_ending;
|
||||||
|
use crate::types::BabelCall;
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
|
pub(crate) fn babel_call<'b, 'g, 'r, 's>(
|
||||||
|
_context: RefContext<'b, 'g, 'r, 's>,
|
||||||
|
input: OrgSource<'s>,
|
||||||
|
) -> Res<OrgSource<'s>, BabelCall<'s>> {
|
||||||
|
let (input, affiliated_keywords) = many0(affiliated_keyword)(input)?;
|
||||||
|
|
||||||
|
let (remaining, (consumed_input, (_, _, parsed_key, _))) =
|
||||||
|
consumed(tuple((space0, tag("#+"), tag_no_case("call"), tag(":"))))(input)?;
|
||||||
|
|
||||||
|
if let Ok((remaining, (_, line_break))) = tuple((space0, org_line_ending))(remaining) {
|
||||||
|
let source = get_consumed(input, remaining);
|
||||||
|
return Ok((
|
||||||
|
remaining,
|
||||||
|
BabelCall {
|
||||||
|
source: Into::<&str>::into(source),
|
||||||
|
name: get_name(&affiliated_keywords),
|
||||||
|
value: Into::<&str>::into(line_break.take(0)),
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
let (remaining, _ws) = space0(remaining)?;
|
||||||
|
let (remaining, parsed_value) =
|
||||||
|
recognize(many_till(anychar, peek(tuple((space0, org_line_ending)))))(remaining)?;
|
||||||
|
let (remaining, _ws) = tuple((space0, org_line_ending))(remaining)?;
|
||||||
|
|
||||||
|
let source = get_consumed(input, remaining);
|
||||||
|
|
||||||
|
Ok((
|
||||||
|
remaining,
|
||||||
|
BabelCall {
|
||||||
|
source: Into::<&str>::into(source),
|
||||||
|
name: get_name(&affiliated_keywords),
|
||||||
|
value: Into::<&str>::into(parsed_value),
|
||||||
|
},
|
||||||
|
))
|
||||||
|
}
|
@ -6,6 +6,7 @@ use nom::sequence::tuple;
|
|||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
use tracing::span;
|
use tracing::span;
|
||||||
|
|
||||||
|
use super::babel_call::babel_call;
|
||||||
use super::clock::clock;
|
use super::clock::clock;
|
||||||
use super::comment::comment;
|
use super::comment::comment;
|
||||||
use super::comment::detect_comment;
|
use super::comment::detect_comment;
|
||||||
@ -20,7 +21,6 @@ use super::footnote_definition::footnote_definition;
|
|||||||
use super::greater_block::greater_block;
|
use super::greater_block::greater_block;
|
||||||
use super::horizontal_rule::horizontal_rule;
|
use super::horizontal_rule::horizontal_rule;
|
||||||
use super::keyword::affiliated_keyword;
|
use super::keyword::affiliated_keyword;
|
||||||
use super::keyword::babel_call_keyword;
|
|
||||||
use super::keyword::keyword;
|
use super::keyword::keyword;
|
||||||
use super::latex_environment::latex_environment;
|
use super::latex_environment::latex_environment;
|
||||||
use super::lesser_block::comment_block;
|
use super::lesser_block::comment_block;
|
||||||
@ -76,7 +76,7 @@ fn _element<'b, 'g, 'r, 's>(
|
|||||||
let fixed_width_area_matcher = parser_with_context!(fixed_width_area)(context);
|
let fixed_width_area_matcher = parser_with_context!(fixed_width_area)(context);
|
||||||
let horizontal_rule_matcher = parser_with_context!(horizontal_rule)(context);
|
let horizontal_rule_matcher = parser_with_context!(horizontal_rule)(context);
|
||||||
let keyword_matcher = parser_with_context!(keyword)(context);
|
let keyword_matcher = parser_with_context!(keyword)(context);
|
||||||
let babel_keyword_matcher = parser_with_context!(babel_call_keyword)(context);
|
let babel_keyword_matcher = parser_with_context!(babel_call)(context);
|
||||||
let paragraph_matcher = parser_with_context!(paragraph)(context);
|
let paragraph_matcher = parser_with_context!(paragraph)(context);
|
||||||
let latex_environment_matcher = parser_with_context!(latex_environment)(context);
|
let latex_environment_matcher = parser_with_context!(latex_environment)(context);
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ use crate::error::CustomError;
|
|||||||
use crate::error::MyError;
|
use crate::error::MyError;
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
use crate::parser::util::start_of_line;
|
use crate::parser::util::start_of_line;
|
||||||
use crate::types::BabelCall;
|
|
||||||
use crate::types::Keyword;
|
use crate::types::Keyword;
|
||||||
|
|
||||||
const ORG_ELEMENT_AFFILIATED_KEYWORDS: [&'static str; 13] = [
|
const ORG_ELEMENT_AFFILIATED_KEYWORDS: [&'static str; 13] = [
|
||||||
@ -104,29 +103,6 @@ pub(crate) fn affiliated_keyword<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>,
|
|||||||
filtered_keyword(affiliated_key)(input)
|
filtered_keyword(affiliated_key)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
|
||||||
pub(crate) fn babel_call_keyword<'b, 'g, 'r, 's>(
|
|
||||||
_context: RefContext<'b, 'g, 'r, 's>,
|
|
||||||
input: OrgSource<'s>,
|
|
||||||
) -> Res<OrgSource<'s>, BabelCall<'s>> {
|
|
||||||
let (input, affiliated_keywords) = many0(affiliated_keyword)(input)?;
|
|
||||||
let (remaining, kw) = filtered_keyword(babel_call_key)(input)?;
|
|
||||||
Ok((
|
|
||||||
remaining,
|
|
||||||
BabelCall {
|
|
||||||
source: kw.source,
|
|
||||||
name: get_name(&affiliated_keywords),
|
|
||||||
key: kw.key,
|
|
||||||
value: kw.value,
|
|
||||||
},
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
|
||||||
fn babel_call_key<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
|
||||||
tag_no_case("call")(input)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
pub(crate) fn table_formula_keyword<'b, 'g, 'r, 's>(
|
pub(crate) fn table_formula_keyword<'b, 'g, 'r, 's>(
|
||||||
_context: RefContext<'b, 'g, 'r, 's>,
|
_context: RefContext<'b, 'g, 'r, 's>,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
mod angle_link;
|
mod angle_link;
|
||||||
|
mod babel_call;
|
||||||
mod citation;
|
mod citation;
|
||||||
mod citation_reference;
|
mod citation_reference;
|
||||||
mod clock;
|
mod clock;
|
||||||
|
@ -138,7 +138,6 @@ pub struct Keyword<'s> {
|
|||||||
pub struct BabelCall<'s> {
|
pub struct BabelCall<'s> {
|
||||||
pub source: &'s str,
|
pub source: &'s str,
|
||||||
pub name: Option<&'s str>,
|
pub name: Option<&'s str>,
|
||||||
pub key: &'s str,
|
|
||||||
pub value: &'s str,
|
pub value: &'s str,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user