Commit 028640a9 authored by Mike Ledger's avatar Mike Ledger

const

parent 50bd6cac
......@@ -26,7 +26,7 @@ executable csvmaps
, bytestring
, streaming-bytestring
, streaming
, cassava-streaming >= 0.2
, cassava-streaming >= 0.3
, cassava
, containers
, optparse-generic
......
......@@ -16,7 +16,7 @@ dependencies:
- bytestring
- streaming-bytestring
- streaming
- cassava-streaming >= 0.2
- cassava-streaming >= 0.3
- cassava
- containers
- optparse-generic
......
......@@ -59,6 +59,7 @@ data MapExpr k a
| IntersectionWithAll (MapExpr k a) (MapExpr k a)
| IntersectionWithChooseLeft (MapExpr k a) (MapExpr k a)
| IntersectionWithChooseRight (MapExpr k a) (MapExpr k a)
| Const ![ByteString] (MapExpr k a)
| NonNullsOf (MapExpr k a)
| NullsOf (MapExpr k a)
| Keys (MapExpr k a)
......@@ -85,16 +86,18 @@ parseMapExpr =
[ [ prefix "nulls" NullsOf
, prefix "non-nulls" NonNullsOf
, prefix "keys" Keys
, Prefix $ do
_ <- P.textSymbol "const"
s <- P.brackets (P.sepBy1 P.stringLiteral (P.symbolic ','))
return (Const (map (T.encodeUtf8 . T.pack) s))
, Prefix $ do
_ <- P.textSymbol "pad"
amount <- P.natural
pure (Pad (fromInteger amount))
, Prefix $ do
_ <- P.textSymbol "col"
cols <- (:[]) <$> P.natural <|> P.between
(P.textSymbol "[")
(P.textSymbol "]")
(P.sepBy1 P.natural (P.textSymbol ","))
cols <- (:[]) <$> P.natural <|>
P.brackets (P.sepBy1 P.natural (P.symbolic ','))
pure (Columns (VU.fromList (map fromInteger cols)))
]
, [ binary "|*|" IntersectionWithAll AssocLeft
......@@ -246,8 +249,8 @@ interpret me0 v =
withResult1 f (Result a) = Result (f a)
withResult1 _ _ = Error
ins k =
k <$ modify' (Map.insert k k)
ins' k' k =
k <$ modify' (Map.insert k' k)
pad i l
| i > 0 = case l of
......@@ -270,6 +273,7 @@ interpret me0 v =
-> State (Map.Map (MapExpr k a) (MapExpr k a)) (MapExpr k a)
go me = do
cache <- get
let ins = ins' me
case Map.lookup me cache of
Just x -> return x
Nothing -> case me of
......@@ -279,6 +283,7 @@ interpret me0 v =
return a'
Label k -> return (Label k)
DocNum i -> return (Result (v V.! (i - 1)))
Const val a -> ins =<< withResult1 (Map.map (const val)) <$> go a
Union a b -> ins =<< withResult2 Map.union <$> go a <*> go b
Difference a b -> ins =<< withResult2 Map.difference <$> go a <*> go b
Intersection a b -> ins =<< withResult2 Map.intersection <$> go a <*> go b
......
......@@ -39,7 +39,7 @@ packages:
- .
- location:
git: git@gitlab.com:transportengineering/streaming-csv.git
commit: 68a600e3822755892630804ec0a82ef34ee97d5c
commit: 217f703e460eeb9e7f34809d1fe5c45bdd35669c
extra-dep: true
# Dependency packages to be pulled from upstream that are not in the resolver
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment