Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dhall/src/Dhall/Format.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ format (Format { inputs = inputs0, transitivity = transitivity0, ..}) =
<> Dhall.Pretty.prettyCharacterSet characterSet expr
<> "\n")

(originalText, transitivity) <- case input of
(inputName, originalText, transitivity) <- case input of
InputFile file -> do
text <- Data.Text.IO.readFile file

return (text, transitivity0)
return (file, text, transitivity0)
StandardInput -> do
text <- Data.Text.IO.getContents

return (text, NonTransitive)
return ("(input)", text, NonTransitive)


headerAndExpr@(_, parsedExpression) <- Dhall.Util.getExpressionAndHeaderFromStdinText censor originalText
headerAndExpr@(_, parsedExpression) <- Dhall.Util.getExpressionAndHeaderFromStdinText censor inputName originalText

case transitivity of
Transitive ->
Expand Down
8 changes: 4 additions & 4 deletions dhall/src/Dhall/Freeze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,18 @@ freezeWithManager newManager outputMode transitivity0 inputs scope intent chosen

let status = Dhall.Import.emptyStatusWithManager newManager directory

(originalText, transitivity) <- case input of
(inputName, originalText, transitivity) <- case input of
InputFile file -> do
text <- Text.IO.readFile file

return (text, transitivity0)
return (file, text, transitivity0)

StandardInput -> do
text <- Text.IO.getContents

return (text, NonTransitive)
return ("(input)", text, NonTransitive)

(Header header, parsedExpression) <- Util.getExpressionAndHeaderFromStdinText censor originalText
(Header header, parsedExpression) <- Util.getExpressionAndHeaderFromStdinText censor inputName originalText

let characterSet = fromMaybe (detectCharacterSet parsedExpression) chosenCharacterSet

Expand Down
8 changes: 4 additions & 4 deletions dhall/src/Dhall/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -848,18 +848,18 @@ command (Options {..}) = do

let status = Dhall.Import.emptyStatus directory

(originalText, transitivity) <- case input of
(inputName, originalText, transitivity) <- case input of
InputFile file -> do
text <- Data.Text.IO.readFile file

return (text, transitivity0)
return (file, text, transitivity0)
StandardInput -> do
text <- Data.Text.IO.getContents

return (text, NonTransitive)
return ("(input)", text, NonTransitive)

(Header header, parsedExpression) <-
Dhall.Util.getExpressionAndHeaderFromStdinText censor originalText
Dhall.Util.getExpressionAndHeaderFromStdinText censor inputName originalText

let characterSet = fromMaybe (detectCharacterSet parsedExpression) chosenCharacterSet

Expand Down
8 changes: 4 additions & 4 deletions dhall/src/Dhall/Schemas.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ data Schemas = Schemas
-- | Implementation of the @dhall rewrite-with-schemas@ subcommand
schemasCommand :: Schemas -> IO ()
schemasCommand Schemas{..} = do
originalText <- case input of
InputFile file -> Text.IO.readFile file
StandardInput -> Text.IO.getContents
(inputName, originalText) <- case input of
InputFile file -> (,) file <$> Text.IO.readFile file
StandardInput -> (,) "(input)" <$> Text.IO.getContents

(Header header, expression) <- Util.getExpressionAndHeaderFromStdinText censor originalText
(Header header, expression) <- Util.getExpressionAndHeaderFromStdinText censor inputName originalText

let characterSet = fromMaybe (detectCharacterSet expression) chosenCharacterSet

Expand Down
16 changes: 10 additions & 6 deletions dhall/src/Dhall/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ get parser censor input = do
case input of
Input_ (InputFile file) -> Data.Text.IO.readFile file
Input_ StandardInput -> Data.Text.IO.getContents
StdinText text -> pure text
StdinText _ text -> pure text

let name =
case input of
Input_ (InputFile file) -> file
Input_ StandardInput -> "(input)"
StdinText _ -> "(input)"
StdinText inputName _ -> inputName

let result = parser name inText

Expand All @@ -149,7 +149,11 @@ data Censor = NoCensor | Censor
data Input = StandardInput | InputFile FilePath deriving (Eq)

-- | Path to input or raw input text, necessary since we can't read STDIN twice
data InputOrTextFromStdin = Input_ Input | StdinText Text
data InputOrTextFromStdin
= Input_ Input
| StdinText String Text
-- ^ @StdinText name text@ where name is a user-friendly name describing the
-- input expression, used in parsing error messages

{-| Specifies whether or not an input's transitive dependencies should also be
processed. Transitive dependencies are restricted to relative file imports.
Expand Down Expand Up @@ -234,6 +238,6 @@ getExpressionAndHeader censor =
-- | Convenient utility for retrieving an expression along with its header from
-- | text already read from STDIN (so it's not re-read)
getExpressionAndHeaderFromStdinText
:: Censor -> Text -> IO (Header, Expr Src Import)
getExpressionAndHeaderFromStdinText censor =
get Dhall.Parser.exprAndHeaderFromText censor . StdinText
:: Censor -> String -> Text -> IO (Header, Expr Src Import)
getExpressionAndHeaderFromStdinText censor inputName =
get Dhall.Parser.exprAndHeaderFromText censor . StdinText inputName