Flow123d  3.9.0-127d9ed9b
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer Class Reference

lexical analysis More...

Public Types

enum  token_type {
  token_type::uninitialized, token_type::literal_true, token_type::literal_false, token_type::literal_null,
  token_type::value_string, token_type::value_number, token_type::begin_array, token_type::begin_object,
  token_type::end_array, token_type::end_object, token_type::name_separator, token_type::value_separator,
  token_type::parse_error, token_type::end_of_input
}
 token types for the parser More...
 
using lexer_char_t = unsigned char
 the char type to use in the lexer More...
 

Public Member Functions

 lexer (const string_t &s) noexcept
 constructor with a given buffer More...
 
 lexer (std::istream *s) noexcept
 constructor with a given stream More...
 
 lexer ()=default
 default constructor More...
 
 lexer (const lexer &)=delete
 
lexer operator= (const lexer &)=delete
 
token_type scan () noexcept
 
void yyfill () noexcept
 append data from the stream to the internal buffer More...
 
string_t get_token () const
 return string representation of last read token More...
 
string_t get_string () const
 return string value for string tokens More...
 
long double str_to_float_t (long double *, char **endptr) const
 parse floating point number More...
 
double str_to_float_t (double *, char **endptr) const
 parse floating point number More...
 
float str_to_float_t (float *, char **endptr) const
 parse floating point number More...
 
void get_number (basic_json &result) const
 return number value for number tokens More...
 

Static Public Member Functions

static string_t to_unicode (const std::size_t codepoint1, const std::size_t codepoint2=0)
 create a string from a Unicode code point More...
 
static std::string token_type_name (token_type t)
 return name of values of type token_type (only used for errors) More...
 
template<typename T_A , typename T_B >
static bool attempt_cast (T_A source, T_B &dest)
 static_cast between two types and indicate if it results in error More...
 

Private Attributes

std::istream * m_stream = nullptr
 optional input stream More...
 
string_t m_buffer
 the buffer More...
 
const lexer_char_tm_content = nullptr
 the buffer pointer More...
 
const lexer_char_tm_start = nullptr
 pointer to the beginning of the current symbol More...
 
const lexer_char_tm_marker = nullptr
 pointer for backtracking information More...
 
const lexer_char_tm_cursor = nullptr
 pointer to the current symbol More...
 
const lexer_char_tm_limit = nullptr
 pointer to the end of the buffer More...
 

Detailed Description

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
class nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer

lexical analysis

This class organizes the lexical analysis during JSON deserialization. The core of it is a scanner generated by re2c that processes a buffer and recognizes tokens according to RFC 7159.

Definition at line 7079 of file json.hpp.

Member Typedef Documentation

◆ lexer_char_t

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::lexer_char_t = unsigned char

the char type to use in the lexer

Definition at line 7102 of file json.hpp.

Member Enumeration Documentation

◆ token_type

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
enum nlohmann::basic_json::lexer::token_type
strong

token types for the parser

Enumerator
uninitialized 

indicating the scanner is uninitialized

literal_true 

the "true" literal

literal_false 

the "false" literal

literal_null 

the "null" literal

value_string 

a string – use get_string() for actual value

value_number 

a number – use get_number() for actual value

begin_array 

the character for array begin "["

begin_object 

the character for object begin "{"

end_array 

the character for array end "]"

end_object 

the character for object end "}"

name_separator 

the name separator ":"

value_separator 

the value separator ","

parse_error 

indicating a parse error

end_of_input 

indicating the end of the input buffer

Definition at line 7083 of file json.hpp.

Constructor & Destructor Documentation

