module Language.Docker.Parser.Copy
  ( parseCopy,
    parseAdd,
  )
where

import Data.List.NonEmpty (NonEmpty, fromList)
import qualified Data.Text as T
import Language.Docker.Parser.Prelude
import Language.Docker.Syntax

data Flag
  = FlagChecksum Checksum
  | FlagChown Chown
  | FlagChmod Chmod
  | FlagLink Link
  | FlagKeepGitDir KeepGitDir
  | FlagParents Parents
  | FlagUnpack Unpack
  | FlagSource CopySource
  | FlagExclude Exclude
  | FlagInvalid (Text, Text)

parseCopy :: (?esc :: Char) => Parser (Instruction Text)
parseCopy :: (?esc::Char) => Parser (Instruction Text)
parseCopy = do
  (?esc::Char) => Text -> Parser ()
Text -> Parser ()
reserved Text
"COPY"
  flags <- Parser Flag
(?esc::Char) => Parser Flag
copyFlag Parser Flag
-> Parser () -> ParsecT DockerfileError Text Identity [Flag]
forall (m :: * -> *) a sep. MonadPlus m => m a -> m sep -> m [a]
`sepEndBy` Parser ()
(?esc::Char) => Parser ()
requiredWhitespace
  let chownFlags = [Chown
c | FlagChown Chown
c <- [Flag]
flags]
  let chmodFlags = [Chmod
c | FlagChmod Chmod
c <- [Flag]
flags]
  let linkFlags = [Link
l | FlagLink Link
l <- [Flag]
flags]
  let parentsFlags = [Parents
p | FlagParents Parents
p <- [Flag]
flags]
  let sourceFlags = [CopySource
f | FlagSource CopySource
f <- [Flag]
flags]
  let excludeFlags = [Exclude
e | FlagExclude Exclude
e <- [Flag]
flags]
  let invalid = [(Text, Text)
i | FlagInvalid (Text, Text)
i <- [Flag]
flags]
  -- Let's do some validation on the flags
  case (invalid, chownFlags, chmodFlags, linkFlags, parentsFlags, sourceFlags, excludeFlags) of
    ((Text
k, Text
v) : [(Text, Text)]
_, [Chown]
_, [Chmod]
_, [Link]
_, [Parents]
_, [CopySource]
_, [Exclude]
_) -> Text -> Text -> Parser (Instruction Text)
forall a. Text -> Text -> Parser a
unexpectedFlag Text
k Text
v
    ([(Text, Text)]
_, Chown
_ : Chown
_ : [Chown]
_, [Chmod]
_, [Link]
_, [Parents]
_, [CopySource]
_, [Exclude]
_) -> DockerfileError -> Parser (Instruction Text)
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser (Instruction Text))
-> DockerfileError -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
DuplicateFlagError String
"--chown"
    ([(Text, Text)]
_, [Chown]
_, Chmod
_ : Chmod
_ : [Chmod]
_, [Link]
_, [Parents]
_, [CopySource]
_, [Exclude]
_) -> DockerfileError -> Parser (Instruction Text)
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser (Instruction Text))
-> DockerfileError -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
DuplicateFlagError String
"--chmod"
    ([(Text, Text)]
_, [Chown]
_, [Chmod]
_, Link
_ : Link
_ : [Link]
_, [Parents]
_, [CopySource]
_, [Exclude]
_) -> DockerfileError -> Parser (Instruction Text)
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser (Instruction Text))
-> DockerfileError -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
DuplicateFlagError String
"--link"
    ([(Text, Text)]
_, [Chown]
_, [Chmod]
_, [Link]
_, Parents
_ : Parents
_ : [Parents]
_, [CopySource]
_, [Exclude]
_) -> DockerfileError -> Parser (Instruction Text)
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser (Instruction Text))
-> DockerfileError -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
DuplicateFlagError String
"--parents"
    ([(Text, Text)]
_, [Chown]
_, [Chmod]
_, [Link]
_, [Parents]
_, CopySource
_ : CopySource
_ : [CopySource]
_, [Exclude]
_) -> DockerfileError -> Parser (Instruction Text)
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser (Instruction Text))
-> DockerfileError -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
DuplicateFlagError String
"--from"
    ([(Text, Text)], [Chown], [Chmod], [Link], [Parents], [CopySource],
 [Exclude])
_ -> do
      let cho :: Chown
cho =
            case [Chown]
chownFlags of
              [] -> Chown
NoChown
              Chown
