ASCII parsers¶
The basic template for all parsers is pni::parser
-
template<typename
T
>
classpni
::
parser
¶ parser for primitive types
This version of the parser structure provides a default parsing implementation for primitive types. The aim of this class is to hide all the complexity of the boost::spirit::qi parsers. In addition it catches all spirit exceptions and wraps them into a parser_error exception.
Use this parser to parse a single primitive value from a string. The input data must be trimmed - so no leading or trailing blanks are allowed. The string is supposed to end with the last character assembling the value to parse.
By default the output iterator is a const string iterator.
- Template Parameters
T
: primitive data type
Public Functions
-
result_type
operator()
(const pni::string &data) const¶ parser primitive type
Parses the input string and returns an instance of a primitive type. In case of errors parser_error is thrown.
- Return
instance of the primitive type
- Exceptions
parser_error
: in case of any problems
- Parameters
data
: the string with input data
Parser specializations¶
-
template<>
classparser
<pni::value>¶ parser for general values
This is a specialization of the parser class for the value type erasure. The parser tries to identify the value provided by the data string and converts it to the appropriate type which will then be wrapped in an instance of pni::value.
The class currently supports the following types
64Bit integer
64Bit floating point
64Bit complex floats
and strings
-
template<>
classpni
::
parser
<pni::bool_t>¶ parser specialization for bool values
This specialization of the parser template reads boolean values from a string. The parser uses regular expressions to distinguish between strings representing true and false.
When instantiated using the default constructor
TRUE
,true
andTrue
are interpreted as trueand
FALSE
,false
andFalse
as false.
Public Functions
-
parser
()¶ default constructor
With the default constructor the following regular expressions are used to distinguish between true and false
for true -
^T(rue|RUE)|true|1$
for false -
^F(alse|ALSE)|false|0$
-
parser
(const pni::string &true_regex, const pni::string &false_regex)¶ constructor
With this constructor the regular expressions used for true and false values can be customized.
- Parameters
true_regex
: regular expression evaluating to truefalse_regex
: regular expression evaluating to false
-
template<>
classparser
<pni::string>¶ parsing strings
This specialization of the parser template parses strings form user input. Virtually this class does nothing it just passes the string provided by the user right through.
-
template<typename
T
>
classpni
::
parser
<std::vector<T>>¶ std::vector parser
This parser reads a linear container of data from a string. The data type of the container is assumed to be homogeneous. This means that all elements must match with the parser selected for the element type.
In their string representation container data is assumed to be embraced between a start and a stop token. The elements are assumed to be separated by a delimiter token.
The container can be any STL compliant container type.
- Template Parameters
T
: the value type of the vector
Public Functions
-
parser
(const container_io_config &config = container_io_config())¶ constructor
With this constructor a container IO configuration can be passed which determines the value seperator, start and stop symbols.
- Parameters
config
: reference to the IO configuration