JSON lexer/tokenizer implementation.
This module provides the json_lexer type which tokenizes JSON input into a stream of tokens for the parser. The lexer extends the abstract lexer interface from TOML Fortran, inserting a prelude of tokens to wrap JSON data in a pseudo-TOML structure for compatibility with the TOML parser.
true, false)null){, }, [, ], :, ,)The lexer is typically not used directly. Instead, use json_load or json_loads from the jonquil module.
type(json_lexer) :: lexer
call new_lexer_from_string(lexer, '{"key": 123}')
Tokenizer for JSON documents
| 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 |
| procedure, public :: extract_bool | Extract a boolean from a token |
| procedure, public :: extract_datetime | Extract a timestamp from a token |
| procedure, public :: extract_float | Extract a float from a token |
| procedure, public :: extract_integer | Extract an integer from a token |
| procedure, public :: extract_string | Extract a string from a token |
| procedure, public :: get_info | Get information about source |
| procedure, public :: next | Obtain the next token |
Create a new instance of a lexer by reading from a file
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(json_lexer), | intent(out) | :: | lexer |
Instance of the lexer |
||
| character(len=*), | intent(in) | :: | filename |
Name of the file to read from |
||
| type(toml_error), | intent(out), | allocatable | :: | error |
Error code |
Create a new instance of a lexer by reading from a string.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(json_lexer), | intent(out) | :: | lexer |
Instance of the lexer |
||
| character(len=*), | intent(in) | :: | string |
String to read from |
Create a new instance of a lexer by reading from a unit.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(json_lexer), | intent(out) | :: | lexer |
Instance of the lexer |
||
| integer, | intent(in) | :: | io |
Unit to read from |
||
| type(toml_error), | intent(out), | allocatable | :: | error |
Error code |