c : [Chown]
_ -> Chown
c
      let chm :: Chmod
chm =
            case [Chmod]
chmodFlags of
              [] -> Chmod
NoChmod
              Chmod
c : [Chmod]
_ -> Chmod
c
      let lnk :: Link
lnk =
            case [Link]
linkFlags of
              [] -> Link
NoLink
              Link
l : [Link]
_ -> Link
l
      let par :: Parents
par =
            case [Parents]
parentsFlags of
              [] -> Parents
NoParents
              Parents
p : [Parents]
_ -> Parents
p
      let fr :: CopySource
fr =
            case [CopySource]
sourceFlags of
              [] -> CopySource
NoSource
              CopySource
f : [CopySource]
_ -> CopySource
f
      Parser (Instruction Text) -> Parser (Instruction Text)
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ((?esc::Char) =>
(NonEmpty SourcePath -> TargetPath -> Instruction Text)
-> Parser (Instruction Text)
(NonEmpty SourcePath -> TargetPath -> Instruction Text)
-> Parser (Instruction Text)
heredocList (\NonEmpty SourcePath
src TargetPath
dest -> CopyArgs -> CopyFlags -> Instruction Text
forall args. CopyArgs -> CopyFlags -> Instruction args
Copy (NonEmpty SourcePath -> TargetPath -> CopyArgs
CopyArgs NonEmpty SourcePath
src TargetPath
dest) (Chown
-> Chmod -> Link -> Parents -> CopySource -> [Exclude] -> CopyFlags
CopyFlags Chown
cho Chmod
chm Link
lnk Parents
par CopySource
fr [Exclude]
excludeFlags)))
        Parser (Instruction Text)
-> Parser (Instruction Text) -> Parser (Instruction Text)
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (?esc::Char) =>
Text
-> (NonEmpty SourcePath -> TargetPath -> Instruction Text)
-> Parser (Instruction Text)
Text
-> (NonEmpty SourcePath -> TargetPath -> Instruction Text)
-> Parser (Instruction Text)
fileList Text
"COPY" (\NonEmpty SourcePath
src TargetPath
dest -> CopyArgs -> CopyFlags -> Instruction Text
forall args. CopyArgs -> CopyFlags -> Instruction args
Copy (NonEmpty SourcePath -> TargetPath -> CopyArgs
CopyArgs NonEmpty SourcePath
src TargetPath
dest) (Chown
-> Chmod -> Link -> Parents -> CopySource -> [Exclude] -> CopyFlags
CopyFlags Chown
cho Chmod
chm Link
lnk Parents
par CopySource
fr [Exclude]
excludeFlags))

parseAdd :: (?esc :: Char) => Parser (Instruction Text)
parseAdd :: (?esc::Char) => Parser (Instruction Text)
parseAdd = do
  (?esc::Char) => Text -> Parser ()
Text -> Parser ()
reserved Text
"ADD"
  flags <- Parser Flag