◆ lexer() [1/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::lexer ( const string_t s)
inlineexplicitnoexcept

constructor with a given buffer

Definition at line 7105 of file json.hpp.

◆ lexer() [2/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::lexer ( std::istream *  s)
inlineexplicitnoexcept

constructor with a given stream

Definition at line 7115 of file json.hpp.

◆ lexer() [3/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::lexer ( )
default

default constructor

◆ lexer() [4/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::lexer ( const lexer )
delete

Member Function Documentation

◆ attempt_cast()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<typename T_A , typename T_B >
static bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::attempt_cast ( T_A  source,
T_B &  dest 
)
inlinestatic

static_cast between two types and indicate if it results in error

This function performs a static_cast between source and dest. It then checks if a static_cast back to dest produces an error.

Parameters
[in]sourcethe value to cast from
[in,out]destthe value to cast to
Returns
true iff the cast was performed without error

Definition at line 8263 of file json.hpp.

Here is the caller graph for this function:

◆ get_number()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::get_number ( basic_json result) const
inline

return number value for number tokens

This function translates the last token into the most appropriate number type (either integer, unsigned integer or floating point), which is passed back to the caller via the result parameter. The pointer m_start points to the beginning of the parsed number. We first examine the first character to determine the sign of the number and then pass this pointer to either std::strtoull (if positive) or std::strtoll (if negative), both of which set endptr to the first character past the converted number. If this pointer is not the same as m_cursor, then either more or less characters have been used during the comparison.

This can happen for inputs like "01" which will be treated like number 0 followed by number 1. This will also occur for valid floating point inputs like "12e3" will be incorrectly read as 12. Numbers that are too large or too small for a signed/unsigned long long will cause a range error (errno set to ERANGE). The parsed number is cast to a number_integer_t/number_unsigned_t using the helper function attempt_cast, which returns false if the cast could not be peformed without error.

In any of these cases (more/less characters read, range error or a cast error) the pointer is passed to std:strtod, which also sets endptr to the first character past the converted number. The resulting number_float_t is then cast to a number_integer_t/number_unsigned_t using attempt_cast and if no error occurs is stored in that form, otherwise it is stored as a number_float_t.

A final comparison is made of endptr and if still not the same as m_cursor a bad input is assumed and result parameter is set to NAN.

Parameters
[out]resultbasic_json object to receive the number, or NAN if the conversion read past the current token. The latter case needs to be treated by the caller function.

Definition at line 8307 of file json.hpp.

Here is the caller graph for this function:

◆ get_string()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
string_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::get_string ( ) const
inline

return string value for string tokens

The function iterates the characters between the opening and closing quotes of the string value. The complete string is the range [m_start,m_cursor). Consequently, we iterate from m_start+1 to m_cursor-1.

We differentiate two cases:

  1. Escaped characters. In this case, a new character is constructed according to the nature of the escape. Some escapes create new characters (e.g., "\\n" is replaced by "\n"), some are copied as is (e.g., "\\\\"). Furthermore, Unicode escapes of the shape "\\uxxxx" need special care. In this case, to_unicode takes care of the construction of the values.
  2. Unescaped characters are copied as is.
Returns
string value of current token without opening and closing quotes
Exceptions
std::out_of_rangeif to_unicode fails

Definition at line 8082 of file json.hpp.

Here is the caller graph for this function:

◆ get_token()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
string_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::get_token ( ) const
inline

return string representation of last read token

Definition at line 8054 of file json.hpp.

Here is the caller graph for this function:

◆ operator=()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
lexer nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::operator= ( const lexer )
delete

◆ scan()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
token_type nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::scan ( )
inlinenoexcept

This function implements a scanner for JSON. It is specified using regular expressions that try to follow RFC 7159 as close as possible. These regular expressions are then translated into a minimized deterministic finite automaton (DFA) by the tool re2c. As a result, the translated code for this function consists of a large block of code with goto jumps.

Returns
the class of the next token read from the buffer

Definition at line 7263 of file json.hpp.

Here is the caller graph for this function:

◆ str_to_float_t() [1/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
double nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::str_to_float_t ( double *  ,
char **  endptr 
) const
inline

parse floating point number

This function (and its overloads) serves to select the most approprate standard floating point number parsing function based on the type supplied via the first parameter. Set this to static_cast<number_float_t*>(nullptr).

Parameters
[in]typethe number_float_t in use
[in,out]endptrrecieves a pointer to the first character after the number
Returns
the floating point number

Definition at line 8225 of file json.hpp.

◆ str_to_float_t() [2/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
float nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::str_to_float_t ( float *  ,
char **  endptr 
) const
inline

parse floating point number

This function (and its overloads) serves to select the most approprate standard floating point number parsing function based on the type supplied via the first parameter. Set this to static_cast<number_float_t*>(nullptr).

Parameters
[in]typethe number_float_t in use
[in,out]endptrrecieves a pointer to the first character after the number
Returns
the floating point number

Definition at line 8245 of file json.hpp.

◆ str_to_float_t() [3/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
long double nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::str_to_float_t ( long double *  ,
char **  endptr 
) const
inline

parse floating point number

This function (and its overloads) serves to select the most approprate standard floating point number parsing function based on the type supplied via the first parameter. Set this to static_cast<number_float_t*>(nullptr).

Parameters
[in]typethe number_float_t in use
[in,out]endptrrecieves a pointer to the first character after the number
Returns
the floating point number
Bug:
This function uses std::strtof, std::strtod, or std::strtold which use the current C locale to determine which character is used as decimal point character. This may yield to parse errors if the locale does not used ..

Definition at line 8205 of file json.hpp.

Here is the caller graph for this function:

◆ to_unicode()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
static string_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::to_unicode ( const std::size_t  codepoint1,
const std::size_t  codepoint2 = 0 
)
inlinestatic

create a string from a Unicode code point

Parameters
[in]codepoint1the code point (can be high surrogate)
[in]codepoint2the code point (can be low surrogate or 0)
Returns
string representation of the code point
Exceptions
std::out_of_rangeif code point is >0x10ffff; example: "code points above 0x10FFFF are invalid"
std::invalid_argumentif the low surrogate is invalid; example: ""missing or wrong low surrogate""
See also
http://en.wikipedia.org/wiki/UTF-8#Sample_code

Definition at line 7148 of file json.hpp.

Here is the caller graph for this function:

◆ token_type_name()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
static std::string nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::token_type_name ( token_type  t)
inlinestatic

return name of values of type token_type (only used for errors)

Definition at line 7213 of file json.hpp.

Here is the caller graph for this function:

◆ yyfill()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::yyfill ( )
inlinenoexcept

append data from the stream to the internal buffer

Definition at line 8028 of file json.hpp.

Here is the caller graph for this function:

Member Data Documentation

◆ m_buffer

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
string_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::m_buffer
private

the buffer

Definition at line 8374 of file json.hpp.

◆ m_content

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
const lexer_char_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::m_content = nullptr
private

the buffer pointer

Definition at line 8376 of file json.hpp.

◆ m_cursor

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
const lexer_char_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::m_cursor = nullptr
private

pointer to the current symbol

Definition at line 8382 of file json.hpp.

◆ m_limit

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
const lexer_char_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::m_limit = nullptr
private

pointer to the end of the buffer

Definition at line 8384 of file json.hpp.

◆ m_marker

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
const lexer_char_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::m_marker = nullptr
private

pointer for backtracking information

Definition at line 8380 of file json.hpp.

◆ m_start

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
const lexer_char_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::m_start = nullptr
private

pointer to the beginning of the current symbol

Definition at line 8378 of file json.hpp.

◆ m_stream

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
std::istream* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::lexer::m_stream = nullptr
private

optional input stream

Definition at line 8372 of file json.hpp.


The documentation for this class was generated from the following file: