Scan for setupfile at the beginning of a parse.
This commit is contained in:
parent
7f6f22717b
commit
a8f277efe5
@ -19,6 +19,7 @@ use nom::multi::separated_list1;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
use super::org_source::OrgSource;
|
||||
use super::setup_file::scan_for_setup_file;
|
||||
use super::token::AllTokensIterator;
|
||||
use super::token::Token;
|
||||
use super::util::exit_matcher_parser;
|
||||
@ -78,6 +79,11 @@ fn document_org_source<'b, 'g, 'r, 's>(
|
||||
context: RefContext<'b, 'g, 'r, 's>,
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, Document<'s>> {
|
||||
let setup_file = scan_for_setup_file(input);
|
||||
if setup_file.is_ok() {
|
||||
let (_remaining, setup_file) = setup_file.expect("If-statement proves this is okay.");
|
||||
println!("TODO: Process setup_file: {}", setup_file);
|
||||
}
|
||||
let (remaining, document) =
|
||||
_document(context, input).map(|(rem, out)| (Into::<&str>::into(rem), out))?;
|
||||
{
|
||||
|
@ -33,6 +33,7 @@ mod planning;
|
||||
mod property_drawer;
|
||||
mod radio_link;
|
||||
mod regular_link;
|
||||
mod setup_file;
|
||||
pub mod sexp;
|
||||
mod statistics_cookie;
|
||||
mod subscript_and_superscript;
|
||||
|
31
src/parser/setup_file.rs
Normal file
31
src/parser/setup_file.rs
Normal file
@ -0,0 +1,31 @@
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::is_not;
|
||||
use nom::bytes::complete::tag_no_case;
|
||||
use nom::character::complete::anychar;
|
||||
use nom::character::complete::line_ending;
|
||||
use nom::character::complete::space1;
|
||||
use nom::combinator::eof;
|
||||
use nom::multi::many_till;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
use super::OrgSource;
|
||||
use crate::error::Res;
|
||||
use crate::parser::util::start_of_line;
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
pub fn scan_for_setup_file<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
let (remaining, setup) = many_till(anychar, setup_file)(input)
|
||||
.map(|(remaining, (_, setup_file))| (remaining, setup_file))?;
|
||||
Ok((remaining, setup))
|
||||
}
|
||||
|
||||
fn setup_file<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
let (remaining, (_, _, _, setup_file, _)) = tuple((
|
||||
start_of_line,
|
||||
tag_no_case("#+SETUPFILE:"),
|
||||
space1,
|
||||
is_not("\r\n"),
|
||||
alt((line_ending, eof)),
|
||||
))(input)?;
|
||||
Ok((remaining, setup_file))
|
||||
}
|
Loading…
Reference in New Issue
Block a user