Reference
To use lexy, you need three things:
lexy is designed to work with your own types and data structures. As such, its usage can be hidden away in the implementation of a parse function whose interface does not mention lexy specific types. Nevertheless, lexy defines some infrastructure types that can be used as vocabulary types in your project interfaces.
Infrastructure
lexy/code_point.hppA Unicode code point, and related algorithms.
lexy/lexeme.hppA lexeme, i.e. a subrange of the input.
lexy/token.hppIdentify and store tokens, i.e. concrete realization of token rules.
lexy/parse_tree.hppA parse tree.
lexy/error.hppThe parse errors.
lexy/input_location.hppCompute human readable line/column numbers for a position of the input.
lexy/visualize.hppVisualize the data structures.
Inputs and Encodings
template <typename T>
concept reader = …;
template <typename T>
concept input = requires(const T& obj) {
{ obj.reader() } -> reader;
};An input defines the input that will be parsed by lexy. It has a corresponding encoding that controls, among other things, its character type and whether certain rules are available. The input itself is unchanging and it produces a reader which remembers the current position of the input during parsing.
lexy/encoding.hpp:lexy::default_encodingAn unknown single byte encoding.
lexy::ascii_encodingASCII
lexy::utf8_encoding,lexy::utf16_encoding,lexy::utf32_encodingUTF-8, UTF-16, UTF-32
lexy::byte_encodingBytes, not text.
lexy::parse_tree_encodingParse tree nodes, not characters.
lexy/range_input.hppUse a generic iterator range as input.
lexy/string_input.hppUse a string as input.
lexy/buffer.hppCreate a buffer that contains the input.
lexy/file.hppUse a file as input.
lexy/argv_input.hppUse the command-line arguments as input.
lexy/lexeme_input.hppUse a subset of an existing input while computing correct line/column information.
lexy/parse_tree_input.hppUse a parse tree as input.
The grammar DSL
template <typename T>
concept production = requires {
{ T::production } -> rule;
{ T::whitespace } -> rule; // optional
{ T::value } -> callback-or-sink; // optional
};The grammar is specified by productions: classes with a ::rule member that specifies the rule.
They can optionally have a ::whitespace member that controls automatic whitespace skipping.
Both of those are specified in a C++ DSL.
The action lexy::parse also needs a ::value member that controls the value produced by parsing the production.
It is specified using callbacks, special function objects, and sinks.
lexy/grammar.hppType traits for defining and interacting with the grammar.
lexy/dsl.hppThe DSL for specifying parse rules.
lexy/callback.hppThe predefined callbacks and sinks for specifying the value.
Tip | It is a recommended to put all the productions into a separate namespace. |
Actions
Actions take a grammar and an input, and do something with the grammar on that input.
They also optionally take a parse state argument.
If provided, it will be forwarded as state parameter to the callbacks,
and to rules such as lexy::dsl::scan.
It can be used to pass additional meta data or allocators etc. to the grammar.
lexy/action/match.hppMatches a grammar on an input and return a
true/falseresult.lexy/action/validate.hppValidates that a grammar matches on an input, and returns the errors if it does not.
lexy/action/parse.hppParses a grammar on an input and returns its value.
lexy/action/parse_as_tree.hppParses a grammar on an input and returns the parse tree.
lexy/action/scan.hppParses a grammar manually by dispatching to other rules.
lexy/action/trace.hppTraces parse events to visualize and debug the parsing process.