toml-parser-2.0.2.0: TOML 1.1.0 parser

Copyright | (c) Eric Mertens 2023
License | ISC
Maintainer | emertens@gmail.com
Safe Haskell | None
Language | Haskell2010

Toml.Syntax.Lexer

Description

This module parses a TOML file into a lazy sequence of tokens. The lexer is aware of nested brackets and equals signs in order to handle TOML's context-sensitive lexing requirements. This context enables the lexer to distinguish between bare keys and various values like: floating-point literals, integer literals, and date literals.

This module uses actions and lexical hooks defined in LexerUtils.

Synopsis

- data Context
  - = TopContext
  - | TableContext
  - | ValueContext
  - | MlBstrContext Position [Text]
  - | BstrContext Position [Text]
  - | MlLstrContext Position [Text]
  - | LstrContext Position [Text]
- scanToken :: Context -> Located Text -> Either (Located String) (Located Token, Located Text)
- lexValue :: Text -> Either String Token
- data Token
  - = TokTrue
  - | TokFalse
  - | TokComma
  - | TokEquals
  - | TokNewline
  - | TokPeriod
  - | TokSquareO
  - | TokSquareC
  - | Tok2SquareO
  - | Tok2SquareC
  - | TokCurlyO
  - | TokCurlyC
  - | TokBareKey Text
  - | TokString Text
  - | TokMlString Text
  - | TokInteger !Integer
  - | TokFloat !Double
  - | TokOffsetDateTime !ZonedTime
  - | TokLocalDateTime !LocalTime
  - | TokLocalDate !Day
  - | TokLocalTime !TimeOfDay
  - | TokEOF

# Documentation

data Context Source #

Representation of the current lexer state.

Constructors

TopContext | top-level where `[[` and `]]` have special meaning
TableContext | inline table - lex key names
ValueContext | value lexer - lex number literals
MlBstrContext Position [Text] | multiline basic string: position of opening delimiter and list of fragments
BstrContext Position [Text] | basic string: position of opening delimiter and list of fragments
MlLstrContext Position [Text] | multiline literal string: position of opening delimiter and list of fragments
LstrContext Position [Text] | literal string: position of opening delimiter and list of fragments

#### Instances

Instances details

Show Context Source # |
Instance details Defined in Toml.Syntax.LexerUtils Methods showsPrec :: Int -> Context -> ShowS Source # show :: Context -> String Source # showList :: [Context] -> ShowS Source #

scanToken :: Context -> Located Text -> Either (Located String) (Located Token, Located Text) Source #

Get the next token from a located string or a located error message.

lexValue :: Text -> Either String Token Source #

Lex a single token in a value context. This is mostly useful for testing.

data Token Source #

Lexical token

Constructors

TokTrue

    true

TokFalse

    false

TokComma

    ','

TokEquals

    '='

TokNewline

    end-of-line

TokPeriod

    .

TokSquareO

    '['

TokSquareC

    ']'

Tok2SquareO

    '[['

Tok2SquareC

    ']]'

TokCurlyO

    '{'

TokCurlyC

    '}'

TokBareKey Text | bare key
TokString Text | string literal
TokMlString Text | multiline string literal
TokInteger !Integer | integer literal
TokFloat !Double | floating-point literal
TokOffsetDateTime !ZonedTime | date-time with timezone offset
TokLocalDateTime !LocalTime | local date-time
TokLocalDate !Day | local date
TokLocalTime !TimeOfDay | local time

TokEOF

    end-of-input

#### Instances

Instances details

Read Token Source # |
Instance details Defined in Toml.Syntax.Token Methods readsPrec :: Int -> ReadS Token Source # readList :: ReadS [Token] Source # readPrec :: ReadPrec Token Source # readListPrec :: ReadPrec [Token] Source #
Show Token Source # |
Instance details Defined in Toml.Syntax.Token Methods showsPrec :: Int -> Token -> ShowS Source # show :: Token -> String Source # showList :: [Token] -> ShowS Source #