json_lexer Derived Type

type, public, extends(abstract_lexer) :: json_lexer

Tokenizer for JSON documents


Components

Type Visibility Attributes Name Initial
character(kind=tfc, len=:), public, allocatable :: chunk

Current source chunk

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

integer, public :: prelude = 2

Additional tokens to insert before the actual token stream


Type-Bound Procedures

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(json_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(json_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(json_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(json_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

    Arguments

    Type IntentOptional Attributes Name
    class(json_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(json_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 to the next token in the lexer

    Arguments

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

    Instance of the lexer

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

    Current token

Source Code

   type, extends(abstract_lexer) :: json_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
      character(:, tfc), allocatable :: chunk
      !> Additional tokens to insert before the actual token stream
      integer :: prelude = 2
   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 json_lexer