Copyright | disco team and contributors |
---|---|
License | BSD-3-Clause |
Maintainer | byorgey@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
Parser to convert concrete Disco syntax into an (untyped, surface language) AST.
Synopsis
- data DiscoParseError
- = ReservedVarName String
- | InvalidPattern OpaqueTerm
- type Parser = StateT ParserState (Parsec DiscoParseError String)
- runParser :: Parser a -> FilePath -> String -> Either (ParseErrorBundle String DiscoParseError) a
- withExts :: Set Ext -> Parser a -> Parser a
- indented :: Parser a -> Parser a
- thenIndented :: Parser a -> Parser a
- sc :: Parser ()
- lexeme :: Parser a -> Parser a
- symbol :: String -> Parser String
- reservedOp :: String -> Parser ()
- natural :: Parser Integer
- reserved :: String -> Parser ()
- reservedWords :: [String]
- ident :: Parser (Name Term)
- parens :: Parser a -> Parser a
- braces :: Parser a -> Parser a
- angles :: Parser a -> Parser a
- brackets :: Parser a -> Parser a
- semi :: Parser String
- comma :: Parser String
- colon :: Parser String
- dot :: Parser String
- pipe :: Parser String
- lambda :: Parser String
- wholeModule :: LoadingMode -> Parser Module
- parseModule :: LoadingMode -> Parser Module
- parseExtName :: Parser Ext
- parseTopLevel :: Parser TopLevel
- parseDecl :: Parser Decl
- parseImport :: Parser String
- parseModuleName :: Parser String
- term :: Parser Term
- parseTerm :: Parser Term
- parseTerm' :: Parser Term
- parseExpr :: Parser Term
- parseAtom :: Parser Term
- parseContainer :: Container -> Parser Term
- parseEllipsis :: Parser (Ellipsis Term)
- parseContainerComp :: Container -> Term -> Parser Term
- parseQual :: Parser Qual
- parseLet :: Parser Term
- parseTypeOp :: Parser Term
- parseCase :: Parser Term
- parseBranch :: Parser Branch
- parseGuards :: Parser (Telescope Guard)
- parseGuard :: Parser Guard
- parsePattern :: Parser Pattern
- parseAtomicPattern :: Parser Pattern
- parseType :: Parser Type
- parseAtomicType :: Parser Type
- parsePolyTy :: Parser PolyType
Parser type and utilities
data DiscoParseError Source #
ReservedVarName String | |
InvalidPattern OpaqueTerm |
Instances
Eq DiscoParseError Source # | |
Defined in Disco.Parser (==) :: DiscoParseError -> DiscoParseError -> Bool # (/=) :: DiscoParseError -> DiscoParseError -> Bool # | |
Ord DiscoParseError Source # | |
Defined in Disco.Parser compare :: DiscoParseError -> DiscoParseError -> Ordering # (<) :: DiscoParseError -> DiscoParseError -> Bool # (<=) :: DiscoParseError -> DiscoParseError -> Bool # (>) :: DiscoParseError -> DiscoParseError -> Bool # (>=) :: DiscoParseError -> DiscoParseError -> Bool # max :: DiscoParseError -> DiscoParseError -> DiscoParseError # min :: DiscoParseError -> DiscoParseError -> DiscoParseError # | |
Show DiscoParseError Source # | |
Defined in Disco.Parser showsPrec :: Int -> DiscoParseError -> ShowS # show :: DiscoParseError -> String # showList :: [DiscoParseError] -> ShowS # | |
ShowErrorComponent DiscoParseError Source # | |
Defined in Disco.Parser |
type Parser = StateT ParserState (Parsec DiscoParseError String) Source #
A parser is a megaparsec parser of strings, with an extra layer of state to keep track of the current indentation level and language extensions, and some custom error messages.
runParser :: Parser a -> FilePath -> String -> Either (ParseErrorBundle String DiscoParseError) a Source #
Run a parser from the initial state.
withExts :: Set Ext -> Parser a -> Parser a Source #
Locally set the enabled extensions within a subparser.
indented :: Parser a -> Parser a Source #
indented p
is just like p
, except that every token must not
start in the first column.
thenIndented :: Parser a -> Parser a Source #
indented p
is just like p
, except that every token after the
first must not start in the first column.
Lexer
Basic lexemes
lexeme :: Parser a -> Parser a Source #
Parse a lexeme, that is, a parser followed by consuming whitespace.
reservedOp :: String -> Parser () Source #
Parse a reserved operator.
reservedWords :: [String] Source #
The list of all reserved words.
Punctuation
lambda :: Parser String Source #
The symbol that starts an anonymous function (either a backslash or a Greek λ).
Disco parser
Modules
wholeModule :: LoadingMode -> Parser Module Source #
Parse the entire input as a module (with leading whitespace and no leftovers).
parseModule :: LoadingMode -> Parser Module Source #
Parse an entire module (a list of declarations ended by
semicolons). The LoadingMode
parameter tells us whether to
include or replace any language extensions enabled at the top
level. We include them when parsing a module entered at the
REPL, and replace them when parsing a standalone module.
parseExtName :: Parser Ext Source #
Parse the name of a language extension (case-insensitive).
parseTopLevel :: Parser TopLevel Source #
Parse a top level item (either documentation or a declaration), which must start at the left margin.
parseDecl :: Parser Decl Source #
Parse a single top-level declaration (either a type declaration or single definition clause).
parseImport :: Parser String Source #
Parse an import, of the form import modulename
.
parseModuleName :: Parser String Source #
Parse the name of a module.
Terms
Parse the entire input as a term (with leading whitespace and no leftovers).
parseTerm :: Parser Term Source #
Parse a term, consisting of a parseTerm'
optionally
followed by an ascription.
parseTerm' :: Parser Term Source #
Parse a non-atomic, non-ascribed term.
parseContainer :: Container -> Parser Term Source #
Parse a container, like a literal list, set, bag, or a comprehension (not including the square or curly brackets).
container ::= '[' container-contents ']' | '{' container-contents '}' container-contents ::= empty | nonempty-container nonempty-container ::= term [ ellipsis ] | term container-end container-end ::= '|' comprehension | ',' [ term (',' item)* ] [ ellipsis ] comprehension ::= qual [ ',' qual ]* qual ::= ident 'in' term | term ellipsis ::= '..' [ term ]
parseEllipsis :: Parser (Ellipsis Term) Source #
Parse an ellipsis at the end of a literal list, of the form
.. t
. Any number > 1 of dots may be used, just for fun.
parseContainerComp :: Container -> Term -> Parser Term Source #
Parse the part of a list comprehension after the | (without square brackets), i.e. a list of qualifiers.
q [,q]*
parseQual :: Parser Qual Source #
Parse a qualifier in a comprehension: either a binder x in t
or
a guard t
.
parseTypeOp :: Parser Term Source #
Case and patterns
parseBranch :: Parser Branch Source #
Parse one branch of a case expression.
parseGuards :: Parser (Telescope Guard) Source #
Parse the list of guards in a branch. otherwise
can be used
interchangeably with an empty list of guards.
parseGuard :: Parser Guard Source #
Parse a single guard (if
, if ... is
, or let
)
parsePattern :: Parser Pattern Source #
Parse a pattern, by parsing a term and then attempting to convert it to a pattern.
parseAtomicPattern :: Parser Pattern Source #
Parse an atomic pattern, by parsing a term and then attempting to convert it to a pattern.
Types
parseAtomicType :: Parser Type Source #
Parse an atomic type.