parse Subroutine

public subroutine parse(lexer, table, config, context, error)

Parse TOML document and return root table

Arguments

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

Instance of the lexer

type(toml_table), intent(out), allocatable :: table

TOML data structure

type(toml_parser_config), intent(in), optional :: config

Configuration for the parser

type(toml_context), intent(out), optional :: context

Context tracking the origin of the data structure to allow rich reports

type(toml_error), intent(out), optional, allocatable :: error

Error handler


Source Code

subroutine parse(lexer, table, config, context, error)
   !> Instance of the lexer
   class(toml_lexer), intent(inout) :: lexer
   !> TOML data structure
   type(toml_table), allocatable, intent(out) :: table
   !> Configuration for the parser
   type(toml_parser_config), intent(in), optional :: config
   !> Context tracking the origin of the data structure to allow rich reports
   type(toml_context), intent(out), optional :: context
   !> Error handler
   type(toml_error), allocatable, intent(out), optional :: error

   type(toml_parser) :: parser

   call new_parser(parser, config)
   call parse_root(parser, lexer)

   if (present(error) .and. allocated(parser%diagnostic)) then
      call make_error(error, parser%diagnostic, lexer, parser%config%color)
   end if
   if (allocated(parser%diagnostic)) return

   call move_alloc(parser%root, table)

   if (present(context)) then
      context = parser%context
      call lexer%get_info("filename", context%filename)
      call lexer%get_info("source", context%source)
   end if
end subroutine parse