Implement the first form of LaTeX fragment.
This commit is contained in:
parent
5ad8fdf4b2
commit
c79b8c7833
@ -1,18 +1,21 @@
|
|||||||
use nom::branch::alt;
|
use nom::branch::alt;
|
||||||
use nom::bytes::complete::tag;
|
use nom::bytes::complete::tag;
|
||||||
use nom::bytes::complete::tag_no_case;
|
use nom::character::complete::alpha1;
|
||||||
use nom::character::complete::satisfy;
|
use nom::character::complete::anychar;
|
||||||
|
use nom::character::complete::line_ending;
|
||||||
|
use nom::character::complete::one_of;
|
||||||
use nom::character::complete::space0;
|
use nom::character::complete::space0;
|
||||||
use nom::combinator::eof;
|
use nom::combinator::opt;
|
||||||
use nom::combinator::peek;
|
use nom::combinator::peek;
|
||||||
use nom::combinator::recognize;
|
use nom::combinator::recognize;
|
||||||
|
use nom::multi::many_till;
|
||||||
|
use nom::sequence::tuple;
|
||||||
|
|
||||||
use super::Context;
|
use super::Context;
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
use crate::parser::object::Entity;
|
|
||||||
use crate::parser::parser_with_context::parser_with_context;
|
use crate::parser::parser_with_context::parser_with_context;
|
||||||
|
use crate::parser::util::exit_matcher_parser;
|
||||||
use crate::parser::util::get_consumed;
|
use crate::parser::util::get_consumed;
|
||||||
use crate::parser::util::not_yet_implemented;
|
|
||||||
use crate::parser::LatexFragment;
|
use crate::parser::LatexFragment;
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
@ -20,22 +23,52 @@ pub fn latex_fragment<'r, 's>(
|
|||||||
context: Context<'r, 's>,
|
context: Context<'r, 's>,
|
||||||
input: &'s str,
|
input: &'s str,
|
||||||
) -> Res<&'s str, LatexFragment<'s>> {
|
) -> Res<&'s str, LatexFragment<'s>> {
|
||||||
not_yet_implemented()?;
|
let (remaining, _) = alt((parser_with_context!(raw_latex_fragment)(context),))(input)?;
|
||||||
let (remaining, _) = tag("\\")(input)?;
|
let (remaining, _) = space0(remaining)?;
|
||||||
todo!()
|
let source = get_consumed(input, remaining);
|
||||||
// let (remaining, entity_name) = name(context, remaining)?;
|
Ok((remaining, LatexFragment { source }))
|
||||||
// let (remaining, _) = alt((
|
}
|
||||||
// tag("{}"),
|
|
||||||
// peek(recognize(parser_with_context!(entity_end)(context))),
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
// ))(remaining)?;
|
fn raw_latex_fragment<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||||
// let (remaining, _) = space0(remaining)?;
|
let (remaining, _) = tag("\\")(input)?;
|
||||||
|
let (remaining, _) = name(context, remaining)?;
|
||||||
// let source = get_consumed(input, remaining);
|
let (remaining, _) = opt(parser_with_context!(brackets)(context))(remaining)?;
|
||||||
// Ok((
|
|
||||||
// remaining,
|
let source = get_consumed(input, remaining);
|
||||||
// Entity {
|
Ok((remaining, source))
|
||||||
// source,
|
}
|
||||||
// entity_name,
|
|
||||||
// },
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
// ))
|
fn name<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||||
|
alpha1(input)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
|
fn brackets<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||||
|
let (remaining, body) = alt((
|
||||||
|
recognize(tuple((
|
||||||
|
tag("["),
|
||||||
|
many_till(
|
||||||
|
anychar,
|
||||||
|
peek(alt((
|
||||||
|
parser_with_context!(exit_matcher_parser)(context),
|
||||||
|
alt((recognize(one_of("{}[]")), line_ending)),
|
||||||
|
))),
|
||||||
|
),
|
||||||
|
tag("]"),
|
||||||
|
))),
|
||||||
|
recognize(tuple((
|
||||||
|
tag("{"),
|
||||||
|
many_till(
|
||||||
|
anychar,
|
||||||
|
peek(alt((
|
||||||
|
parser_with_context!(exit_matcher_parser)(context),
|
||||||
|
alt((recognize(one_of("{}")), line_ending)),
|
||||||
|
))),
|
||||||
|
),
|
||||||
|
tag("}"),
|
||||||
|
))),
|
||||||
|
))(input)?;
|
||||||
|
Ok((remaining, body))
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,6 @@ pub struct Entity<'s> {
|
|||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct LatexFragment<'s> {
|
pub struct LatexFragment<'s> {
|
||||||
pub source: &'s str,
|
pub source: &'s str,
|
||||||
pub entity_name: &'s str,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'s> Source<'s> for Object<'s> {
|
impl<'s> Source<'s> for Object<'s> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user