From 1671d0fbf3b5691f2db44883a0973ec858beaf94 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 5 Nov 2021 17:02:26 +0100 Subject: driver: replace regex with nom-based parser For now, the nom-based parser doesn't really reduce complexity, but we will need a more powerful parsing solution anyways when the task YML is replaced with a specialized language. --- crates/driver/src/context.rs | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) (limited to 'crates/driver/src/context.rs') diff --git a/crates/driver/src/context.rs b/crates/driver/src/context.rs index ccb8581..bd8d985 100644 --- a/crates/driver/src/context.rs +++ b/crates/driver/src/context.rs @@ -8,16 +8,13 @@ use std::{ result, }; -use lazy_static::lazy_static; -use regex::Regex; - use common::{ error::{self, Contextualizable}, string_hash::ArchiveHash, types::TaskID, }; -use crate::{args::*, paths, pin::Pins, task::*}; +use crate::{args::*, parse, paths, pin::Pins, task::*}; #[derive(Debug, Clone, Copy)] pub enum ErrorKind<'ctx> { @@ -347,16 +344,10 @@ impl Context { } pub fn parse<'ctx>(&'ctx self, s: &str) -> error::Result { - lazy_static! { - static ref RE: Regex = Regex::new( - r"^(?P[[:word:]-]+):(?P[[:word:]-]+)(?:/(?P[[:word:]-]+)?(?::(?P[[:word:]-]+))?)?$", - ).unwrap(); - } - - let cap = RE.captures(s).context("Invalid task syntax")?; + let parsed = parse::parse_task(s).context("Invalid task syntax")?; - let recipe = cap["recipe"].to_string(); - let task = cap["task"].to_string(); + let recipe = parsed.recipe.to_string(); + let task = parsed.task.to_string(); let id = TaskID { recipe, task }; let (ctx_id, _) = self @@ -366,19 +357,19 @@ impl Context { let mut args = self.globals.clone(); - if let Some(host) = cap.name("host") { + if let Some(host) = parsed.host { let plat = self .platforms - .get(host.as_str()) - .with_context(|| format!("Platform '{}' not found", host.as_str()))?; + .get(host) + .with_context(|| format!("Platform '{}' not found", host))?; args.set("host", Some(plat)); args.set("target", Some(plat)); } - if let Some(target) = cap.name("target") { + if let Some(target) = parsed.target { let plat = self .platforms - .get(target.as_str()) - .with_context(|| format!("Platform '{}' not found", target.as_str()))?; + .get(target) + .with_context(|| format!("Platform '{}' not found", target))?; args.set("target", Some(plat)); } -- cgit v1.2.3