(?esc::Char) => Parser Flag
addFlag Parser Flag
-> Parser () -> ParsecT DockerfileError Text Identity [Flag]
forall (m :: * -> *) a sep. MonadPlus m => m a -> m sep -> m [a]
`sepEndBy` Parser ()
(?esc::Char) => Parser ()
requiredWhitespace
  let checksumFlags = [Checksum
c | FlagChecksum Checksum
c <- [Flag]
flags]
  let chownFlags = [Chown
c | FlagChown Chown
c <- [Flag]
flags]
  let chmodFlags = [Chmod
c | FlagChmod Chmod
c <- [Flag]
flags]
  let linkFlags = [Link
l | FlagLink Link
l <- [Flag]
flags]
  let keepGitDirFlags = [KeepGitDir
k | FlagKeepGitDir KeepGitDir
k <- [Flag]
flags]
  let unpackFlags = [Unpack
u | FlagUnpack Unpack
u <- [Flag]
flags]
  let excludeFlags = [Exclude
e | FlagExclude Exclude
e <- [Flag]
flags]
  let invalidFlags = [(Text, Text)
i | FlagInvalid (Text, Text)
i <- [Flag]
flags]
  notFollowedBy (string "--") <?>
    "only the --checksum, --chown, --chmod, --link, --exclude, --keep-git-dir, --unpack flags or the src and dest paths"
  case (invalidFlags, checksumFlags, chownFlags, linkFlags, chmodFlags, keepGitDirFlags, unpackFlags, excludeFlags) of
    ((Text
k, Text
v) : [(Text, Text)]
_, [Checksum]
_, [Chown]
_, [Link]
_, [Chmod]
_, [KeepGitDir]
_, [Unpack]
_, [Exclude]
_) -> Text -> Text -> Parser (Instruction Text)
forall a. Text -> Text -> Parser a
unexpectedFlag Text
k Text
v
    ([(Text, Text)]
_, Checksum
_ : Checksum
_ : [Checksum]
_, [Chown]
_, [Link]
_, [Chmod]
_, [KeepGitDir]
_, [Unpack]
_, [Exclude]
_) -> DockerfileError -> Parser (Instruction Text)
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser (Instruction Text))
-> DockerfileError -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
DuplicateFlagError String
"--checksum"
    ([(Text, Text)]
_, [Checksum]
_, Chown
_ : Chown
_ : [Chown]
_, [Link]
_, [Chmod]
_, [KeepGitDir]
_, [Unpack]
_, [Exclude]
_) -> DockerfileError -> Parser (Instruction Text)
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser (Instruction Text))
-> DockerfileError -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
DuplicateFlagError String
"--chown"
    ([(Text, Text)]
_, [Checksum]
_, [Chown]
_, Link
_ : Link
_ : [Link]
_, [Chmod]
_, [KeepGitDir]
_, [Unpack]
_, [Exclude]
_) -> DockerfileError -> Parser (Instruction Text)
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser (Instruction Text))
-> DockerfileError -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
DuplicateFlagError String
"--chmod"
    ([(Text, Text)]
_, [Checksum]
_, [Chown]
_, [Link]
_, Chmod
_ : Chmod
_ : [Chmod]
_, [KeepGitDir]
_, [Unpack]
_, [Exclude]
_) -> DockerfileError -> Parser (Instruction Text)
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser (Instruction Text))
-> DockerfileError -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
DuplicateFlagError String
"--link"
    ([(Text, Text)]
_, [Checksum]
_, [Chown]
_, [Link]
_, [Chmod]
_, KeepGitDir
_ : KeepGitDir
_ : [KeepGitDir]
_, [Unpack]
_, [Exclude]
_) -> DockerfileError -> Parser (Instruction Text)
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser (Instruction Text))
-> DockerfileError -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
DuplicateFlagError String
"--keep-git-dir"
    ([(Text, Text)]
_, [Checksum]
_, [Chown]
_, [Link]
_, [Chmod]
_, [KeepGitDir]
_, Unpack
_ : Unpack
_ : [Unpack]
_, [Exclude]
_) -> DockerfileError -> Parser (Instruction Text)
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser (Instruction Text))
-> DockerfileError -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
DuplicateFlagError String
"--unpack"
    ([(Text, Text)], [Checksum], [Chown], [Link], [Chmod],
 [KeepGitDir], [Unpack], [Exclude])
_ -> do
      let chk :: Checksum
chk = case [Checksum]
checksumFlags of
                  [] -> Checksum
NoChecksum
                  Checksum
c : [Checksum]
_ -> Checksum
c
      let cho :: Chown
cho = case [Chown]
chownFlags of
                  [] -> Chown
NoChown
                  Chown
c : [Chown]
_ -> Chown
c
      let chm :: Chmod
chm = case [Chmod]
chmodFlags of
                  [] -> Chmod
NoChmod
                  Chmod
c : [Chmod]
_ -> Chmod
c
      let lnk :: Link
lnk = case [Link]
linkFlags of
                  [] -> Link
NoLink
                  Link
l : [Link]
_ -> Link
l
      let kgd :: KeepGitDir
kgd = case [KeepGitDir]
keepGitDirFlags of
                  [] -> KeepGitDir
NoKeepGitDir
                  KeepGitDir
k : [KeepGitDir]
_ -> KeepGitDir
k
      let unp :: Unpack
unp = case [Unpack]
unpackFlags of
                  [] -> Unpack
NoUnpack
                  Unpack
u : [Unpack]
_ -> Unpack
u
      (?esc::Char) =>
