swarm-0.1.0.0: 2D resource gathering game with programmable robots
CopyrightBrent Yorgey
LicenseBSD-3-Clause
Maintainerbyorgey@gmail.com
Safe HaskellSafe-Inferred
LanguageHaskell2010

Swarm.Language.Parse

Description

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

Reserved words

reservedWords :: [Text] Source #

List of reserved words that cannot be used as variable names.

Parsers

type Parser = ReaderT Antiquoting (Parsec Void Text) Source #

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.

parseType :: Parser Type Source #

Parse a Swarm language (mono)type.

parseTerm :: Parser Syntax Source #

Parse a Swarm language term.

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 Text (Maybe Syntax) Source #

Parse some input Text completely as a Term, consuming leading whitespace and ensuring the parsing extends all the way to the end of the input Text. Returns either the resulting Term (or Nothing if the input was only whitespace) or a pretty-printed parse error message.

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 #

A utility for converting a ParserError into a one line message: line-nr: error-msg

showErrorPos :: ParserError -> ((Int, Int), (Int, Int), Text) Source #

A utility for converting a ParseError into a range and error message.

getLocRange :: Text -> (Int, Int) -> ((Int, Int), (Int, Int)) Source #

A utility for converting a Location into a range