Header lexy/action/parse_as_tree.hpp

Action lexy::parse_as_tree

lexy/action/parse_as_tree.hpp
namespace lexy
{
    template <typename State, typename Input, typename ErrorCallback,
              typename TokenKind = void, typename MemoryResource = default-resource>
    struct parse_as_tree_action;

    template <production Production,
              typename TK, typename MemRes,
              input Input>
    auto parse_as_tree(parse_tree<lexy::input_reader<Input>, TK, MemRes>& tree,
                       const Input& input, error-callback auto error_callback)
        -> validate_result<decltype(error_callback)>;

    template <production Production,
              typename TK, typename MemRes,
              input Input, typename ParseState>
    auto parse_as_tree(parse_tree<lexy::input_reader<Input>, TK, MemRes>& tree,
                       const Input& input, ParseState& parse_state, error-callback auto error_callback)
        -> validate_result<decltype(error_callback)>;
    template <production Production,
              typename TK, typename MemRes,
              input Input, typename ParseState>
    auto parse_as_tree(parse_tree<lexy::input_reader<Input>, TK, MemRes>& tree,
                       const Input& input, const ParseState& parse_state, error-callback auto error_callback)
        -> validate_result<decltype(error_callback)>;
}

An action that parses Production on input and produces a lexy::parse_tree .

It parses Production on input. All values produced during parsing are discarded; all errors raised are forwarded to the error callback. Returns the lexy::validate_result  containing the result of the error callback.

During parsing, tree is cleared and replaced by a new tree that represents the parse tree of the input: it will have a production node for each production, and a token node for each tokens as indicated by the rules. If a production is a lexy::transparent_production , it will not get its own node in the parse tree, but the would-be children instead added to the currently active node. If a token rule has an ignorable lexy::token_kind  and matches without having consumed any input, it will not be added to the parse tree.

The resulting parse tree is a lossless representation of the input: Traversing all token nodes of the tree and concatenating their lexy::lexeme s will yield the same input back. Any remaining input that was not parsed by the production is stored in the tree’s remaining_input() lexy::lexeme ; if the remaining input is empty, both iterators will point to the end of the input.

See also