toml-parser-2.0.2.0: TOML 1.1.0 parser

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

Toml.Syntax

Contents

- Parsing
- Lexing
- Locations

Description

These are the low-level processing functions for transforming concrete TOML syntax into abstract TOML syntax. This module does not do any semantic validation of the parsed TOML.

Synopsis

- parseRawToml :: Text -> Either (Located String) [Expr Position]
- type Key a = NonEmpty (a, Text)
- data Expr a
  - = KeyValExpr (Key a) (Val a)
  - | TableExpr (Key a)
  - | ArrayTableExpr (Key a)
- data Val a
  - = ValInteger a Integer
  - | ValFloat a Double
  - | ValArray a [Val a]
  - | ValTable a [(Key a, Val a)]
  - | ValBool a Bool
  - | ValString a Text
  - | ValTimeOfDay a TimeOfDay
  - | ValZonedTime a ZonedTime
  - | ValLocalTime a LocalTime
  - | ValDay a Day
- scanToken :: Context -> Located Text -> Either (Located String) (Located Token, Located Text)
- data Context
  - = TopContext
  - | TableContext
  - | ValueContext
  - | MlBstrContext Position [Text]
  - | BstrContext Position [Text]
  - | MlLstrContext Position [Text]
  - | LstrContext Position [Text]
- 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
- data Located a = Located {
  - locPosition :: !Position
  - locThing :: !a
  }
- data Position = Position {
  - posIndex :: !Int
  - posLine :: !Int
  - posColumn :: !Int
  }
- startPos :: Position

# Parsing

parseRawToml :: Text -> Either (Located String) [Expr Position] Source #

Parse a list of tokens either returning the first unexpected token or a list of the TOML statements in the file to be processed by Toml.Semantics.

type Key a = NonEmpty (a, Text) Source #

Non-empty sequence of dotted simple keys

data Expr a Source #

Headers and assignments corresponding to lines of a TOML file

Constructors

KeyValExpr (Key a) (Val a) | key value assignment: `key = value`
TableExpr (Key a) | table: `[key]`
ArrayTableExpr (Key a) | array of tables: `[[key]]`

#### Instances

Instances details

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

data Val a Source #

Unvalidated TOML values. Table are represented as a list of assignments rather than as resolved maps.

Constructors

ValInteger a Integer |
ValFloat a Double |
ValArray a [Val a] |
ValTable a [(Key a, Val a)] |
ValBool a Bool |
ValString a Text |
ValTimeOfDay a TimeOfDay |
ValZonedTime a ZonedTime |
ValLocalTime a LocalTime |
ValDay a Day |

#### Instances

Instances details

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

# Lexing

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.

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 #

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 #

# Locations

data Located a Source #

A value annotated with its text file position

Constructors

Located |

Fields

- locPosition :: !Position

  position

- locThing :: !a

  thing at position

#### Instances

Instances details

Functor Located Source # | Default instance
Instance details Defined in Toml.Syntax.Position Methods fmap :: (a -> b) -> Located a -> Located b Source # (<$) :: a -> Located b -> Located a Source #
Foldable Located Source # | Default instance

Instance details

Defined in Toml.Syntax.Position

Methods

fold :: Monoid m => Located m -> m Source #

foldMap :: Monoid m => (a -> m) -> Located a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Located a -> m Source #

foldr :: (a -> b -> b) -> b -> Located a -> b Source #

foldr' :: (a -> b -> b) -> b -> Located a -> b Source #

foldl :: (b -> a -> b) -> b -> Located a -> b Source #

foldl' :: (b -> a -> b) -> b -> Located a -> b Source #

foldr1 :: (a -> a -> a) -> Located a -> a Source #

foldl1 :: (a -> a -> a) -> Located a -> a Source #

toList :: Located a -> [a] Source #

null :: Located a -> Bool Source #

length :: Located a -> Int Source #

elem :: Eq a => a -> Located a -> Bool Source #

maximum :: Ord a => Located a -> a Source #

minimum :: Ord a => Located a -> a Source #

sum :: Num a => Located a -> a Source #

product :: Num a => Located a -> a Source #

Traversable Located Source # | Default instance
Instance details Defined in Toml.Syntax.Position Methods traverse :: Applicative f => (a -> f b) -> Located a -> f (Located b) Source # sequenceA :: Applicative f => Located (f a) -> f (Located a) Source # mapM :: Monad m => (a -> m b) -> Located a -> m (Located b) Source # sequence :: Monad m => Located (m a) -> m (Located a) Source #
Read a => Read (Located a) Source # | Default instance
Instance details Defined in Toml.Syntax.Position Methods readsPrec :: Int -> ReadS (Located a) Source # readList :: ReadS [Located a] Source # readPrec :: ReadPrec (Located a) Source # readListPrec :: ReadPrec [Located a] Source #
Show a => Show (Located a) Source # | Default instance
Instance details Defined in Toml.Syntax.Position Methods showsPrec :: Int -> Located a -> ShowS Source # show :: Located a -> String Source # showList :: [Located a] -> ShowS Source #

data Position Source #

A position in a text file

Constructors

Position |

Fields

- posIndex :: !Int

  code-point index (zero-based)

- posLine :: !Int

  line index (one-based)

- posColumn :: !Int

  column index (one-based)

#### Instances

Instances details

Read Position Source # | Default instance
Instance details Defined in Toml.Syntax.Position Methods readsPrec :: Int -> ReadS Position Source # readList :: ReadS [Position] Source # readPrec :: ReadPrec Position Source # readListPrec :: ReadPrec [Position] Source #
Show Position Source # | Default instance
Instance details Defined in Toml.Syntax.Position Methods showsPrec :: Int -> Position -> ShowS Source # show :: Position -> String Source # showList :: [Position] -> ShowS Source #
Eq Position Source # | Default instance
Instance details Defined in Toml.Syntax.Position Methods (==) :: Position -> Position -> Bool Source # (/=) :: Position -> Position -> Bool Source #
Ord Position Source # | Default instance
Instance details Defined in Toml.Syntax.Position Methods compare :: Position -> Position -> Ordering Source # (<) :: Position -> Position -> Bool Source # (<=) :: Position -> Position -> Bool Source # (>) :: Position -> Position -> Bool Source # (>=) :: Position -> Position -> Bool Source # max :: Position -> Position -> Position Source # min :: Position -> Position -> Position Source #

startPos :: Position Source #

The initial `Position` for the start of a file