Copyright | Brent Yorgey |
---|---|
License | BSD-3-Clause |
Maintainer | byorgey@gmail.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Parser for the Swarm language. Note, you probably don't want to
use this directly, unless there is a good reason to parse a term
without also type checking it; use
processTerm
instead, which parses,
typechecks, elaborates, and capability checks a term all at once.
Synopsis
- reservedWords :: [Text]
- type Parser = ReaderT Antiquoting (Parsec Void Text)
- parsePolytype :: Parser Polytype
- parseType :: Parser Type
- parseTerm :: Parser Syntax
- binOps :: Map Int [Operator Parser Syntax]
- unOps :: Map Int [Operator Parser Syntax]
- runParser :: Parser a -> Text -> Either Text a
- runParserTH :: (Monad m, MonadFail m) => (String, Int, Int) -> Parser a -> String -> m a
- readTerm :: Text -> Either Text (Maybe Syntax)
- readTerm' :: Text -> Either ParserError (Maybe Syntax)
- showShortError :: ParserError -> String
- showErrorPos :: ParserError -> ((Int, Int), (Int, Int), Text)
- getLocRange :: Text -> (Int, Int) -> ((Int, Int), (Int, Int))
- unTuple :: Syntax' ty -> [Syntax' ty]
Reserved words
reservedWords :: [Text] Source #
List of reserved words that cannot be used as variable names.
Parsers
parsePolytype :: Parser Polytype Source #
Parse a Swarm language polytype, which starts with an optional
quanitifation (forall
followed by one or more variables and a
period) followed by a type. Note that anything accepted by
parseType
is also accepted by parsePolytype
.
binOps :: Map Int [Operator Parser Syntax] Source #
Precedences and parsers of binary operators.
>>>
Map.map length binOps
fromList [(0,1),(2,1),(3,1),(4,6),(6,3),(7,2),(8,1)]
unOps :: Map Int [Operator Parser Syntax] Source #
Precedences and parsers of unary operators (currently only Neg
).
>>>
Map.map length unOps
fromList [(7,1)]
Utility functions
runParser :: Parser a -> Text -> Either Text a Source #
Run a parser on some input text, returning either the result or a pretty-printed parse error message.
runParserTH :: (Monad m, MonadFail m) => (String, Int, Int) -> Parser a -> String -> m a Source #
A utility for running a parser in an arbitrary MonadFail
(which
is going to be the TemplateHaskell Q
monad --- see
Swarm.Language.Parse.QQ), with a specified source position.
readTerm' :: Text -> Either ParserError (Maybe Syntax) Source #
A lower-level readTerm
which returns the megaparsec bundle error
for precise error reporting.
showShortError :: ParserError -> String Source #
showErrorPos :: ParserError -> ((Int, Int), (Int, Int), Text) Source #
A utility for converting a ParseError into a range and error message.