toml_lexer Derived Type

type, public, extends(abstract_lexer) :: toml_lexer

Tokenizer for TOML documents.


Components

Type Visibility Attributes Name Initial
integer, public :: buffer = 0

Index in the buffer queue

character(kind=tfc, len=:), public, allocatable :: chunk

Current source chunk, for convenience stored as character array rather than string

type(toml_context), public :: context

Douple-ended queue for buffering tokens

character(len=:), public, allocatable :: filename

Name of the source file, used for error reporting

integer, public :: pos = 0

Current internal position in the source chunk

type(stack_item), public, allocatable :: stack(:)

Stack of scopes, used to identify the current state of the lexer

integer, public :: top = 0

Last scope of the lexer


Type-Bound Procedures

  • private subroutine extract_string(lexer, token, string)

    Extract string value of token, works for keypath, string, multiline string, literal, and mulitline literal tokens.

    Arguments

    Type IntentOptional Attributes Name
    class(toml_lexer), intent(in) :: lexer

    Instance of the lexer

    type(toml_token), intent(in) :: token

    Token to extract string value from

    character(len=:), intent(out), allocatable :: string

    String value of token

  • private subroutine extract_integer(lexer, token, val)

    Extract integer value of token

    Arguments

    Type IntentOptional Attributes Name
    class(toml_lexer), intent(in) :: lexer

    Instance of the lexer

    type(toml_token), intent(in) :: token

    Token to extract integer value from

    integer(kind=tfi), intent(out) :: val

    Integer value of token

  • private subroutine extract_float(lexer, token, val)

    Extract floating point value of token

    Arguments

    Type IntentOptional Attributes Name
    class(toml_lexer), intent(in) :: lexer

    Instance of the lexer

    type(toml_token), intent(in) :: token

    Token to extract floating point value from

    real(kind=tfr), intent(out) :: val

    Floating point value of token

  • private subroutine extract_bool(lexer, token, val)

    Extract boolean value of token

    Arguments

    Type IntentOptional Attributes Name
    class(toml_lexer), intent(in) :: lexer

    Instance of the lexer

    type(toml_token), intent(in) :: token

    Token to extract boolean value from

    logical, intent(out) :: val

    Boolean value of token

  • private subroutine extract_datetime(lexer, token, val)

    Extract datetime value of token

    Arguments

    Type IntentOptional Attributes Name
    class(toml_lexer), intent(in) :: lexer

    Instance of the lexer

    type(toml_token), intent(in) :: token

    Token to extract datetime value from

    type(toml_datetime), intent(out) :: val

    Datetime value of token

procedure, public :: extract_bool

Extract a boolean from a token

  • private subroutine extract_bool(lexer, token, val)

    Extract boolean value of token

    Arguments

    Type IntentOptional Attributes Name
    class(toml_lexer), intent(in) :: lexer

    Instance of the lexer

    type(toml_token), intent(in) :: token

    Token to extract boolean value from

    logical, intent(out) :: val

    Boolean value of token

procedure, public :: extract_datetime

Extract a timestamp from a token

  • private subroutine extract_datetime(lexer, token, val)

    Extract datetime value of token

    Arguments

    Type IntentOptional Attributes Name
    class(toml_lexer), intent(in) :: lexer

    Instance of the lexer

    type(toml_token), intent(in) :: token

    Token to extract datetime value from

    type(toml_datetime), intent(out) :: val

    Datetime value of token

procedure, public :: extract_float

Extract a float from a token

  • private subroutine extract_float(lexer, token, val)

    Extract floating point value of token

    Arguments

    Type IntentOptional Attributes Name
    class(toml_lexer), intent(in) :: lexer

    Instance of the lexer

    type(toml_token), intent(in) :: token

    Token to extract floating point value from

    real(kind=tfr), intent(out) :: val

    Floating point value of token

procedure, public :: extract_integer

Extract an integer from a token

  • private subroutine extract_integer(lexer, token, val)

    Extract integer value of token

    Arguments

    Type IntentOptional Attributes Name
    class(toml_lexer), intent(in) :: lexer

    Instance of the lexer

    type(toml_token), intent(in) :: token

    Token to extract integer value from

    integer(kind=tfi), intent(out) :: val

    Integer value of token

procedure, public :: extract_string

Extract a string from a token

  • private subroutine extract_string(lexer, token, string)

    Extract string value of token, works for keypath, string, multiline string, literal, and mulitline literal tokens.

    Arguments

    Type IntentOptional Attributes Name
    class(toml_lexer), intent(in) :: lexer

    Instance of the lexer

    type(toml_token), intent(in) :: token

    Token to extract string value from

    character(len=:), intent(out), allocatable :: string

    String value of token

procedure, public :: get_info

Get information about source

  • private subroutine get_info(lexer, meta, output)

    Extract information about the source

    Arguments

    Type IntentOptional Attributes Name
    class(toml_lexer), intent(in) :: lexer

    Instance of the lexer

    character(kind=tfc, len=*), intent(in) :: meta

    Query about the source

    character(kind=tfc, len=:), intent(out), allocatable :: output

    Metadata about the source

procedure, public :: next

Obtain the next token

  • private subroutine next(lexer, token)

    Advance the lexer to the next token.

    Arguments

    Type IntentOptional Attributes Name
    class(toml_lexer), intent(inout) :: lexer

    Instance of the lexer

    type(toml_token), intent(inout) :: token

    Current lexeme

Source Code

   type, extends(abstract_lexer) :: toml_lexer
      !> Name of the source file, used for error reporting
      character(len=:), allocatable :: filename
      !> Current internal position in the source chunk
      integer :: pos = 0
      !> Current source chunk, for convenience stored as character array rather than string
      character(:, tfc), allocatable :: chunk
      !> Last scope of the lexer
      integer :: top = 0
      !> Stack of scopes, used to identify the current state of the lexer
      type(stack_item), allocatable :: stack(:)
      !> Index in the buffer queue
      integer :: buffer = 0
      !> Douple-ended queue for buffering tokens
      type(toml_context) :: context
   contains
      !> Obtain the next token
      procedure :: next
      !> Extract a string from a token
      procedure :: extract_string
      !> Extract an integer from a token
      procedure :: extract_integer
      !> Extract a float from a token
      procedure :: extract_float
      !> Extract a boolean from a token
      procedure :: extract_bool
      !> Extract a timestamp from a token
      procedure :: extract_datetime
      !> Get information about source
      procedure :: get_info
   end type toml_lexer