Text
-> (NonEmpty SourcePath -> TargetPath -> Instruction Text)
-> Parser (Instruction Text)
Text
-> (NonEmpty SourcePath -> TargetPath -> Instruction Text)
-> Parser (Instruction Text)
fileList Text
"ADD" (\NonEmpty SourcePath
src TargetPath
dest -> AddArgs -> AddFlags -> Instruction Text
forall args. AddArgs -> AddFlags -> Instruction args
Add (NonEmpty SourcePath -> TargetPath -> AddArgs
AddArgs NonEmpty SourcePath
src TargetPath
dest) (Checksum
-> Chown
-> Chmod
-> Link
-> KeepGitDir
-> Unpack
-> [Exclude]
-> AddFlags
AddFlags Checksum
chk Chown
cho Chmod
chm Link
lnk KeepGitDir
kgd Unpack
unp [Exclude]
excludeFlags))

heredocList :: (?esc :: Char) =>
               (NonEmpty SourcePath -> TargetPath -> Instruction Text) ->
               Parser (Instruction Text)
heredocList :: (?esc::Char) =>
(NonEmpty SourcePath -> TargetPath -> Instruction Text)
-> Parser (Instruction Text)
heredocList NonEmpty SourcePath -> TargetPath -> Instruction Text
constr = do
  markers <- ParsecT DockerfileError Text Identity [Text]
-> ParsecT DockerfileError Text Identity [Text]
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Parser Text -> ParsecT DockerfileError Text Identity [Text]
forall a. Parser a -> Parser [a]
spaceSep1 Parser Text
(?esc::Char) => Parser Text
heredocMarker) ParsecT DockerfileError Text Identity [Text]
-> String -> ParsecT DockerfileError Text Identity [Text]
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"a list of heredoc markers"
  target <- untilEol "target path"
  case reverse markers of
    [] -> DockerfileError -> Parser ()
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser ()) -> DockerfileError -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
FileListError String
"empty list of heredoc markers"
    Text
m:[Text]
_ -> Parser Text -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Parser Text -> Parser ()) -> Parser Text -> Parser ()
forall a b. (a -> b) -> a -> b
$ Text -> Parser Text
heredocContent Text
m
  return $ constr (SourcePath <$> fromList markers) (TargetPath target)

fileList :: (?esc :: Char) => Text ->
            (NonEmpty SourcePath -> TargetPath -> Instruction Text) ->
            Parser (Instruction Text)
fileList :: (?esc::Char) =>
Text
-> (NonEmpty SourcePath -> TargetPath -> Instruction Text)
-> Parser (Instruction Text)
fileList Text
name NonEmpty SourcePath -> TargetPath -> Instruction Text
constr = do
  paths <-
    (ParsecT DockerfileError Text Identity [Text]
-> ParsecT DockerfileError Text Identity [Text]
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity [Text]
stringList ParsecT DockerfileError Text Identity [Text]
-> String -> ParsecT DockerfileError Text Identity [Text]
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"an array of strings [\"src_file\", \"dest_file\"]")
      ParsecT DockerfileError Text Identity [Text]
-> ParsecT DockerfileError Text Identity [Text]
-> ParsecT DockerfileError Text Identity [Text]
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (ParsecT DockerfileError Text Identity [Text]
-> ParsecT DockerfileError Text Identity [Text]
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity [Text]
spaceSeparated ParsecT DockerfileError Text Identity [Text]
-> String -> ParsecT DockerfileError Text Identity [Text]
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"a space separated list of file paths")
  case paths of
    [Text
_] -> DockerfileError -> Parser (Instruction Text)
forall a. DockerfileError -> Parser a
customError (DockerfileError -> Parser (Instruction Text))
-> DockerfileError -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
FileListError (Text -> String
T.unpack Text
name)
    [Text]
_ -> Instruction Text -> Parser (Instruction Text)
forall a. a -> ParsecT DockerfileError Text Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (Instruction Text -> Parser (Instruction Text))
-> Instruction Text -> Parser (Instruction Text)
forall a b. (a -> b) -> a -> b
$ NonEmpty SourcePath -> TargetPath -> Instruction Text
constr (Text -> SourcePath
SourcePath (Text -> SourcePath) -> NonEmpty Text -> NonEmpty SourcePath
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Text] -> NonEmpty Text
forall a. HasCallStack => [a] -> NonEmpty a
fromList ([Text] -> [Text]
forall a. HasCallStack => [a] -> [a]
init [Text]
paths)) (Text -> TargetPath
TargetPath (Text -> TargetPath) -> Text -> TargetPath
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
forall a. HasCallStack => [a] -> a
last [Text]
paths)
  where
    spaceSeparated :: ParsecT DockerfileError Text Identity [Text]
spaceSeparated =
      (?esc::Char) => String -> (Char -> Bool) -> Parser Text
