Use a single function for finding all keywords.
This commit is contained in:
28
src/parser/in_buffer_settings.rs
Normal file
28
src/parser/in_buffer_settings.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::tag_no_case;
|
||||
use nom::character::complete::anychar;
|
||||
use nom::combinator::map;
|
||||
use nom::multi::many0;
|
||||
use nom::multi::many_till;
|
||||
|
||||
use super::keyword::filtered_keyword;
|
||||
use super::OrgSource;
|
||||
use crate::error::Res;
|
||||
use crate::types::Keyword;
|
||||
|
||||
pub fn scan_for_in_buffer_settings<'s>(
|
||||
input: OrgSource<'s>,
|
||||
) -> Res<OrgSource<'s>, Vec<Keyword<'s>>> {
|
||||
// TODO: Optimization idea: since this is slicing the OrgSource at each character, it might be more efficient to do a parser that uses a search function like take_until, and wrap it in a function similar to consumed but returning the input along with the normal output, then pass all of that into a verify that confirms we were at the start of a line using the input we just returned.
|
||||
|
||||
let keywords = many0(map(
|
||||
many_till(anychar, filtered_keyword(in_buffer_settings_key)),
|
||||
|(_, kw)| kw,
|
||||
))(input);
|
||||
keywords
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn in_buffer_settings_key<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
alt((tag_no_case("todo"), tag_no_case("setupfile")))(input)
|
||||
}
|
||||
Reference in New Issue
Block a user