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

Swarm.Language.Parser.Lex

Description

Token lexing and comment preservation for the Swarm language.

Synopsis

Parsing with source locations

parseLocG :: Parser a -> Parser (SrcLoc, a) Source #

Add SrcLoc to a parser

Whitespace + comments

getCommentSituation :: Parser CommentSituation Source #

If we see a comment starting now, is it the first non-whitespace thing on the current line so far, or were there other non-whitespace tokens previously?

lineComment :: Text -> Parser () Source #

Parse a line comment, while appending it out-of-band to the list of comments saved in the custom state.

blockComment :: Text -> Text -> Parser () Source #

Parse a block comment, while appending it out-of-band to the list of comments saved in the custom state.

sc :: Parser () Source #

Skip spaces and comments.

Tokens

Lexemes

lexeme :: Parser a -> Parser a Source #

In general, we follow the convention that every token parser assumes no leading whitespace and consumes all trailing whitespace. Concretely, we achieve this by wrapping every token parser using lexeme.

Also sets freshLine to False every time we see a non-whitespace token.

Specific token types

symbol :: Text -> Parser Text Source #

A lexeme consisting of a literal string.

operator :: Text -> Parser Text Source #

A lexeme consisting of a specific string, not followed by any other operator character.

reservedWords :: Set Text Source #

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

reservedCS :: Text -> Parser () Source #

Parse a case-sensitive reserved word.

reserved :: Text -> Parser () Source #

Parse a case-insensitive reserved word.

locIdentifier :: IdentifierType -> Parser LocVar Source #

Parse an identifier together with its source location info.

locTmVar :: Parser LocVar Source #

Parse a term variable together with its source location info.

locTyName :: Parser LocVar Source #

Parse a user-defined type name together with its source location info.

identifier :: IdentifierType -> Parser Var Source #

Parse an identifier, i.e. any non-reserved string containing alphanumeric characters and underscores, not starting with a digit. The Bool indicates whether we are parsing a type variable.

tyVar :: Parser Var Source #

Parse a type variable, which must start with an underscore or lowercase letter and cannot be the lowercase version of a type name.

tyName :: Parser Var Source #

Parse a (user-defined) type constructor name, which must start with an uppercase letter.

tmVar :: Parser Var Source #

Parse a term variable, which can start in any case and just cannot be the same (case-insensitively) as a lowercase reserved word.

textLiteral :: Parser Text Source #

Parse a text literal (including escape sequences) in double quotes.

integer :: Parser Integer Source #

Parse a positive integer literal token, in decimal, binary, octal, or hexadecimal notation. Note that negation is handled as a separate operator.

Combinators