String -> (Char -> Bool) -> Parser Text
someUnless String
"a file" (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
' ') Parser Text
-> Parser () -> ParsecT DockerfileError Text Identity [Text]
forall (m :: * -> *) a sep. MonadPlus m => m a -> m sep -> m [a]
`sepEndBy1` (Parser () -> Parser ()
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try Parser ()
(?esc::Char) => Parser ()
requiredWhitespace Parser () -> String -> Parser ()
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"at least another file path")
    stringList :: ParsecT DockerfileError Text Identity [Text]
stringList = ParsecT DockerfileError Text Identity [Text]
-> ParsecT DockerfileError Text Identity [Text]
forall a. (?esc::Char) => Parser a -> Parser a
brackets (ParsecT DockerfileError Text Identity [Text]
 -> ParsecT DockerfileError Text Identity [Text])
-> ParsecT DockerfileError Text Identity [Text]
-> ParsecT DockerfileError Text Identity [Text]
forall a b. (a -> b) -> a -> b
$ Parser Text -> ParsecT DockerfileError Text Identity [Text]
forall a. (?esc::Char) => Parser a -> Parser [a]
commaSep Parser Text
doubleQuotedString

unexpectedFlag :: Text -> Text -> Parser a
unexpectedFlag :: forall a. Text -> Text -> Parser a
unexpectedFlag Text
name Text
"" = DockerfileError -> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => e -> m a
customFailure (DockerfileError -> ParsecT DockerfileError Text Identity a)
-> DockerfileError -> ParsecT DockerfileError Text Identity a
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
NoValueFlagError (Text -> String
T.unpack Text
name)
unexpectedFlag Text
name Text
_ = DockerfileError -> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => e -> m a
customFailure (DockerfileError -> ParsecT DockerfileError Text Identity a)
-> DockerfileError -> ParsecT DockerfileError Text Identity a
forall a b. (a -> b) -> a -> b
$ String -> DockerfileError
InvalidFlagError (Text -> String
T.unpack Text
name)

copyFlag :: (?esc :: Char) => Parser Flag
copyFlag :: (?esc::Char) => Parser Flag
copyFlag = (CopySource -> Flag
FlagSource (CopySource -> Flag)
-> ParsecT DockerfileError Text Identity CopySource -> Parser Flag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity CopySource
-> ParsecT DockerfileError Text Identity CopySource
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity CopySource
(?esc::Char) => ParsecT DockerfileError Text Identity CopySource
copySource Parser Flag -> String -> Parser Flag
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"only one --from")
  Parser Flag -> Parser Flag -> Parser Flag
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Chown -> Flag
FlagChown (Chown -> Flag)
-> ParsecT DockerfileError Text Identity Chown -> Parser Flag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity Chown
-> ParsecT DockerfileError Text Identity Chown
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity Chown
(?esc::Char) => ParsecT DockerfileError Text Identity Chown
chown Parser Flag -> String -> Parser Flag
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"--chown")
  Parser Flag -> Parser Flag -> Parser Flag
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Chmod -> Flag
FlagChmod (Chmod -> Flag)
-> ParsecT DockerfileError Text Identity Chmod -> Parser Flag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity Chmod
-> ParsecT DockerfileError Text Identity Chmod
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity Chmod
(?esc::Char) => ParsecT DockerfileError Text Identity Chmod
chmod Parser Flag -> String -> Parser Flag
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"--chmod")
  Parser Flag -> Parser Flag -> Parser Flag
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Link -> Flag
FlagLink (Link -> Flag)
-> ParsecT DockerfileError Text Identity Link -> Parser Flag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity Link
-> ParsecT DockerfileError Text Identity Link
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity Link
link Parser Flag -> String -> Parser Flag
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"--link")
  Parser Flag -> Parser Flag -> Parser Flag
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parents -> Flag
FlagParents (Parents -> Flag)
-> ParsecT DockerfileError Text Identity Parents -> Parser Flag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity Parents
-> ParsecT DockerfileError Text Identity Parents
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity Parents
parents Parser Flag -> String -> Parser Flag
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"--parents")
  Parser Flag -> Parser Flag -> Parser Flag
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Exclude -> Flag
FlagExclude (Exclude -> Flag)
-> ParsecT DockerfileError Text Identity Exclude -> Parser Flag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity Exclude
-> ParsecT DockerfileError Text Identity Exclude
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity Exclude
(?esc::Char) => ParsecT DockerfileError Text Identity Exclude
exclude Parser Flag -> String -> Parser Flag
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"--exclude")
  Parser Flag -> Parser Flag -> Parser Flag
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ((Text, Text) -> Flag
FlagInvalid ((Text, Text) -> Flag)
-> ParsecT DockerfileError Text Identity (Text, Text)
-> Parser Flag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity (Text, Text)
-> ParsecT DockerfileError Text Identity (Text, Text)
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity (Text, Text)
(?esc::Char) => ParsecT DockerfileError Text Identity (Text, Text)
anyFlag Parser Flag -> String -> Parser Flag
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"other flag")

