commit 14af8548873f12142cd9e1f7f03de4f4006a074e Author: Christoffer Müller Madsen Date: Wed Apr 5 02:20:53 2017 +0200 initial commit, started work on parser diff --git a/cookbook.scm b/cookbook.scm new file mode 100644 index 0000000..0a79b55 --- /dev/null +++ b/cookbook.scm @@ -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"))) + diff --git a/grammar.ebnf b/grammar.ebnf new file mode 100644 index 0000000..a4f17b9 --- /dev/null +++ b/grammar.ebnf @@ -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}; diff --git a/parse.scm b/parse.scm new file mode 100644 index 0000000..f36e89b --- /dev/null +++ b/parse.scm @@ -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))))