Scan for setupfile at the beginning of a parse.

This commit is contained in:
Tom Alexander 2023-09-04 12:48:59 -04:00
parent 7f6f22717b
commit a8f277efe5
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 38 additions and 0 deletions

View File

@ -19,6 +19,7 @@ use nom::multi::separated_list1;
use nom::sequence::tuple; use nom::sequence::tuple;
use super::org_source::OrgSource; use super::org_source::OrgSource;
use super::setup_file::scan_for_setup_file;
use super::token::AllTokensIterator; use super::token::AllTokensIterator;
use super::token::Token; use super::token::Token;
use super::util::exit_matcher_parser; use super::util::exit_matcher_parser;
@ -78,6 +79,11 @@ fn document_org_source<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>, context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Document<'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) = let (remaining, document) =
_document(context, input).map(|(rem, out)| (Into::<&str>::into(rem), out))?; _document(context, input).map(|(rem, out)| (Into::<&str>::into(rem), out))?;
{ {

View File

@ -33,6 +33,7 @@ mod planning;
mod property_drawer; mod property_drawer;
mod radio_link; mod radio_link;
mod regular_link; mod regular_link;
mod setup_file;
pub mod sexp; pub mod sexp;
mod statistics_cookie; mod statistics_cookie;
mod subscript_and_superscript; mod subscript_and_superscript;

31
src/parser/setup_file.rs Normal file
View 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))
}