| License | BSD-3-Clause |
|---|---|
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Swarm.Language.Parser.Lex
Description
Token lexing and comment preservation for the Swarm language.
Synopsis
- parseLoc :: Parser Term -> Parser Syntax
- parseLocG :: Parser a -> Parser (SrcLoc, a)
- getCommentSituation :: Parser CommentSituation
- lineComment :: Text -> Parser ()
- blockComment :: Text -> Text -> Parser ()
- sc :: Parser ()
- lexeme :: Parser a -> Parser a
- symbol :: Text -> Parser Text
- operator :: Text -> Parser Text
- reservedWords :: Set Text
- reservedCS :: Text -> Parser ()
- reserved :: Text -> Parser ()
- data IdentifierType
- locIdentifier :: IdentifierType -> Parser LocVar
- locTmVar :: Parser LocVar
- locTyName :: Parser LocVar
- identifier :: IdentifierType -> Parser Var
- tyVar :: Parser Var
- tyName :: Parser Var
- tmVar :: Parser Var
- textLiteral :: Parser Text
- integer :: Parser Integer
- braces :: Parser a -> Parser a
- parens :: Parser a -> Parser a
- brackets :: Parser a -> Parser a
Parsing with source locations
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.
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
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.
data IdentifierType Source #
What kind of identifier are we parsing?
Instances
| Show IdentifierType Source # | |
Defined in Swarm.Language.Parser.Lex Methods showsPrec :: Int -> IdentifierType -> ShowS # show :: IdentifierType -> String # showList :: [IdentifierType] -> ShowS # | |
| Eq IdentifierType Source # | |
Defined in Swarm.Language.Parser.Lex Methods (==) :: IdentifierType -> IdentifierType -> Bool # (/=) :: IdentifierType -> IdentifierType -> Bool # | |
| Ord IdentifierType Source # | |
Defined in Swarm.Language.Parser.Lex Methods compare :: IdentifierType -> IdentifierType -> Ordering # (<) :: IdentifierType -> IdentifierType -> Bool # (<=) :: IdentifierType -> IdentifierType -> Bool # (>) :: IdentifierType -> IdentifierType -> Bool # (>=) :: IdentifierType -> IdentifierType -> Bool # max :: IdentifierType -> IdentifierType -> IdentifierType # min :: IdentifierType -> IdentifierType -> IdentifierType # | |
locIdentifier :: IdentifierType -> Parser LocVar Source #
Parse an identifier 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.
Parse a type variable, which must start with an underscore or lowercase letter and cannot be the lowercase version of a type name.
Parse a (user-defined) type constructor name, which must start with an uppercase letter.
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.