mirror of
https://github.com/zaphar/kitchen.git
synced 2025-07-22 19:40:14 -04:00
disable macro-error diagnostic for this workspace.
This commit is contained in:
parent
821cc098fb
commit
b21bdd0252
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"rust-analyzer.diagnostics.disabled": [
|
||||||
|
"macro-error"
|
||||||
|
]
|
||||||
|
}
|
@ -11,7 +11,7 @@
|
|||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
mod parse;
|
pub mod parse;
|
||||||
pub mod unit;
|
pub mod unit;
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
@ -20,7 +20,7 @@ use std::str::FromStr;
|
|||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use uuid::{self, Uuid};
|
use uuid::{self, Uuid};
|
||||||
|
|
||||||
use parse::{ingredient, measure};
|
use parse::*;
|
||||||
use unit::*;
|
use unit::*;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
@ -141,6 +141,14 @@ impl Step {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_ingredients<Iter>(mut self, ingredients: Iter) -> Step
|
||||||
|
where
|
||||||
|
Iter: IntoIterator<Item = Ingredient>,
|
||||||
|
{
|
||||||
|
self.add_ingredients(ingredients);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn add_ingredients<Iter>(&mut self, ingredients: Iter)
|
pub fn add_ingredients<Iter>(&mut self, ingredients: Iter)
|
||||||
where
|
where
|
||||||
Iter: IntoIterator<Item = Ingredient>,
|
Iter: IntoIterator<Item = Ingredient>,
|
||||||
|
@ -21,9 +21,81 @@ use num_rational::Ratio;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
unit::{Measure, Measure::*, Quantity, VolumeMeasure::*},
|
unit::{Measure, Measure::*, Quantity, VolumeMeasure::*},
|
||||||
Ingredient,
|
Ingredient, Recipe, Step,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
make_fn!(
|
||||||
|
pub recipe<StrIter, Recipe>,
|
||||||
|
do_each!(
|
||||||
|
title => title,
|
||||||
|
_ => optional!(para_separator),
|
||||||
|
desc => optional!(do_each!(
|
||||||
|
_ => peek!(not!(step_prefix)),
|
||||||
|
desc => description,
|
||||||
|
(desc)
|
||||||
|
)),
|
||||||
|
_ => optional!(para_separator),
|
||||||
|
steps => step_list,
|
||||||
|
(Recipe::new(title, desc).with_steps(steps))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
make_fn!(
|
||||||
|
pub title<StrIter, &str>,
|
||||||
|
do_each!(
|
||||||
|
_ => text_token!("title:"),
|
||||||
|
_ => optional!(ws),
|
||||||
|
title => until!(text_token!("\n")),
|
||||||
|
_ => text_token!("\n"),
|
||||||
|
(title)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
make_fn!(
|
||||||
|
para_separator<StrIter, &str>,
|
||||||
|
do_each!(
|
||||||
|
_ => text_token!("\n"),
|
||||||
|
_ => optional!(ws),
|
||||||
|
_ => text_token!("\n"),
|
||||||
|
("")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
make_fn!(
|
||||||
|
pub description<StrIter, &str>,
|
||||||
|
until!(either!(
|
||||||
|
discard!(para_separator),
|
||||||
|
eoi,
|
||||||
|
))
|
||||||
|
);
|
||||||
|
|
||||||
|
make_fn!(
|
||||||
|
pub step_prefix<StrIter, &str>,
|
||||||
|
do_each!(
|
||||||
|
_ => text_token!("step:"),
|
||||||
|
_ => optional!(ws),
|
||||||
|
_ => para_separator,
|
||||||
|
("")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
make_fn!(
|
||||||
|
pub step<StrIter, Step>,
|
||||||
|
do_each!(
|
||||||
|
_ => step_prefix,
|
||||||
|
ingredients => ingredient_list,
|
||||||
|
_ => para_separator,
|
||||||
|
desc => description,
|
||||||
|
_ => either!(discard!(para_separator), eoi),
|
||||||
|
(Step::new(None, desc).with_ingredients(ingredients))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
make_fn!(
|
||||||
|
pub step_list<StrIter, Vec<Step>>,
|
||||||
|
repeat!(step)
|
||||||
|
);
|
||||||
|
|
||||||
make_fn!(ws<StrIter, &str>,
|
make_fn!(ws<StrIter, &str>,
|
||||||
consume_all!(either!(
|
consume_all!(either!(
|
||||||
text_token!(" "),
|
text_token!(" "),
|
||||||
|
@ -338,3 +338,87 @@ fn test_ingredient_list_parse() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_single_step() {
|
||||||
|
let step = "step:
|
||||||
|
|
||||||
|
1 tbsp flour
|
||||||
|
2 tbsp butter
|
||||||
|
1 cup apple (chopped)
|
||||||
|
|
||||||
|
Saute apples in butter until golden brown. Add flour slowly
|
||||||
|
until thickens. Set aside to cool.";
|
||||||
|
|
||||||
|
match parse::step(StrIter::new(step)) {
|
||||||
|
ParseResult::Complete(_, step) => {
|
||||||
|
assert_eq!(step.ingredients.len(), 3);
|
||||||
|
assert_eq!(
|
||||||
|
step.instructions,
|
||||||
|
"Saute apples in butter until golden brown. Add flour slowly
|
||||||
|
until thickens. Set aside to cool."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
err => assert!(false, "{:?}", err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_multiple_steps() {
|
||||||
|
let steps = "step:
|
||||||
|
|
||||||
|
1 tbsp flour
|
||||||
|
2 tbsp butter
|
||||||
|
1 cup apple (chopped)
|
||||||
|
|
||||||
|
Saute apples in butter until golden brown. Add flour slowly
|
||||||
|
until thickens. Set aside to cool.
|
||||||
|
|
||||||
|
step:
|
||||||
|
|
||||||
|
1 tbsp flour
|
||||||
|
2 tbsp butter
|
||||||
|
|
||||||
|
Saute apples in butter until golden brown. Add flour slowly
|
||||||
|
until thickened. Set aside to cool.
|
||||||
|
";
|
||||||
|
|
||||||
|
match parse::step_list(StrIter::new(steps)) {
|
||||||
|
ParseResult::Complete(_, steps) => {
|
||||||
|
assert_eq!(steps.len(), 2);
|
||||||
|
}
|
||||||
|
err => assert!(false, "{:?}", err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_recipe_multiple_steps() {
|
||||||
|
let recipe = "title: gooey apple bake
|
||||||
|
|
||||||
|
A simple gooey apple bake recipe.
|
||||||
|
|
||||||
|
step:
|
||||||
|
|
||||||
|
1 tbsp flour
|
||||||
|
2 tbsp butter
|
||||||
|
1 cup apple (chopped)
|
||||||
|
|
||||||
|
Saute apples in butter until golden brown. Add flour slowly
|
||||||
|
until thickens. Set aside to cool.
|
||||||
|
|
||||||
|
step:
|
||||||
|
|
||||||
|
1 tbsp flour
|
||||||
|
2 tbsp butter
|
||||||
|
|
||||||
|
Saute apples in butter until golden brown. Add flour slowly
|
||||||
|
until thickened. Set aside to cool.
|
||||||
|
";
|
||||||
|
|
||||||
|
match parse::recipe(StrIter::new(recipe)) {
|
||||||
|
ParseResult::Complete(_, recipe) => {
|
||||||
|
assert_eq!(recipe.steps.len(), 2);
|
||||||
|
}
|
||||||
|
err => assert!(false, "{:?}", err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user