From 1d63c5147500e10d386f3843ba6930fe533ab4e5 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sun, 9 Aug 2015 10:36:45 +0200 Subject: Chane result and reference argument to quantity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now the recipe’s yield can be extracted from the root’s quantity. --- src/Codec/Pesto/Parse.lhs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/Codec/Pesto/Parse.lhs') diff --git a/src/Codec/Pesto/Parse.lhs b/src/Codec/Pesto/Parse.lhs index d411906..1777aa2 100644 --- a/src/Codec/Pesto/Parse.lhs +++ b/src/Codec/Pesto/Parse.lhs @@ -51,8 +51,8 @@ The following instructions are supported: > | Tool Quantity > | Action String > | Reference Quantity -> | Result Object -> | Alternative Object +> | Result Quantity +> | Alternative Quantity > | Directive String > | Unknown String > deriving (Show, Eq) @@ -95,8 +95,8 @@ whitespace characters and then consumes an object or a quantity. > oparg ident cont = char ident *> spaces *> cont > ingredient = oparg '+' (Ingredient <$> quantity) > tool = oparg '&' (Tool <$> quantity) -> result = oparg '>' (Result <$> object) -> alternative = oparg '|' (Alternative <$> object) +> result = oparg '>' (Result <$> quantity) +> alternative = oparg '|' (Alternative <$> quantity) > reference = oparg '*' (Reference <$> quantity) Additionally there are two special instructions. Directives are similar to the @@ -118,11 +118,11 @@ Below are examples for these instructions: > cmpInstruction "+100 g flour" > (Right (Ingredient (Quantity (Exact (AmountRatio (100%1))) "g" "flour"))) > , cmpInstruction "&oven" -> (Right (Tool (Quantity (Exact (AmountStr "")) "" "oven"))) -> , cmpInstruction ">dough" (Right (Result "dough")) -> , cmpInstruction "|trimmings" (Right (Alternative "trimmings")) +> (Right (Tool (strQuantity "oven"))) +> , cmpInstruction ">dough" (Right (Result (strQuantity "dough"))) +> , cmpInstruction "|trimmings" (Right (Alternative (strQuantity "trimmings"))) > , cmpInstruction "*fish" -> (Right (Reference (Quantity (Exact (AmountStr "")) "" "fish"))) +> (Right (Reference (strQuantity "fish"))) > , cmpInstruction3 "% invalid" (Right (Directive "invalid")) "%invalid" > , cmpInstruction3 "* \t\n 1 _ cheese" > (Right (Reference (Quantity (Exact (AmountRatio (1%1))) "" "cheese"))) @@ -367,6 +367,7 @@ Wrap qstr test in AmountStr to aid serialization test > cmpInstruction3 = cmpParseSerialize instruction > exactQuantity a b c = Right (Quantity (Exact a) b c) +> strQuantity = Quantity (Exact (AmountStr "")) "" > test = [ > "quantity" ~: testQuantityOverloaded ++ testQuantityApprox ++ testQuantityAmount ++ testQuantityRatio -- cgit v1.2.3