Header lexy/action/parse_as_tree.hpp

Action lexy::parse_as_tree

namespace lexy
    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)>;

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 production is a lexy::token_production, adjacent token nodes with the same lexy::token_kind are merged, and only one node will be added for each run of adjacent tokens. If a token rule has an unknown 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::lexemes will yield the same input back.

See also