addFlag :: (?esc :: Char) => Parser Flag
addFlag :: (?esc::Char) => Parser Flag
addFlag = (Checksum -> Flag
FlagChecksum (Checksum -> Flag)
-> ParsecT DockerfileError Text Identity Checksum -> Parser Flag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity Checksum
-> ParsecT DockerfileError Text Identity Checksum
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity Checksum
(?esc::Char) => ParsecT DockerfileError Text Identity Checksum
checksum Parser Flag -> String -> Parser Flag
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"--checksum")
  Parser Flag -> Parser Flag -> Parser Flag
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Chown -> Flag
FlagChown (Chown -> Flag)
-> ParsecT DockerfileError Text Identity Chown -> Parser Flag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity Chown
-> ParsecT DockerfileError Text Identity Chown
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity Chown
(?esc::Char) => ParsecT DockerfileError Text Identity Chown
chown Parser Flag -> String -> Parser Flag
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"--chown")
  Parser Flag -> Parser Flag -> Parser Flag
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Chmod -> Flag
FlagChmod (Chmod -> Flag)
-> ParsecT DockerfileError Text Identity Chmod -> Parser Flag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity Chmod
-> ParsecT DockerfileError Text Identity Chmod
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity Chmod
(?esc::Char) => ParsecT DockerfileError Text Identity Chmod
chmod Parser Flag -> String -> Parser Flag
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"--chmod")
  Parser Flag -> Parser Flag -> Parser Flag
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Link -> Flag
FlagLink (Link -> Flag)
-> ParsecT DockerfileError Text Identity Link -> Parser Flag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity Link
-> ParsecT DockerfileError Text Identity Link
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity Link
link Parser Flag -> String -> Parser Flag
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"--link")
  Parser Flag -> Parser Flag -> Parser Flag
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (KeepGitDir -> Flag
FlagKeepGitDir (KeepGitDir -> Flag)
-> ParsecT DockerfileError Text Identity KeepGitDir -> Parser Flag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity KeepGitDir
-> ParsecT DockerfileError Text Identity KeepGitDir
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity KeepGitDir
keepGitDir Parser Flag -> String -> Parser Flag
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"--keep-git-dir")
  Parser Flag -> Parser Flag -> Parser Flag
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Unpack -> Flag
FlagUnpack (Unpack -> Flag)
-> ParsecT DockerfileError Text Identity Unpack -> Parser Flag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity Unpack
-> ParsecT DockerfileError Text Identity Unpack
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity Unpack
unpack Parser Flag -> String -> Parser Flag
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"--unpack")
  Parser Flag -> Parser Flag -> Parser Flag
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Exclude -> Flag
FlagExclude (Exclude -> Flag)
-> ParsecT DockerfileError Text Identity Exclude -> Parser Flag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity Exclude
-> ParsecT DockerfileError Text Identity Exclude
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity Exclude
(?esc::Char) => ParsecT DockerfileError Text Identity Exclude
exclude Parser Flag -> String -> Parser Flag
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"--exclude")
  Parser Flag -> Parser Flag -> Parser Flag
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ((Text, Text) -> Flag
FlagInvalid ((Text, Text) -> Flag)
-> ParsecT DockerfileError Text Identity (Text, Text)
-> Parser Flag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT DockerfileError Text Identity (Text, Text)
-> ParsecT DockerfileError Text Identity (Text, Text)
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity (Text, Text)
(?esc::Char) => ParsecT DockerfileError Text Identity (Text, Text)
anyFlag Parser Flag -> String -> Parser Flag
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"other flag")

checksum :: (?esc :: Char) => Parser Checksum
checksum :: (?esc::Char) => ParsecT DockerfileError Text Identity Checksum
checksum = do
  ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--checksum="
  chk <- (?esc::Char) => String -> (Char -> Bool) -> Parser Text
