initial commit, started work on parser
This commit is contained in:
commit
14af854887
13
cookbook.scm
Normal file
13
cookbook.scm
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
(
|
||||||
|
("Spejlæg"
|
||||||
|
((2 "æg"))
|
||||||
|
("Slå æggene ud på en varm pande"
|
||||||
|
"Steg ægene"))
|
||||||
|
("Røræg"
|
||||||
|
((2 "æg")
|
||||||
|
(50 "mL" "mælk"))
|
||||||
|
("Slå æggene ud i en skål"
|
||||||
|
"Tilføj mælk"
|
||||||
|
"Pisk mælk og æg"
|
||||||
|
"Hæld ud på en varm pande og steg til det er nok #beskrivende")))
|
||||||
|
|
8
grammar.ebnf
Normal file
8
grammar.ebnf
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
recipe = title, ingredients, (*tools,*) method;
|
||||||
|
title = string;
|
||||||
|
ingredients = {amount, ingredient}
|
||||||
|
| {amount, unit, ingredient};
|
||||||
|
amount = fractional number;
|
||||||
|
unit = "mL" | "L" | "g" | "kg";
|
||||||
|
ingredient = "æg" | "mælk";
|
||||||
|
method = {step};
|
47
parse.scm
Normal file
47
parse.scm
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
;; Predicates
|
||||||
|
|
||||||
|
(define title
|
||||||
|
(lambda (recipe)
|
||||||
|
(car (recipe))))
|
||||||
|
|
||||||
|
(define ingredients
|
||||||
|
(lambda (recipe)
|
||||||
|
(car (cdr recipe))))
|
||||||
|
|
||||||
|
(define steps
|
||||||
|
(lambda (recipe)
|
||||||
|
(car (cdr (cdr recipe)))))
|
||||||
|
|
||||||
|
(define ingredient-name
|
||||||
|
(lambda (ingredient)
|
||||||
|
(if (= (length ingredient) 2)
|
||||||
|
(car (cdr ingredient))
|
||||||
|
(car (cddr ingredient)))))
|
||||||
|
|
||||||
|
(define ingredient-amount
|
||||||
|
(lambda (ingredient)
|
||||||
|
(car ingredient)))
|
||||||
|
|
||||||
|
|
||||||
|
;;
|
||||||
|
|
||||||
|
(define ingredient-ref
|
||||||
|
(lambda (ingredients n)
|
||||||
|
(if (= n 0)
|
||||||
|
(car ingredients)
|
||||||
|
(ingredient-ref (cdr ingredients) (- n 1)))))
|
||||||
|
|
||||||
|
(define ingredient-by-name
|
||||||
|
(lambda (ingredients search-name)
|
||||||
|
(let ((ingredient (car ingredients)))
|
||||||
|
(cond [(equal? (ingredient-name ingredient)
|
||||||
|
search-name)
|
||||||
|
ingredient]
|
||||||
|
[(null? (cdr ingredients)) #f]
|
||||||
|
[else (ingredient-by-name (cdr ingredients)
|
||||||
|
search-name)]))))
|
||||||
|
|
||||||
|
(define contains-ingredient?
|
||||||
|
(lambda (recipe ingredient)
|
||||||
|
(let ((ingredients (ingredients recipe)))
|
||||||
|
(ingredient-by-name ingredients ingredient))))
|
Loading…
Reference in New Issue
Block a user