| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Text.LaTeX.Base.Parser
Contents
Description
The LaTeX parser.
Use parseLaTeX to parse a Text containing LaTeX code.
If the Text is in a file, you may want to use parseLaTeXFile.
Use this module together with Text.LaTeX.Base.Syntax to perform
analysis and transformations of LaTeX code. The parser (parseLaTeX)
is related with the renderer (render) by the following property:
If t :: Text is a syntactically valid LaTeX block, then:
fmap render (parseLaTeX t) == Right t
This property says two things:
- Given a valid LaTeX input,
parseLaTeXreturns aLaTeXvalue. - If the parsed value is again rendered, you get the initial input.
In other words, parseLaTeX is a partial function defined over the
set of valid LaTeX files, and render is its left inverse.
- parseLaTeX :: Text -> Either ParseError LaTeX
- parseLaTeXFile :: FilePath -> IO (Either ParseError LaTeX)
- data ParseError :: *
- errorPos :: ParseError -> SourcePos
- errorMessages :: ParseError -> [Message]
- data Message :: *
- messageString :: Message -> String
- data SourcePos :: *
- sourceLine :: SourcePos -> Line
- sourceColumn :: SourcePos -> Column
- sourceName :: SourcePos -> SourceName
- data ParserConf = ParserConf {}
- defaultParserConf :: ParserConf
- parseLaTeXWith :: ParserConf -> Text -> Either ParseError LaTeX
- parseLaTeXFileWith :: ParserConf -> FilePath -> IO (Either ParseError LaTeX)
- type Parser = Parsec Text ParserConf
- latexParser :: Parser LaTeX
- latexBlockParser :: Parser LaTeX
The parser
parseLaTeX :: Text -> Either ParseError LaTeX Source #
parseLaTeXFile :: FilePath -> IO (Either ParseError LaTeX) Source #
Read a file and parse it as LaTeX.
Parsing errors
data ParseError :: * #
The abstract data type ParseError represents parse errors. It
provides the source position (SourcePos) of the error
and a list of error messages (Message). A ParseError
can be returned by the function parse. ParseError is an
instance of the Show and Eq classes.
Instances
errorPos :: ParseError -> SourcePos #
Extracts the source position from the parse error
errorMessages :: ParseError -> [Message] #
Extracts the list of error messages from the parse error
Error messages
This abstract data type represents parse error messages. There are four kinds of messages:
data Message = SysUnExpect String
| UnExpect String
| Expect String
| Message StringThe fine distinction between different kinds of parse errors allows the system to generate quite good error messages for the user. It also allows error messages that are formatted in different languages. Each kind of message is generated by different combinators:
- A
SysUnExpectmessage is automatically generated by thesatisfycombinator. The argument is the unexpected input. - A
UnExpectmessage is generated by theunexpectedcombinator. The argument describes the unexpected item. - A
Expectmessage is generated by the<?>combinator. The argument describes the expected item. - A
Messagemessage is generated by thefailcombinator. The argument is some general parser message.
messageString :: Message -> String #
Extract the message string from an error message
Source positions
sourceLine :: SourcePos -> Line #
Extracts the line number from a source position.
sourceColumn :: SourcePos -> Column #
Extracts the column number from a source position.
sourceName :: SourcePos -> SourceName #
Extracts the name of the source from a source position.
Configuring your parser
data ParserConf Source #
Configuration for the LaTeX parser.
Constructors
| ParserConf | |
Fields
| |
defaultParserConf :: ParserConf Source #
Default parser configuration, used by parseLaTeX and parseLaTeXFile.
Defaults:
verbatimEnvironments = ["verbatim"]
parseLaTeXWith :: ParserConf -> Text -> Either ParseError LaTeX Source #
parseLaTeXFileWith :: ParserConf -> FilePath -> IO (Either ParseError LaTeX) Source #
Parser combinators
type Parser = Parsec Text ParserConf Source #
Parser with Text input and ParserConf environment.