Toml.Syntax

toml-parser-2.0.1.0: TOML 1.0.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] #

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) #

Non-empty sequence of dotted simple keys

data Expr a #

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

data Val a #

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

# Lexing

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

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

data Context #

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 # |
Instance details Defined in Toml.Syntax.LexerUtils Methods showsPrec :: Int -> Context -> ShowS # show :: Context -> String # showList :: [Context] -> ShowS #

data Token #

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

# Locations

data Located a #

A value annotated with its text file position

Constructors

Located |
Fields locPosition :: !Position position locThing :: !a thing at position

#### Instances

Instances details

Functor Located # | Default instance
Instance details Defined in Toml.Syntax.Position Methods fmap :: (a -> b) -> Located a -> Located b # (<$) :: a -> Located b -> Located a #
Foldable Located # | Default instance
Instance details Defined in Toml.Syntax.Position Methods fold :: Monoid m => Located m -> m # foldMap :: Monoid m => (a -> m) -> Located a -> m # foldMap' :: Monoid m => (a -> m) -> Located a -> m # foldr :: (a -> b -> b) -> b -> Located a -> b # foldr' :: (a -> b -> b) -> b -> Located a -> b # foldl :: (b -> a -> b) -> b -> Located a -> b # foldl' :: (b -> a -> b) -> b -> Located a -> b # foldr1 :: (a -> a -> a) -> Located a -> a # foldl1 :: (a -> a -> a) -> Located a -> a # toList :: Located a -> [a] # null :: Located a -> Bool # length :: Located a -> Int # elem :: Eq a => a -> Located a -> Bool # maximum :: Ord a => Located a -> a # minimum :: Ord a => Located a -> a # sum :: Num a => Located a -> a # product :: Num a => Located a -> a #
Traversable Located # | Default instance
Instance details Defined in Toml.Syntax.Position Methods traverse :: Applicative f => (a -> f b) -> Located a -> f (Located b) # sequenceA :: Applicative f => Located (f a) -> f (Located a) # mapM :: Monad m => (a -> m b) -> Located a -> m (Located b) # sequence :: Monad m => Located (m a) -> m (Located a) #
Read a => Read (Located a) # | Default instance
Instance details Defined in Toml.Syntax.Position Methods readsPrec :: Int -> ReadS (Located a) # readList :: ReadS [Located a] # readPrec :: ReadPrec (Located a) # readListPrec :: ReadPrec [Located a] #
Show a => Show (Located a) # | Default instance
Instance details Defined in Toml.Syntax.Position Methods showsPrec :: Int -> Located a -> ShowS # show :: Located a -> String # showList :: [Located a] -> ShowS #

data Position #

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

startPos :: Position #

The initial `Position` for the start of a file