use std::collections::
This commit is contained in:
parent
2d8e3d9abe
commit
8ec000c159
21
src/main.rs
21
src/main.rs
@ -2,7 +2,8 @@ extern crate regex;
|
|||||||
|
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
|
|
||||||
use std::{io, fs, env, collections};
|
use std::{io, fs, env};
|
||||||
|
use std::collections::{HashSet, BTreeMap};
|
||||||
|
|
||||||
macro_rules! warn {
|
macro_rules! warn {
|
||||||
($($arg:tt)*) => {{
|
($($arg:tt)*) => {{
|
||||||
@ -28,21 +29,21 @@ struct Recipe<'a> {
|
|||||||
name: &'a str,
|
name: &'a str,
|
||||||
leading_whitespace: &'a str,
|
leading_whitespace: &'a str,
|
||||||
commands: Vec<&'a str>,
|
commands: Vec<&'a str>,
|
||||||
dependencies: collections::HashSet<&'a str>,
|
dependencies: HashSet<&'a str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Resolver<'a> {
|
struct Resolver<'a> {
|
||||||
recipes: &'a collections::BTreeMap<&'a str, Recipe<'a>>,
|
recipes: &'a BTreeMap<&'a str, Recipe<'a>>,
|
||||||
resolved: collections::HashSet<&'a str>,
|
resolved: HashSet<&'a str>,
|
||||||
seen: collections::HashSet<&'a str>,
|
seen: HashSet<&'a str>,
|
||||||
stack: Vec<&'a str>,
|
stack: Vec<&'a str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve<'a> (recipes: &'a collections::BTreeMap<&'a str, Recipe<'a>>) {
|
fn resolve<'a> (recipes: &'a BTreeMap<&'a str, Recipe<'a>>) {
|
||||||
let mut resolver = Resolver {
|
let mut resolver = Resolver {
|
||||||
recipes: recipes,
|
recipes: recipes,
|
||||||
resolved: collections::HashSet::new(),
|
resolved: HashSet::new(),
|
||||||
seen: collections::HashSet::new(),
|
seen: HashSet::new(),
|
||||||
stack: vec![],
|
stack: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -114,7 +115,7 @@ fn main() {
|
|||||||
let name_re = re(r"^[a-z](-[a-z]|[a-z])*$");
|
let name_re = re(r"^[a-z](-[a-z]|[a-z])*$");
|
||||||
let whitespace_re = re(r"\s+");
|
let whitespace_re = re(r"\s+");
|
||||||
|
|
||||||
let mut recipes = collections::BTreeMap::new();
|
let mut recipes = BTreeMap::new();
|
||||||
let mut current_recipe: Option<Recipe> = None;
|
let mut current_recipe: Option<Recipe> = None;
|
||||||
for (i, line) in contents.lines().enumerate() {
|
for (i, line) in contents.lines().enumerate() {
|
||||||
if blank_re.is_match(line) {
|
if blank_re.is_match(line) {
|
||||||
@ -150,7 +151,7 @@ fn main() {
|
|||||||
} else if let Some(captures) = label_re.captures(line) {
|
} else if let Some(captures) = label_re.captures(line) {
|
||||||
let name = captures.at(1).unwrap();
|
let name = captures.at(1).unwrap();
|
||||||
let rest = captures.at(3).unwrap().trim();
|
let rest = captures.at(3).unwrap().trim();
|
||||||
let mut dependencies = collections::HashSet::new();
|
let mut dependencies = HashSet::new();
|
||||||
for part in whitespace_re.split(rest) {
|
for part in whitespace_re.split(rest) {
|
||||||
if name_re.is_match(part) {
|
if name_re.is_match(part) {
|
||||||
if dependencies.contains(part) {
|
if dependencies.contains(part) {
|
||||||
|
Loading…
Reference in New Issue
Block a user