Skip to content

Commit 9357243

Browse files
authored
Accept empty input. (#121)
1 parent c201c84 commit 9357243

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/Eucalypt/Source/YamlSource.hs

+10-3
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,18 @@ incorporateAliases :: RawExpr -> CoreExpr
252252
incorporateAliases (RawExpr e _) = e -- TODO: Yaml aliases
253253

254254
-- | Parse eu-annotated active YAML into a CoreExpr
255+
--
256+
-- If the data is entirely blank, return an empty block (despite this
257+
-- being invalid yaml)
255258
parseYamlExpr :: String -> BS.ByteString -> IO CoreExpr
256259
parseYamlExpr inputName s =
257-
catchJust yamlError
258-
(incorporateAliases <$> runConduitRes (decode s .| sinkActiveRawExpr))
259-
(throwM . yamlExceptionToDataParseException inputName)
260+
if BS.null s
261+
then
262+
return $ anon block []
263+
else
264+
catchJust yamlError
265+
(incorporateAliases <$> runConduitRes (decode s .| sinkActiveRawExpr))
266+
(throwM . yamlExceptionToDataParseException inputName)
260267
where
261268
yamlError :: YamlException -> Maybe YamlException
262269
yamlError = Just

test/Eucalypt/Source/YamlSourceSpec.hs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ main = hspec spec
1616
spec :: Spec
1717
spec =
1818
describe "Yaml parser" $ do
19+
it "Accepts empty input" $ parseYamlExpr "<test>" "" `shouldReturn` block []
1920
it "Parses key value" $
2021
parseYamlExpr "<test>" "a: !!int 1234" `shouldReturn`
2122
letexp [("a", int 1234)] (block [element "a" $ var "a"])

0 commit comments

Comments
 (0)