![]() |
Eclipse SUMO - Simulation of Urban MObility
|
lexical analysis More...
#include <json.hpp>
Public Types | |
| using | token_type = typename lexer_base<BasicJsonType>::token_type |
Public Member Functions | |
| JSON_HEDLEY_RETURNS_NON_NULL constexpr const char * | get_error_message () const noexcept |
| return syntax error message | |
| constexpr number_float_t | get_number_float () const noexcept |
| return floating-point value | |
| constexpr number_integer_t | get_number_integer () const noexcept |
| return integer value | |
| constexpr number_unsigned_t | get_number_unsigned () const noexcept |
| return unsigned integer value | |
| constexpr position_t | get_position () const noexcept |
| return position of last read token | |
| string_t & | get_string () |
| return current string value (implicitly resets the token; useful only once) | |
| std::string | get_token_string () const |
| lexer (const lexer &)=delete | |
| lexer (InputAdapterType &&adapter, bool ignore_comments_=false) noexcept | |
| lexer (lexer &&)=default | |
| lexer & | operator= (lexer &&)=default |
| lexer & | operator= (lexer &)=delete |
| token_type | scan () |
| bool | skip_bom () |
| skip the UTF-8 byte order mark | |
| void | skip_whitespace () |
| ~lexer ()=default | |
Static Public Member Functions | |
| JSON_HEDLEY_RETURNS_NON_NULL static JSON_HEDLEY_CONST const char * | token_type_name (const token_type t) noexcept |
| return name of values of type token_type (only used for errors) | |
Private Types | |
| using | char_int_type = typename std::char_traits<char_type>::int_type |
| using | char_type = typename InputAdapterType::char_type |
| using | number_float_t = typename BasicJsonType::number_float_t |
| using | number_integer_t = typename BasicJsonType::number_integer_t |
| using | number_unsigned_t = typename BasicJsonType::number_unsigned_t |
| using | string_t = typename BasicJsonType::string_t |
Private Member Functions | |
| void | add (char_int_type c) |
| add a character to token_buffer | |
| char_int_type | get () |
| int | get_codepoint () |
| get codepoint from 4 hex characters following \u | |
| bool | next_byte_in_range (std::initializer_list< char_int_type > ranges) |
| check if the next byte(s) are inside a given range | |
| void | reset () noexcept |
| reset token_buffer; current character is beginning of token | |
| bool | scan_comment () |
| scan a comment | |
| token_type | scan_literal (const char_type *literal_text, const std::size_t length, token_type return_type) |
| token_type | scan_number () |
| scan a number literal | |
| token_type | scan_string () |
| scan a string literal | |
| void | unget () |
| unget current character (read it again on next get) | |
Static Private Member Functions | |
| static JSON_HEDLEY_PURE char | get_decimal_point () noexcept |
| return the locale-dependent decimal point | |
| static void | strtof (double &f, const char *str, char **endptr) noexcept |
| static void | strtof (float &f, const char *str, char **endptr) noexcept |
| static void | strtof (long double &f, const char *str, char **endptr) noexcept |
Private Attributes | |
| char_int_type | current = std::char_traits<char_type>::eof() |
| the current character | |
| const char_int_type | decimal_point_char = '.' |
| the decimal point | |
| const char * | error_message = "" |
| a description of occurred lexer errors | |
| InputAdapterType | ia |
| input adapter | |
| const bool | ignore_comments = false |
| whether comments should be ignored (true) or signaled as errors (false) | |
| bool | next_unget = false |
| whether the next get() call should just return current | |
| position_t | position {} |
| the start position of the current token | |
| string_t | token_buffer {} |
| buffer for variable-length tokens (numbers, strings) | |
| std::vector< char_type > | token_string {} |
| raw input token string (for error messages) | |
| number_float_t | value_float = 0 |
| number_integer_t | value_integer = 0 |
| number_unsigned_t | value_unsigned = 0 |
lexical analysis
This class organizes the lexical analysis during JSON deserialization.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
| using nlohmann::detail::lexer< BasicJsonType, InputAdapterType >::token_type = typename lexer_base<BasicJsonType>::token_type |
|
inlineexplicitnoexcept |
Definition at line 6525 of file json.hpp.
References decimal_point_char, get_decimal_point(), ia, and ignore_comments.
Referenced by lexer(), lexer(), operator=(), and operator=().
|
delete |
References lexer().
|
default |
References lexer().
|
default |
References JSON_HEDLEY_PURE.
|
inlineprivate |
add a character to token_buffer
Definition at line 7803 of file json.hpp.
References token_buffer.
Referenced by next_byte_in_range(), scan_number(), and scan_string().
|
inlineprivate |
Definition at line 7739 of file json.hpp.
References current, ia, JSON_HEDLEY_LIKELY, next_unget, position, and token_string.
Referenced by get_codepoint(), next_byte_in_range(), scan_comment(), scan_literal(), scan_number(), scan_string(), skip_bom(), and skip_whitespace().
|
inlineprivate |
get codepoint from 4 hex characters following \u
For input "\u c1 c2 c3 c4" the codepoint is: (c1 * 0x1000) + (c2 * 0x0100) + (c3 * 0x0010) + c4 = (c1 << 12) + (c2 << 8) + (c3 << 4) + (c4 << 0)
Furthermore, the possible characters '0'..'9', 'A'..'F', and 'a'..'f' must be converted to the integers 0x0..0x9, 0xA..0xF, 0xA..0xF, resp. The conversion is done by subtracting the offset (0x30, 0x37, and 0x57) between the ASCII value of the character and the desired integer value.
Definition at line 6571 of file json.hpp.
References current, get(), and JSON_ASSERT.
Referenced by scan_string().
|
inlinestaticprivatenoexcept |
return the locale-dependent decimal point
Definition at line 6545 of file json.hpp.
References JSON_ASSERT.
Referenced by lexer().
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inline |
return current string value (implicitly resets the token; useful only once)
Definition at line 7832 of file json.hpp.
References token_buffer.
|
inline |
return the last read token (for errors only). Will never contain EOF (an arbitrary value that is not a valid char value, often -1), because 255 may legitimately occur. May contain NUL, which should be escaped.
Definition at line 7850 of file json.hpp.
References nlohmann::result, and token_string.
|
inlineprivate |
check if the next byte(s) are inside a given range
Adds the current byte and, for each passed range, reads a new byte and checks if it is inside the range. If a violation was detected, set up an error message and return false. Otherwise, return true.
| [in] | ranges | list of integers; interpreted as list of pairs of inclusive lower and upper bound, respectively |
Definition at line 6619 of file json.hpp.
References add(), current, error_message, get(), JSON_ASSERT, and JSON_HEDLEY_LIKELY.
Referenced by scan_string().
|
default |
References lexer().
|
delete |
References lexer().
|
inlineprivatenoexcept |
reset token_buffer; current character is beginning of token
Definition at line 7722 of file json.hpp.
References current, token_buffer, and token_string.
Referenced by scan_number(), and scan_string().
|
inline |
Definition at line 7911 of file json.hpp.
References current, error_message, ignore_comments, position, scan_comment(), scan_literal(), scan_number(), scan_string(), skip_bom(), and skip_whitespace().
|
inlineprivate |
|
inlineprivate |
| [in] | literal_text | the literal text to expect |
| [in] | length | the length of the passed literal text |
| [in] | return_type | the token type to return on success |
Definition at line 7702 of file json.hpp.
References current, error_message, get(), JSON_ASSERT, JSON_HEDLEY_UNLIKELY, and scan_literal().
Referenced by scan(), and scan_literal().
|
inlineprivate |
scan a number literal
This function scans a string according to Sect. 6 of RFC 8259.
The function is realized with a deterministic finite state machine derived from the grammar described in RFC 8259. Starting in state "init", the input is read and used to determined the next state. Only state "done" accepts the number. State "error" is a trap state to model errors. In the table below, "anything" means any character but the ones listed before.
| state | 0 | 1-9 | e E | + | - | . | anything |
|---|---|---|---|---|---|---|---|
| init | zero | any1 | [error] | [error] | minus | [error] | [error] |
| minus | zero | any1 | [error] | [error] | [error] | [error] | [error] |
| zero | done | done | exponent | done | done | decimal1 | done |
| any1 | any1 | any1 | exponent | done | done | decimal1 | done |
| decimal1 | decimal2 | decimal2 | [error] | [error] | [error] | [error] | [error] |
| decimal2 | decimal2 | decimal2 | exponent | done | done | done | done |
| exponent | any2 | any2 | [error] | sign | sign | [error] | [error] |
| sign | any2 | any2 | [error] | [error] | [error] | [error] | [error] |
| any2 | any2 | any2 | done | done | done | done | done |
The state machine is realized with one label per state (prefixed with "scan_number_") and goto statements between them. The state machine contains cycles, but any cycle can be left when EOF is read. Therefore, the function is guaranteed to terminate.
During scanning, the read bytes are stored in token_buffer. This string is then converted to a signed integer, an unsigned integer, or a floating-point number.
Definition at line 7371 of file json.hpp.
References add(), current, decimal_point_char, error_message, get(), JSON_ASSERT, reset(), strtof(), token_buffer, unget(), value_float, value_integer, and value_unsigned.
Referenced by scan().
|
inlineprivate |
scan a string literal
This function scans a string according to Sect. 7 of RFC 8259. While scanning, bytes are escaped and copied into buffer token_buffer. Then the function returns successfully, token_buffer is not null-terminated (as it may contain \0 bytes), and token_buffer.size() is the number of bytes in the string.
Definition at line 6656 of file json.hpp.
References add(), current, error_message, get(), get_codepoint(), JSON_ASSERT, JSON_HEDLEY_LIKELY, JSON_HEDLEY_UNLIKELY, next_byte_in_range(), and reset().
Referenced by scan().
|
inline |
|
inline |
|
inlinestaticprivatenoexcept |
|
inlinestaticprivatenoexcept |
|
inlinestaticprivatenoexcept |
|
inlinestaticnoexceptinherited |
return name of values of type token_type (only used for errors)
Definition at line 6464 of file json.hpp.
References begin_array, begin_object, end_array, end_object, end_of_input, literal_false, literal_null, literal_or_value, literal_true, name_separator, parse_error, uninitialized, value_float, value_integer, value_separator, value_string, and value_unsigned.
Referenced by nlohmann::detail::parser< BasicJsonType, InputAdapterType >::exception_message().
|
inlineprivate |
unget current character (read it again on next get)
We implement unget by setting variable next_unget to true. The input is not changed - we just simulate ungetting by modifying chars_read_total, chars_read_current_line, and token_string. The next call to get() will behave as if the unget character is read again.
Definition at line 7776 of file json.hpp.
References current, JSON_ASSERT, JSON_HEDLEY_LIKELY, next_unget, position, and token_string.
Referenced by scan_comment(), scan_number(), and skip_bom().
|
private |
the current character
Definition at line 8007 of file json.hpp.
Referenced by get(), get_codepoint(), next_byte_in_range(), reset(), scan(), scan_literal(), scan_number(), scan_string(), skip_whitespace(), and unget().
|
private |
the decimal point
Definition at line 8030 of file json.hpp.
Referenced by lexer(), and scan_number().
|
private |
a description of occurred lexer errors
Definition at line 8022 of file json.hpp.
Referenced by get_error_message(), next_byte_in_range(), scan(), scan_comment(), scan_literal(), scan_number(), and scan_string().
|
private |
|
private |
|
private |
|
private |
|
private |
buffer for variable-length tokens (numbers, strings)
Definition at line 8019 of file json.hpp.
Referenced by add(), get_string(), reset(), and scan_number().
|
private |
|
private |
Definition at line 8027 of file json.hpp.
Referenced by get_number_float(), and scan_number().
|
private |
Definition at line 8025 of file json.hpp.
Referenced by get_number_integer(), and scan_number().
|
private |
Definition at line 8026 of file json.hpp.
Referenced by get_number_unsigned(), and scan_number().