|
Parsnip
parsing library
|
Serialization and parsing library. More...
Data Structures | |
| class | ArgumentVector |
| This class lexically analyzes a string, splitting it up into tokens, which are accessed as a vector. More... | |
| class | ArgvCursor |
| An iterator for argument vectors. More... | |
| class | ConjunctionSchema |
| A meta-schema that determines if any, all, or exactly one or none of its subschemas are valid. More... | |
| class | Data |
| Generic data type. More... | |
| class | DataFormatError |
| DataFormatError represents a syntax error in a datastream. More... | |
| class | DataRangeError |
| DataRangeError indicates a value received in a stream can't be represented. More... | |
| class | DictionarySchema |
| Schema component for validating dictionaries. More... | |
| class | Dispatcher |
| class | DuplicateOption |
| An option was supplied twice to an iterating option parser. More... | |
| class | EndOfOptionEvaluator |
| An evaluator representing abrupt end of the command pattern. More... | |
| class | Evaluator |
| Evaluator base class. More... | |
| struct | EvaluatorDeleter |
| This does what std::default_delete would do, but is required since we haven't defined Evaluator yet. More... | |
| class | Exception |
| Class representing issues related to serialization & parsing. More... | |
| class | IncompleteCommand |
| More tokens were expected. More... | |
| class | IncorrectDataType |
| The data's type is inconsistent with the use requested of it. More... | |
| class | IncorrectListSize |
| The list size does not meet schema requirements. More... | |
| class | IntegerEvaluator |
| Evaluate and validate an integral value field. More... | |
| class | IntegerSchema |
| class | Interpreter |
| class | InvalidKey |
| They key is not specified in the schema. More... | |
| class | InvalidSchema |
| Parsing/command patterns produce schema inconsistency. More... | |
| class | InvalidValue |
| A token encountered was not one of the expected keywords. More... | |
| class | KeywordEvaluator |
| Evaluate a keyword in a command line. More... | |
| class | KeywordSchema |
| Schema component accepting strings with certain values. More... | |
| class | ListSchema |
| Schema component for lists. More... | |
| class | NoSchemaDefined |
| A schema is not defined for a certain command ID. More... | |
| class | NoSuchKey |
| An element requested from a constant dictionary does not exist. More... | |
| class | NotNumeric |
| Not numeric: A command pattern specified a number, but the token was not valid number. More... | |
| class | NumberOutOfRange |
| NumberOutOfRange: The number was outside the range defined in the command pattern. More... | |
| class | OptionEvaluator |
| Evaluate remainder with a different parser. More... | |
| class | OptionParser |
| A class for parsing command line options (name-value pairs, for instance). More... | |
| class | OptionSchema |
| Schema adapter component that allows use of schemas from option parsers. More... | |
| class | Parser |
| A class for parsing command lines. More... | |
| class | RangeSchema |
| Schema component for numeric data, either Integer or Real. More... | |
| class | RawRemainderEvaluator |
| Gather the rest of the command line as an untokenized string. More... | |
| class | RealEvaluator |
| Evaluate and validate a numeric value field. More... | |
| class | RegExEvaluator |
| Evaluate a string value field. More... | |
| class | RegExSchema |
| Schema component requiring data be a string of characters matching a regular expression. More... | |
| class | RemainderEvaluator |
| An evaluator that represents the rest of the command line. More... | |
| class | RemainingValuesEvaluator |
| Gather the rest of the command line tokens in a list. More... | |
| class | RunOnCommand |
| There were extra tokens at the end of the command pattern. More... | |
| class | Schema |
| Schema for one JSON object. More... | |
| class | SchemaBase |
| struct | SchemaBaseDeleter |
| Helper functor for schema smart pointers. More... | |
| class | SchemaBaseRef |
| Smart pointer for schemas, with unusual ability to be copied. More... | |
| class | SchemaConflict |
| Parsing/command patterns produce schema inconsistency. More... | |
| class | SchemaSet |
| A schema built to validate JSON messages based on command line patterns. More... | |
| class | StringEvaluator |
| Evaluate a string value field. More... | |
| class | StringSchema |
| Schema component requiring data be a string of characters (no control characters). More... | |
| class | TerminatorEvaluator |
| An evaluator representing abrupt end of the command pattern. More... | |
| class | TypeSchema |
| Schema component requiring data be a particular type. More... | |
| class | UncheckedSchema |
| Schema component requiring data be a particular type. More... | |
| class | ValueEvaluator |
| Evaluate a value/fill-in field. More... | |
Typedefs | |
| using | InputStream = std::istream |
| using | SchemaRef = std::shared_ptr< class Schema > |
| using | EvaluatorRef = std::unique_ptr< class Evaluator, EvaluatorDeleter > |
| using | OptionParserRef = std::shared_ptr< OptionParser > |
| using | ParserRef = std::shared_ptr< Parser > |
| using | SchemaSetRef = std::shared_ptr< SchemaSet > |
| using | SchemaIntegratorCallback = std::function< void(const int, const class DictionarySchema &)> |
| using | NumberSchema = RangeSchema< double > |
Functions | |
| Data | parse_json (std::istream &from, bool check_termination) |
| Parse a stream as JSON data. | |
| Data | parse_json (const std::string &from) |
| Parse a string as a JSON stream. | |
| std::ostream & | operator<< (std::ostream &out, const Parsnip::Data &data) |
| void | parser_assert (bool requirement, const char *explanation) |
| void | parser_assert (bool requirement, const char *explanation, const std::string &detail) |
| std::istream::int_type | next_non_whitespace (InputStream &from) |
| Read from a stream until a non-whitespace character is found. | |
Variables | |
| const std::string | EmptyString |
| const char | hex_digits [] = "0123456789abcdef" |
| Digits used for encoding/decoding hexadecimal. | |
Serialization and parsing library.
Classes providing evaluation for command lines.
The Parser class accepts arrays of strings/command ID combinations (Parser::Definition). From these, it builds a parse tree against which it can subsequently evaluate commands, identifying commands by ID and providing a dictionary the commands parameters. Multiple definition sets can be added to a single parser.
Lexically, commands are split at spaces, unless quoted. Single or double quotes may be used, but must match. Open quotes are only identified at the start of a word, close quotes only at the end of a word. Quotes may be doubled within a quoted span to insert a literal quote.
Statement patterns can be composed of:
Literal:
keyword – a bare word for matching command pattern. Alternation:<name:one|two> – accepts any 1 of the required words in that position Optional:[name:optional] – accepts an optional word in the current position[name:four|five] – accepts 0 or 1 optional words in the current position[word] – accepts an optional word, named itself, in the current position Fillable fields:{name} – accepts any string/number/value in that position{#name:3-5} – Accepts numeric range in that position. See range note below.{name...} – accepts the remainder of the command line, raw/unparsed as a single string. Optional remainder fillable fields (only at end of command):[{name}] – accepts a single optional value; may be string or numeric fillable.[{name}] ... – accepts 0 or more optional values; may be string or numeric fillable.[{name...}] – accepts the raw/unparsed remainder, if present. Always string.Names:
Alternation and optional patterns may contain an arbitrary number of possible keywords, Storage behavior:
Ranges:
Examples:
A completely different approach to the above would be:
Since the parse tree is assumed to be hard-coded in your application, this module simply throws a runtime_error it finds problems in the parse definitions.
Options parsing
An option parser may be used inline or as a remainder handler:
The option parser must be predefined and registered with the containing Parser prior to adding statements that reference it. Values from within the option parser sequences are stored in a dictionary named name.
If the parser name in the fill-in referencing it is written as <name>, the first keyword of each option is are used to select the option parser.
Example: {options:<my_options>}
This allows optionals before the option parser, or multiple parallel option parsers. Only one option parser will be used at a time (though an optional non-iterating option parsing could precede a final iterating one).
| std::istream::int_type Parsnip::next_non_whitespace | ( | InputStream & | from | ) |
Read from a stream until a non-whitespace character is found.
| DataFormatError | if EOF is encountered. |
| Data Parsnip::parse_json | ( | const std::string & | from | ) |
Parse a string as a JSON stream.
| from | The string to parse. |
| DataFormatError | if JSON is mangled. |
| DataRangeError | If the stream contains unrepresentable numbers. |
| Data Parsnip::parse_json | ( | std::istream & | from, |
| bool | check_termination | ||
| ) |
Parse a stream as JSON data.
| from | The stream to parse. |
| check_termination | If true (default), validates stream terminates (EOF) after end of JSON data. If false, stops reading after a complete JSON object has been read. |
| DataFormatError | if JSON is mangled. |
| DataRangeError | If the stream contains unrepresentable numbers. |