swarm-0.6.0.0: 2D resource gathering game with programmable robots
LicenseBSD-3-Clause
Safe HaskellSafe-Inferred
LanguageHaskell2010

Swarm.Language.Parser.Core

Description

Core data type definitions and utilities for the Swarm language parser.

Synopsis

Parser configuration

data Antiquoting Source #

When parsing a term using a quasiquoter (i.e. something in the Swarm source code that will be parsed at compile time), we want to allow antiquoting, i.e. writing something like $x to refer to an existing Haskell variable. But when parsing a term entered by the user at the REPL, we do not want to allow this syntax.

data LanguageVersion Source #

Which version of the Swarm language are we parsing? As a general rule, we want to support one older version in addition to the current version, to allow for upgrading code via swarm format.

Instances

Instances details
Bounded LanguageVersion Source # 
Instance details

Defined in Swarm.Language.Parser.Core

Enum LanguageVersion Source # 
Instance details

Defined in Swarm.Language.Parser.Core

Show LanguageVersion Source # 
Instance details

Defined in Swarm.Language.Parser.Core

Eq LanguageVersion Source # 
Instance details

Defined in Swarm.Language.Parser.Core

Ord LanguageVersion Source # 
Instance details

Defined in Swarm.Language.Parser.Core

data ParserConfig Source #

Read-only parser configuration.

Comment parsing state

data CommentState Source #

Constructors

CS 

Fields

  • _freshLine :: Bool

    Are we currently on a (so far) blank line, i.e. have there been no nontrivial tokens since the most recent newline? This field is updated every time we parse a lexeme or symbol (set to false), or a newline (set to true).

  • _comments :: Seq Comment

    The actual sequence of comments, in the order they were encountered

Parser type

Running

runParser :: Parser a -> Text -> Either ParserError (a, Seq Comment) Source #

Run a parser on some input text, returning either the result + all collected comments, or a parse error message.

runParser' :: ParserConfig -> Parser a -> Text -> Either ParserError (a, Seq Comment) Source #

Like runParser, but allow configuring with an arbitrary ParserConfig.

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.Parser.QQ), with a specified source position.