String -> (Char -> Bool) -> Parser Text
someUnless String
"the remote file checksum" (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
' ')
  return $ Checksum chk

chown :: (?esc :: Char) => Parser Chown
chown :: (?esc::Char) => ParsecT DockerfileError Text Identity Chown
chown = do
  ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--chown="
  cho <- (?esc::Char) => String -> (Char -> Bool) -> Parser Text
String -> (Char -> Bool) -> Parser Text
someUnless String
"the user and group for chown" (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
' ')
  return $ Chown cho

chmod :: (?esc :: Char) => Parser Chmod
chmod :: (?esc::Char) => ParsecT DockerfileError Text Identity Chmod
chmod = do
  ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--chmod="
  chm <- (?esc::Char) => String -> (Char -> Bool) -> Parser Text
String -> (Char -> Bool) -> Parser Text
someUnless String
"the mode for chmod" (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
' ')
  return $ Chmod chm

link :: Parser Link
link :: ParsecT DockerfileError Text Identity Link
link = ( ParsecT DockerfileError Text Identity Link
-> ParsecT DockerfileError Text Identity Link
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity Link
linkExplicit ParsecT DockerfileError Text Identity Link
-> String -> ParsecT DockerfileError Text Identity Link
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"explicit --link" )
  ParsecT DockerfileError Text Identity Link
-> ParsecT DockerfileError Text Identity Link
-> ParsecT DockerfileError Text Identity Link
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ( ParsecT DockerfileError Text Identity Link
-> ParsecT DockerfileError Text Identity Link
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity Link
linkImplicit ParsecT DockerfileError Text Identity Link
-> String -> ParsecT DockerfileError Text Identity Link
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"implicit --link" )
  where
    linkExplicit :: ParsecT DockerfileError Text Identity Link
linkExplicit = do
      ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--link="
      val <- Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"true" ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Tokens Text)
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"false"
      return $ Link ( val == "true" )
    linkImplicit :: ParsecT DockerfileError Text Identity Link
linkImplicit =  do
      ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--link"
      Link -> ParsecT DockerfileError Text Identity Link
forall a. a -> ParsecT DockerfileError Text Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (Link -> ParsecT DockerfileError Text Identity Link)
-> Link -> ParsecT DockerfileError Text Identity Link
forall a b. (a -> b) -> a -> b
$ Bool -> Link
Link Bool
True

parents :: Parser Parents
parents :: ParsecT DockerfileError Text Identity Parents
parents = ( ParsecT DockerfileError Text Identity Parents
-> ParsecT DockerfileError Text Identity Parents
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity Parents
parentsExplicit ParsecT DockerfileError Text Identity Parents
-> String -> ParsecT DockerfileError Text Identity Parents
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"explicit --parents")
  ParsecT DockerfileError Text Identity Parents
-> ParsecT DockerfileError Text Identity Parents
-> ParsecT DockerfileError Text Identity Parents
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ( ParsecT DockerfileError Text Identity Parents
-> ParsecT DockerfileError Text Identity Parents
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity Parents
parentsImplicit ParsecT DockerfileError Text Identity Parents
-> String -> ParsecT DockerfileError Text Identity Parents
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"implicit --parents")
  where
    parentsExplicit :: ParsecT DockerfileError Text Identity Parents
parentsExplicit = do
      ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--parents="
      val <- Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"true" ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Tokens Text)
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"false"
      return $ Parents (val == "true")
    parentsImplicit :: ParsecT DockerfileError Text Identity Parents
parentsImplicit = do
      ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--parents"
      Parents -> ParsecT DockerfileError Text Identity Parents
forall a. a -> ParsecT DockerfileError Text Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (Parents -> ParsecT DockerfileError Text Identity Parents)
-> Parents -> ParsecT DockerfileError Text Identity Parents
forall a b. (a -> b) -> a -> b
$ Bool -> Parents
Parents Bool
True

keepGitDir :: Parser KeepGitDir
keepGitDir :: ParsecT DockerfileError Text Identity KeepGitDir
keepGitDir = ( ParsecT DockerfileError Text Identity KeepGitDir
-> ParsecT DockerfileError Text Identity KeepGitDir
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity KeepGitDir
keepGitDirExplicit ParsecT DockerfileError Text Identity KeepGitDir
-> String -> ParsecT DockerfileError Text Identity KeepGitDir
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"explicit --keep-git-dir" )
  ParsecT DockerfileError Text Identity KeepGitDir
