diff options
Diffstat (limited to 'crates/driver/src/parse.rs')
-rw-r--r-- | crates/driver/src/parse.rs | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/crates/driver/src/parse.rs b/crates/driver/src/parse.rs index 892b654..aad9360 100644 --- a/crates/driver/src/parse.rs +++ b/crates/driver/src/parse.rs @@ -5,13 +5,19 @@ use nom::{ Err, IResult, InputLength, Parser, }; -pub struct Output<'a> { +#[derive(Debug, Clone, Copy)] +pub struct Task<'a> { pub recipe: &'a str, pub task: &'a str, pub host: Option<&'a str>, pub target: Option<&'a str>, } +#[derive(Debug, Clone, Copy)] +pub struct TaskFlags { + pub force_run: bool, +} + fn is_name_char(c: char) -> bool { matches!(c, 'a'..='z' | 'A' ..='Z' | '0'..='9' | '_' | '-') } @@ -41,7 +47,7 @@ fn task_args(input: &str) -> IResult<&str, (Option<&str>, Option<&str>)> { Ok((input, (host, target))) } -fn task_ref(input: &str) -> IResult<&str, Output> { +fn task(input: &str) -> IResult<&str, Task> { let (input, (recipe, task)) = task_id(input)?; let (input, args) = opt(task_args)(input)?; @@ -49,7 +55,7 @@ fn task_ref(input: &str) -> IResult<&str, Output> { Ok(( input, - Output { + Task { recipe, task, host, @@ -58,6 +64,24 @@ fn task_ref(input: &str) -> IResult<&str, Output> { )) } +fn task_flags(input: &str) -> IResult<&str, TaskFlags> { + let (input, force_run) = opt(tag("+"))(input)?; + + Ok(( + input, + TaskFlags { + force_run: force_run.is_some(), + }, + )) +} + +fn task_with_flags(input: &str) -> IResult<&str, (Task, TaskFlags)> { + let (input, task) = task(input)?; + let (input, flags) = task_flags(input)?; + + Ok((input, (task, flags))) +} + fn parse_all<I, O, E: ParseError<I>, F>(f: F, input: I) -> Result<O, Err<E>> where I: InputLength, @@ -66,6 +90,6 @@ where all_consuming(f)(input).map(|(_, result)| result) } -pub fn parse_task(input: &str) -> Option<Output> { - parse_all(task_ref, input).ok() +pub fn parse_task_with_flags(input: &str) -> Option<(Task, TaskFlags)> { + parse_all(task_with_flags, input).ok() } |