Convert all functions to using the wrapped input type.
This commit is contained in:
@@ -7,6 +7,7 @@ use nom::combinator::verify;
|
||||
use nom::multi::many0;
|
||||
use nom::multi::separated_list0;
|
||||
|
||||
use super::org_source::OrgSource;
|
||||
use super::Context;
|
||||
use crate::error::Res;
|
||||
use crate::parser::object::OrgMacro;
|
||||
@@ -15,7 +16,10 @@ use crate::parser::util::exit_matcher_parser;
|
||||
use crate::parser::util::get_consumed;
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn org_macro<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, OrgMacro<'s>> {
|
||||
pub fn org_macro<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, OrgMacro<'s>> {
|
||||
let (remaining, _) = tag("{{{")(input)?;
|
||||
let (remaining, macro_name) = org_macro_name(context, remaining)?;
|
||||
let (remaining, macro_args) = opt(parser_with_context!(org_macro_args)(context))(remaining)?;
|
||||
@@ -25,15 +29,22 @@ pub fn org_macro<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s st
|
||||
Ok((
|
||||
remaining,
|
||||
OrgMacro {
|
||||
source,
|
||||
macro_name,
|
||||
macro_args: macro_args.unwrap_or_else(|| Vec::with_capacity(0)),
|
||||
source: source.into(),
|
||||
macro_name: macro_name.into(),
|
||||
macro_args: macro_args
|
||||
.unwrap_or_else(|| Vec::with_capacity(0))
|
||||
.into_iter()
|
||||
.map(|arg| arg.into())
|
||||
.collect(),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn org_macro_name<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||
fn org_macro_name<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
let (remaining, _) = verify(anychar, |c| c.is_alphabetic())(input)?;
|
||||
let (remaining, _) = many0(verify(anychar, |c| {
|
||||
c.is_alphanumeric() || *c == '-' || *c == '_'
|
||||
@@ -43,7 +54,10 @@ fn org_macro_name<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s s
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn org_macro_args<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Vec<&'s str>> {
|
||||
fn org_macro_args<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, Vec<OrgSource<'s>>> {
|
||||
let (remaining, _) = tag("(")(input)?;
|
||||
let (remaining, args) =
|
||||
separated_list0(tag(","), parser_with_context!(org_macro_arg)(context))(remaining)?;
|
||||
@@ -53,7 +67,10 @@ fn org_macro_args<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s s
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn org_macro_arg<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||
fn org_macro_arg<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
let mut remaining = input;
|
||||
let mut escaping: bool = false;
|
||||
loop {
|
||||
|
||||
Reference in New Issue
Block a user