-> ParsecT DockerfileError Text Identity KeepGitDir
-> ParsecT DockerfileError Text Identity KeepGitDir
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ( ParsecT DockerfileError Text Identity KeepGitDir
-> ParsecT DockerfileError Text Identity KeepGitDir
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity KeepGitDir
keepGitDirImplicit ParsecT DockerfileError Text Identity KeepGitDir
-> String -> ParsecT DockerfileError Text Identity KeepGitDir
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"implicit --keep-git-dir" )
  where
    keepGitDirExplicit :: ParsecT DockerfileError Text Identity KeepGitDir
keepGitDirExplicit = do
      ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--keep-git-dir="
      val <- Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"true" ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Tokens Text)
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"false"
      return $ KeepGitDir (val == "true")
    keepGitDirImplicit :: ParsecT DockerfileError Text Identity KeepGitDir
keepGitDirImplicit = do
      ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--keep-git-dir"
      KeepGitDir -> ParsecT DockerfileError Text Identity KeepGitDir
forall a. a -> ParsecT DockerfileError Text Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (KeepGitDir -> ParsecT DockerfileError Text Identity KeepGitDir)
-> KeepGitDir -> ParsecT DockerfileError Text Identity KeepGitDir
forall a b. (a -> b) -> a -> b
$ Bool -> KeepGitDir
KeepGitDir Bool
True

unpack :: Parser Unpack
unpack :: ParsecT DockerfileError Text Identity Unpack
unpack = ( ParsecT DockerfileError Text Identity Unpack
-> ParsecT DockerfileError Text Identity Unpack
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity Unpack
unpackExplicit ParsecT DockerfileError Text Identity Unpack
-> String -> ParsecT DockerfileError Text Identity Unpack
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"explicit --unpack" )
  ParsecT DockerfileError Text Identity Unpack
-> ParsecT DockerfileError Text Identity Unpack
-> ParsecT DockerfileError Text Identity Unpack
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ( ParsecT DockerfileError Text Identity Unpack
-> ParsecT DockerfileError Text Identity Unpack
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ParsecT DockerfileError Text Identity Unpack
unpackImplicit ParsecT DockerfileError Text Identity Unpack
-> String -> ParsecT DockerfileError Text Identity Unpack
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"implicit --unpack" )
  where
    unpackExplicit :: ParsecT DockerfileError Text Identity Unpack
unpackExplicit = do
      ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--unpack="
      val <- Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"true" ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Tokens Text)
-> ParsecT DockerfileError Text Identity (Tokens Text)
forall a.
ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
-> ParsecT DockerfileError Text Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"false"
      return $ Unpack (val == "true")
    unpackImplicit :: ParsecT DockerfileError Text Identity Unpack
unpackImplicit = do
      ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--unpack"
      Unpack -> ParsecT DockerfileError Text Identity Unpack
forall a. a -> ParsecT DockerfileError Text Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (Unpack -> ParsecT DockerfileError Text Identity Unpack)
-> Unpack -> ParsecT DockerfileError Text Identity Unpack
forall a b. (a -> b) -> a -> b
$ Bool -> Unpack
Unpack Bool
True

copySource :: (?esc :: Char) => Parser CopySource
copySource :: (?esc::Char) => ParsecT DockerfileError Text Identity CopySource
copySource = do
  ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--from="
  src <- (?esc::Char) => String -> (Char -> Bool) -> Parser Text
String -> (Char -> Bool) -> Parser Text
someUnless String
"the copy source path" Char -> Bool
isNl
  return $ CopySource src

exclude :: (?esc :: Char) => Parser Exclude
exclude :: (?esc::Char) => ParsecT DockerfileError Text Identity Exclude
exclude = do
  ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--exclude="
  exc <- (?esc::Char) => String -> (Char -> Bool) -> Parser Text
String -> (Char -> Bool) -> Parser Text
someUnless String
"the exclude pattern" (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
' ')
  return $ Exclude exc

anyFlag :: (?esc :: Char) => Parser (Text, Text)
anyFlag :: (?esc::Char) => ParsecT DockerfileError Text Identity (Text, Text)
anyFlag = do
  ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ())
-> ParsecT DockerfileError Text Identity (Tokens Text) -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT DockerfileError Text Identity (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"--"
  name <- (?esc::Char) => String -> (Char -> Bool) -> Parser Text
String -> (Char -> Bool) -> Parser Text
someUnless String
"the flag value" (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'=')
  void $ char '='
  val <- anyUnless (== ' ')
  return (T.append "--" name, val)