makefile- Simple Makefile parser and generator

Safe HaskellNone




>>> :set -XOverloadedStrings

parseMakefile :: IO (Either String Makefile) Source #

Parse makefile.

Tries to open and parse a file name Makefile in the current directory.

parseAsMakefile :: FilePath -> IO (Either String Makefile) Source #

Parse the specified file as a makefile.

parseAll :: Parser a -> Text -> Either String a Source #

Similar to parseOnly but fails if all input has not been consumed.

makefile :: Parser Makefile Source #

Parser for a makefile

entry :: Parser Entry Source #

Parser for a makefile entry (either a rule or a variable assignment)

assignment :: Parser Entry Source #

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")

takeWhileM :: (Char -> Parser Bool) -> Parser Text Source #

Read chars while some (Parser, monadic) predicate is True.

XXX: extremely inefficient.

variableName :: Parser Text Source #

Parse a variable name, not consuming any of the assignment operator. See also assignment.

>>> Atto.parseOnly variableName "foo!?!= bar "
Right "foo!?"

assignmentType :: Parser AssignmentType Source #

Parse an assignment type, not consuming any of the assigned value. See also assignment.

>>> Atto.parseOnly assignmentType "!= bar "
Right ShellAssign

rule :: Parser Entry Source #

Parser for an entire rule

endOfLine' :: Parser () Source #

Succeeds on endOfLine (line end) or if the end of input is reached.

command :: Parser Command Source #

Parser for a command

target :: Parser Target Source #

Parser for a (rule) target

dependency :: Parser Dependency Source #

Parser for a (rule) dependency

otherLine :: Parser Entry Source #

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 "")

toEscapedLineEnd :: Parser Text Source #

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"