diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-04-02 22:41:05 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-04-03 22:31:14 +0200 |
commit | 42e667a5086fa4a6557ef7a64e40b833a93f3124 (patch) | |
tree | 1c6a1c3dc9063574e54e30bcb52e7e56aeb27591 /crates/driver/src/parse.rs | |
parent | 89e193c1ab8184f74b2b40f3822e544d5e0d5163 (diff) | |
download | rebel-42e667a5086fa4a6557ef7a64e40b833a93f3124.tar rebel-42e667a5086fa4a6557ef7a64e40b833a93f3124.zip |
driver: parse: introduce TaskID and TaskArgs struct
Make the parser code a bit clearer by not passing around tuples of strs.
Diffstat (limited to 'crates/driver/src/parse.rs')
-rw-r--r-- | crates/driver/src/parse.rs | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/crates/driver/src/parse.rs b/crates/driver/src/parse.rs index aad9360..df540fc 100644 --- a/crates/driver/src/parse.rs +++ b/crates/driver/src/parse.rs @@ -6,14 +6,24 @@ use nom::{ }; #[derive(Debug, Clone, Copy)] -pub struct Task<'a> { +pub struct TaskID<'a> { pub recipe: &'a str, pub task: &'a str, +} + +#[derive(Debug, Clone, Copy, Default)] +pub struct TaskArgs<'a> { pub host: Option<&'a str>, pub target: Option<&'a str>, } #[derive(Debug, Clone, Copy)] +pub struct Task<'a> { + pub id: TaskID<'a>, + pub args: TaskArgs<'a>, +} + +#[derive(Debug, Clone, Copy)] pub struct TaskFlags { pub force_run: bool, } @@ -26,11 +36,11 @@ fn name(input: &str) -> IResult<&str, &str> { take_while1(is_name_char)(input) } -fn task_id(input: &str) -> IResult<&str, (&str, &str)> { +fn task_id(input: &str) -> IResult<&str, TaskID> { let (input, recipe) = name(input)?; let (input, _) = tag(":")(input)?; let (input, task) = name(input)?; - Ok((input, (recipe, task))) + Ok((input, TaskID { recipe, task })) } fn task_arg_target(input: &str) -> IResult<&str, &str> { @@ -39,27 +49,23 @@ fn task_arg_target(input: &str) -> IResult<&str, &str> { Ok((input, target)) } -fn task_args(input: &str) -> IResult<&str, (Option<&str>, Option<&str>)> { +fn task_args(input: &str) -> IResult<&str, TaskArgs> { let (input, _) = tag("/")(input)?; let (input, host) = opt(name)(input)?; let (input, target) = opt(task_arg_target)(input)?; - Ok((input, (host, target))) + Ok((input, TaskArgs { host, target })) } fn task(input: &str) -> IResult<&str, Task> { - let (input, (recipe, task)) = task_id(input)?; + let (input, id) = task_id(input)?; let (input, args) = opt(task_args)(input)?; - let (host, target) = args.unwrap_or_default(); - Ok(( input, Task { - recipe, - task, - host, - target, + id, + args: args.unwrap_or_default(), }, )) } |