From 6bd5f8ccbd8c44c3311ef36b0e2de9ede4fa71ed Mon Sep 17 00:00:00 2001 From: Jakub Hampl Date: Thu, 14 Feb 2019 15:23:49 +0000 Subject: New Style Generator (#8) --- style-generator/src/Decoder/Legacy.elm | 110 +++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 style-generator/src/Decoder/Legacy.elm (limited to 'style-generator/src/Decoder/Legacy.elm') diff --git a/style-generator/src/Decoder/Legacy.elm b/style-generator/src/Decoder/Legacy.elm new file mode 100644 index 0000000..2c7be93 --- /dev/null +++ b/style-generator/src/Decoder/Legacy.elm @@ -0,0 +1,110 @@ +module Decoder.Legacy exposing (filter) + +import Decoder.Expression exposing (decodeBool) +import Decoder.Generic as Decode +import Decoder.Helpers exposing (todo) +import Json.Decode as D exposing (Decoder) +import Lib +import MyElm.Syntax exposing (Expression, calln, float, int, list, pair, string) + + +filter = + let + decodeProp = + D.index 1 D.string + |> D.map + (\prop -> + case prop of + "$type" -> + Lib.eValue "geometryType" + + "$id" -> + Lib.eValue "id" + + _ -> + calln (Lib.eName "getProperty") [ Lib.str (string prop) ] + ) + + decodeVal = + D.index 2 <| + D.oneOf + [ D.map (string >> Lib.str) D.string + , D.map (float >> Lib.float) D.float + , decodeBool + ] + + decodeVals = + D.list <| + D.oneOf + [ D.map (string >> Lib.str) D.string + , D.map (float >> Lib.float) D.float + , decodeBool + ] + + operator name = + D.map2 (\prop val -> Lib.pipelineCall name [ prop, val ]) decodeProp decodeVal + in + D.index 0 D.string + |> D.andThen + (\filt -> + case filt of + "all" -> + Decode.tail filter |> D.map (\filters -> calln (Lib.eName "all") [ list filters ]) + + "any" -> + Decode.tail filter |> D.map (\filters -> calln (Lib.eName "any") [ list filters ]) + + "none" -> + Decode.tail filter |> D.map (\filters -> calln (Lib.eName "all") [ list (List.map (\f -> calln (Lib.eName "not") [ f ]) filters) ]) + + "has" -> + D.index 1 D.string |> D.map (\prop -> calln (Lib.eName "hasProperty") [ Lib.str (string prop) ]) + + "!has" -> + D.index 1 D.string |> D.map (\prop -> calln (Lib.eName "not") [ calln (Lib.eName "hasProperty") [ Lib.str (string prop) ] ]) + + "==" -> + operator "isEqual" + + "!=" -> + operator "notEqual" + + ">" -> + operator "greaterThan" + + ">=" -> + operator "greaterThanOrEqual" + + "<" -> + operator "lessThan" + + "<=" -> + operator "lessThanOrEqual" + + "in" -> + D.map2 + (\prop values -> + List.drop 2 values + |> List.map (\v -> Lib.pipelineCall "isEqual" [ prop, v ]) + |> list + |> List.singleton + |> calln (Lib.eName "any") + ) + decodeProp + decodeVals + + "!in" -> + D.map2 + (\prop values -> + List.drop 2 values + |> List.map (\v -> Lib.pipelineCall "notEqual" [ prop, v ]) + |> list + |> List.singleton + |> calln (Lib.eName "all") + ) + decodeProp + decodeVals + + _ -> + D.fail "not actually a legacy filter" + ) -- cgit v1.2.3