Agda-2.8.0: A dependently typed functional programming language and proof assistant

Safe Haskell | None
Language | Haskell2010

Agda.Syntax.Parser

Contents

- Types
- Parse functions
- Parsers
- Reading files.
- Parse errors

Synopsis

- data Parser a
- parse :: Parser a -> String -> PM (a, Attributes)
- parsePosString :: Parser a -> Position -> String -> PM (a, Attributes)
- parseFile :: Show a => Parser a -> RangeFile -> String -> PM ((a, Attributes), FileType)
- moduleParser :: Parser Module
- moduleNameParser :: Parser QName
- agdaFileExtensions :: [String]
- exprParser :: Parser Expr
- exprWhereParser :: Parser ExprWhere
- holeContentParser :: Parser HoleContent
- tokensParser :: Parser [Token]
- readFilePM :: RangeFile -> PM Text
- data ParseError
  - = ParseError {
    - errSrcFile :: !SrcFile
    - errPos :: !PositionWithoutFile
    - errInput :: String
    - errPrevToken :: String
    - errMsg :: String
    }
  - | OverlappingTokensError {
    - errRange :: !(Range' SrcFile)
    }
  - | InvalidExtensionError {
    - errPath :: !RangeFile
    - errValidExts :: [String]
    }
  - | ReadFileError {
    - errPath :: !RangeFile
    - errIOError :: IOError
    }
- data ParseWarning
  - = OverlappingTokensWarning {
    - warnRange :: !(Range' SrcFile)
    }
  - | MisplacedAttributes Range String
  - | UnknownPolarity Range String
  - | UnknownAttribute Range String
  - | UnsupportedAttribute Range !(Maybe String)
  - | MultipleAttributes Range !(Maybe String)
- newtype PM a = PM {
  - unPM :: ExceptT ParseError (StateT [ParseWarning] IO) a
  }
- runPMIO :: MonadIO m => PM a -> m (Either ParseError a, [ParseWarning])

# Types

data Parser a Source #

Wrapped Parser type.

# Parse functions

parse :: Parser a -> String -> PM (a, Attributes) Source #

Parse without top-level layout.

parsePosString :: Parser a -> Position -> String -> PM (a, Attributes) Source #

parseFile Source #

Arguments

:: Show a |
=> Parser a |
-> RangeFile | The file.
-> String | The file contents. Note that the file is not read from disk.
-> PM ((a, Attributes), FileType) |

# Parsers

moduleParser :: Parser Module Source #

Parses a module.

moduleNameParser :: Parser QName Source #

Parses a module name.

agdaFileExtensions :: [String] Source #

Extensions supported by `parseFile`.

exprParser :: Parser Expr Source #

Parses an expression.

exprWhereParser :: Parser ExprWhere Source #

Parses an expression followed by a where clause.

holeContentParser :: Parser HoleContent Source #

Parses an expression or some other content of an interaction hole.

tokensParser :: Parser [Token] Source #

Gives the parsed token stream (including comments).

# Reading files.

readFilePM :: RangeFile -> PM Text Source #

Returns the contents of the given file.

# Parse errors

data ParseError Source #

Parse errors: what you get if parsing fails.

Constructors

ParseError | Errors that arise at a specific position in the file

Fields

- errSrcFile :: !SrcFile

  The file in which the error occurred.

- errPos :: !PositionWithoutFile

  Where the error occurred.

- errInput :: String

  The remaining input.

- errPrevToken :: String

  The previous token.

- errMsg :: String

  Hopefully an explanation of what happened.

OverlappingTokensError | Parse errors that concern a range in a file.

Fields

- errRange :: !(Range' SrcFile)

  The range of the bigger overlapping token

InvalidExtensionError | Parse errors that concern a whole file.

Fields

- errPath :: !RangeFile

  The file which the error concerns.

- errValidExts :: [String]

ReadFileError |

Fields

- errPath :: !RangeFile

  The file which the error concerns.

- errIOError :: IOError

#### Instances

Instances details

Pretty ParseError Source # |
Instance details Defined in Agda.Syntax.Parser.Monad Methods pretty :: ParseError -> Doc Source # prettyPrec :: Int -> ParseError -> Doc Source # prettyList :: [ParseError] -> Doc Source #
HasRange ParseError Source # |
Instance details Defined in Agda.Syntax.Parser.Monad Methods getRange :: ParseError -> Range Source #
NFData ParseError Source # |
Instance details Defined in Agda.Syntax.Parser.Monad Methods rnf :: ParseError -> () Source #
Show ParseError Source # |
Instance details Defined in Agda.Syntax.Parser.Monad Methods showsPrec :: Int -> ParseError -> ShowS Source # show :: ParseError -> String Source # showList :: [ParseError] -> ShowS Source #
MonadError ParseError PM Source # |
Instance details Defined in Agda.Syntax.Parser Methods throwError :: ParseError -> PM a Source # catchError :: PM a -> (ParseError -> PM a) -> PM a Source #
MonadError ParseError Parser Source # |
Instance details Defined in Agda.Syntax.Parser.Monad Methods throwError :: ParseError -> Parser a Source # catchError :: Parser a -> (ParseError -> Parser a) -> Parser a Source #

data ParseWarning Source #

Warnings for parsing.

Constructors

OverlappingTokensWarning | Parse errors that concern a range in a file.

Fields

- warnRange :: !(Range' SrcFile)

  The range of the bigger overlapping token.

MisplacedAttributes Range String | The `String` is the error message.
UnknownPolarity Range String | Unknown polarity, ignored.
UnknownAttribute Range String | Unknown attribute, ignored. The `Range` includes the "@", the `String` not.
UnsupportedAttribute Range !(Maybe String) | Unsupported attribute.
MultipleAttributes Range !(Maybe String) | Multiple attributes.

#### Instances

Instances details

Pretty ParseWarning Source # | Does not include printing of the range.
Instance details Defined in Agda.Syntax.Parser.Monad Methods pretty :: ParseWarning -> Doc Source # prettyPrec :: Int -> ParseWarning -> Doc Source # prettyList :: [ParseWarning] -> Doc Source #
HasRange ParseWarning Source # |
Instance details Defined in Agda.Syntax.Parser.Monad Methods getRange :: ParseWarning -> Range Source #
EmbPrj ParseWarning Source # |
Instance details Defined in Agda.TypeChecking.Serialise.Instances.Errors Methods icode :: ParseWarning -> S Word32 Source # icod_ :: ParseWarning -> S Word32 Source # value :: Word32 -> R ParseWarning Source #
NFData ParseWarning Source # |
Instance details Defined in Agda.Syntax.Parser.Monad Methods rnf :: ParseWarning -> () Source #
Show ParseWarning Source # |
Instance details Defined in Agda.Syntax.Parser.Monad Methods showsPrec :: Int -> ParseWarning -> ShowS Source # show :: ParseWarning -> String Source # showList :: [ParseWarning] -> ShowS Source #
MonadState [ParseWarning] PM Source # |
Instance details Defined in Agda.Syntax.Parser Methods get :: PM [ParseWarning] Source # put :: [ParseWarning] -> PM () Source # state :: ([ParseWarning] -> (a, [ParseWarning])) -> PM a Source #

newtype PM a Source #

A monad for handling parse errors and warnings.

Constructors

PM |

Fields

- unPM :: ExceptT ParseError (StateT [ParseWarning] IO) a

#### Instances

Instances details

MonadIO PM Source # |
Instance details Defined in Agda.Syntax.Parser Methods liftIO :: IO a -> PM a Source #
Applicative PM Source # |
Instance details Defined in Agda.Syntax.Parser Methods pure :: a -> PM a Source # (<*>) :: PM (a -> b) -> PM a -> PM b Source # liftA2 :: (a -> b -> c) -> PM a -> PM b -> PM c Source # (*>) :: PM a -> PM b -> PM b Source # (<*) :: PM a -> PM b -> PM a Source #
Functor PM Source # |
Instance details Defined in Agda.Syntax.Parser Methods fmap :: (a -> b) -> PM a -> PM b Source # (<$) :: a -> PM b -> PM a Source #
Monad PM Source # |
Instance details Defined in Agda.Syntax.Parser Methods (>>=) :: PM a -> (a -> PM b) -> PM b Source # (>>) :: PM a -> PM b -> PM b Source # return :: a -> PM a Source #
MonadError ParseError PM Source # |
Instance details Defined in Agda.Syntax.Parser Methods throwError :: ParseError -> PM a Source # catchError :: PM a -> (ParseError -> PM a) -> PM a Source #
MonadState [ParseWarning] PM Source # |
Instance details Defined in Agda.Syntax.Parser Methods get :: PM [ParseWarning] Source # put :: [ParseWarning] -> PM () Source # state :: ([ParseWarning] -> (a, [ParseWarning])) -> PM a Source #

runPMIO :: MonadIO m => PM a -> m (Either ParseError a, [ParseWarning]) Source #

Run a `PM` computation, returning a list of warnings in first-to-last order and either a parse error or the parsed thing.