-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Simple Makefile parser and generator -- -- This package provides a few Attoparser parsers and -- convenience functions for parsing and generating Makefiles. The -- datatypes used for describing Makefiles are located in -- Data.Makefile. The parsers and parsing functions are located in -- Data.Makefile.Parse. The generating and encoding functions are -- located in Data.Makefile.Render. To parse a Makefile in the -- current folder, simply run parseMakefile. To parse a Makefile -- located at path, run parseAsMakefile path. To -- parse a Makefile from a Text txt, run 'parseMakefileContents -- txt`. To encode a Makefile, run encodeMakefile. @package makefile @version 1.1.0.0 -- | This module defines the different types used when working with a -- Makefile. -- --
-- # File: Makefile -- -- hello = world -- -- foo: bar -- baz ---- --
-- Makefile {
-- entries =
-- [ Assignment RecursiveAssign "hello" "world"
-- , Rule (Target "foo") [Dependency "bar"] [Command "baz"]
-- ]
-- }
--
module Data.Makefile
-- | A Makefile object, a list of makefile entries
data Makefile
Makefile :: [Entry] -> Makefile
[entries] :: Makefile -> [Entry]
-- | A makefile entry, either a rule (target: dep1 dep1; commands)
-- or a variable assignment (hello = world or hello :=
-- world)
data Entry
Rule :: Target -> [Dependency] -> [Command] -> Entry
Assignment :: AssignmentType -> Text -> Text -> Entry
-- | Catch all value for comments, empty lines and lines that failed to
-- parse.
OtherLine :: Text -> Entry
data AssignmentType
-- | foo = bar
RecursiveAssign :: AssignmentType
-- | foo := bar
SimpleAssign :: AssignmentType
-- | foo ::= bar
SimplePosixAssign :: AssignmentType
-- | foo ?= bar
ConditionalAssign :: AssignmentType
-- | foo != bar
ShellAssign :: AssignmentType
-- | foo += bar
AppendAssign :: AssignmentType
-- | Makefile target (foo in the example above)
newtype Target
Target :: Text -> Target
-- | Target dependency (bar in the example above)
newtype Dependency
Dependency :: Text -> Dependency
-- | Command (baz in the example above)
newtype Command
Command :: Text -> Command
instance GHC.Classes.Eq Data.Makefile.Makefile
instance GHC.Read.Read Data.Makefile.Makefile
instance GHC.Show.Show Data.Makefile.Makefile
instance GHC.Classes.Eq Data.Makefile.Entry
instance GHC.Read.Read Data.Makefile.Entry
instance GHC.Show.Show Data.Makefile.Entry
instance Data.String.IsString Data.Makefile.Command
instance GHC.Classes.Eq Data.Makefile.Command
instance GHC.Read.Read Data.Makefile.Command
instance GHC.Show.Show Data.Makefile.Command
instance Data.String.IsString Data.Makefile.Dependency
instance GHC.Classes.Eq Data.Makefile.Dependency
instance GHC.Read.Read Data.Makefile.Dependency
instance GHC.Show.Show Data.Makefile.Dependency
instance Data.String.IsString Data.Makefile.Target
instance GHC.Classes.Eq Data.Makefile.Target
instance GHC.Read.Read Data.Makefile.Target
instance GHC.Show.Show Data.Makefile.Target
instance GHC.Enum.Bounded Data.Makefile.AssignmentType
instance GHC.Enum.Enum Data.Makefile.AssignmentType
instance GHC.Classes.Eq Data.Makefile.AssignmentType
instance GHC.Read.Read Data.Makefile.AssignmentType
instance GHC.Show.Show Data.Makefile.AssignmentType
module Data.Makefile.Parse.Internal
-- | Parse makefile.
--
-- Tries to open and parse a file name Makefile in the current
-- directory.
parseMakefile :: IO (Either String Makefile)
-- | Parse the specified file as a makefile.
parseAsMakefile :: FilePath -> IO (Either String Makefile)
parseMakefileContents :: Text -> Either String Makefile
-- | Similar to parseOnly but fails if all input has not been
-- consumed.
parseAll :: Parser a -> Text -> Either String a
-- | Parser for a makefile
makefile :: Parser Makefile
-- | Parser for a makefile entry (either a rule or a variable assignment)
entry :: Parser Entry
-- | Parser of variable assignment (see Assignment). Note that
-- leading and trailing whitespaces will be stripped both from the
-- variable name and assigned value.
--
-- Note that this tries to follow GNU make's (crazy) behavior when it
-- comes to variable names and assignment operators.
--
-- -- >>> parseAll assignment "foo = bar " -- Right (Assignment RecursiveAssign "foo" "bar") ---- --
-- >>> parseAll assignment "foo := bar " -- Right (Assignment SimpleAssign "foo" "bar") ---- --
-- >>> parseAll assignment "foo ::= bar " -- Right (Assignment SimplePosixAssign "foo" "bar") ---- --
-- >>> parseAll assignment "foo?= bar " -- Right (Assignment ConditionalAssign "foo" "bar") ---- --
-- >>> parseAll assignment "foo??= bar " -- Right (Assignment ConditionalAssign "foo?" "bar") ---- --
-- >>> parseAll assignment "foo!?!= bar " -- Right (Assignment ShellAssign "foo!?" "bar") --assignment :: Parser Entry -- | Read chars while some (Parser, monadic) predicate is -- True. -- -- XXX: extremely inefficient. takeWhileM :: (Char -> Parser Bool) -> Parser Text -- | Parse a variable name, not consuming any of the assignment operator. -- See also assignment. -- --
-- >>> Atto.parseOnly variableName "foo!?!= bar " -- Right "foo!?" --variableName :: Parser Text -- | Parse an assignment type, not consuming any of the assigned value. See -- also assignment. -- --
-- >>> Atto.parseOnly assignmentType "!= bar " -- Right ShellAssign --assignmentType :: Parser AssignmentType -- | Parser for an entire rule rule :: Parser Entry -- | Succeeds on endOfLine (line end) or if the end of input is -- reached. endOfLine' :: Parser () -- | Parser for a command command :: Parser Command recipeLine :: Parser Text -- | Parser for a (rule) target target :: Parser Target -- | Parser for a (rule) dependency dependency :: Parser Dependency -- | Catch all, used for * comments, empty lines * lines that failed to -- parse -- --
-- >>> parseAll otherLine "# I AM A COMMENT\n" -- Right (OtherLine "# I AM A COMMENT") ---- -- Ensure all Entrys consume the end of line: >>> -- parseAll otherLine "n" Right (OtherLine "") otherLine :: Parser Entry toLineEnd :: Parser Text -- | Get the contents until the end of the (potentially multi) line. -- Multiple lines are separated by a \ char and individual lines -- will be stripped and spaces will be interspersed. -- -- The final n character is consumed. -- --
-- >>> Atto.parseOnly toEscapedLineEnd "foo bar \\\n baz" -- Right "foo bar baz" ---- --
-- >>> Atto.parseOnly toEscapedLineEnd "foo \t\\\n bar \\\n baz \\\n \t" -- Right "foo bar baz" --toEscapedLineEnd :: Parser Text stripped :: Parser Text -> Parser Text module Data.Makefile.Parse -- | Parse makefile. -- -- Tries to open and parse a file name Makefile in the current -- directory. parseMakefile :: IO (Either String Makefile) -- | Parse the specified file as a makefile. parseAsMakefile :: FilePath -> IO (Either String Makefile) parseMakefileContents :: Text -> Either String Makefile -- | Parser for a makefile makefile :: Parser Makefile -- | Parser for a makefile entry (either a rule or a variable assignment) entry :: Parser Entry -- | Parser of variable assignment (see Assignment). Note that -- leading and trailing whitespaces will be stripped both from the -- variable name and assigned value. -- -- Note that this tries to follow GNU make's (crazy) behavior when it -- comes to variable names and assignment operators. -- --
-- >>> parseAll assignment "foo = bar " -- Right (Assignment RecursiveAssign "foo" "bar") ---- --
-- >>> parseAll assignment "foo := bar " -- Right (Assignment SimpleAssign "foo" "bar") ---- --
-- >>> parseAll assignment "foo ::= bar " -- Right (Assignment SimplePosixAssign "foo" "bar") ---- --
-- >>> parseAll assignment "foo?= bar " -- Right (Assignment ConditionalAssign "foo" "bar") ---- --
-- >>> parseAll assignment "foo??= bar " -- Right (Assignment ConditionalAssign "foo?" "bar") ---- --
-- >>> parseAll assignment "foo!?!= bar " -- Right (Assignment ShellAssign "foo!?" "bar") --assignment :: Parser Entry -- | Parse a variable name, not consuming any of the assignment operator. -- See also assignment. -- --
-- >>> Atto.parseOnly variableName "foo!?!= bar " -- Right "foo!?" --variableName :: Parser Text -- | Parse an assignment type, not consuming any of the assigned value. See -- also assignment. -- --
-- >>> Atto.parseOnly assignmentType "!= bar " -- Right ShellAssign --assignmentType :: Parser AssignmentType -- | Parser for an entire rule rule :: Parser Entry -- | Parser for a command command :: Parser Command -- | Parser for a (rule) target target :: Parser Target -- | Parser for a (rule) dependency dependency :: Parser Dependency -- | Catch all, used for * comments, empty lines * lines that failed to -- parse -- --
-- >>> parseAll otherLine "# I AM A COMMENT\n" -- Right (OtherLine "# I AM A COMMENT") ---- -- Ensure all Entrys consume the end of line: >>> -- parseAll otherLine "n" Right (OtherLine "") otherLine :: Parser Entry -- | Get the contents until the end of the (potentially multi) line. -- Multiple lines are separated by a \ char and individual lines -- will be stripped and spaces will be interspersed. -- -- The final n character is consumed. -- --
-- >>> Atto.parseOnly toEscapedLineEnd "foo bar \\\n baz" -- Right "foo bar baz" ---- --
-- >>> Atto.parseOnly toEscapedLineEnd "foo \t\\\n bar \\\n baz \\\n \t" -- Right "foo bar baz" --toEscapedLineEnd :: Parser Text module Data.Makefile.Render.Internal writeMakefile :: FilePath -> Makefile -> IO () encodeMakefile :: Makefile -> Text renderMakefile :: Makefile -> Builder encodeEntry :: Entry -> Text renderEntry :: Entry -> Builder intercalate :: Monoid a => a -> [a] -> a renderDep :: Dependency -> Builder renderCmd :: Command -> Builder module Data.Makefile.Render encodeMakefile :: Makefile -> Text writeMakefile :: FilePath -> Makefile -> IO ()