initial commit, started work on parser

This commit is contained in:
Christoffer Müller Madsen 2017-04-05 02:20:53 +02:00
commit 14af854887
3 changed files with 68 additions and 0 deletions

13
cookbook.scm Normal file
View 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
View 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
View 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))))