### RExpressions JSON-like Language Example Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/rexpr This code snippet demonstrates the structure of a minimalistic JSON-like language that can be parsed by Boost.Spirit X3. It includes nested dictionaries and key-value pairs. ```cpp { "color" = "blue" "size" = "29 cm." "position" = { "x" = "123" "y" = "456" } } ``` -------------------------------- ### Simple Grammar Example (Throwing) Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/non_throwing_expectations A basic Boost Spirit X3 grammar demonstrating the default behavior of throwing an `expectation_failure` when input does not match the expected sequence 'a' followed by 'b'. ```cpp x3::lit('a') > 'b' ``` -------------------------------- ### Boost Spirit X3 Quick Reference and Index Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/changelog Provides links to essential resources for the Boost Spirit X3 library, including a quick reference guide for semantic actions and the main index page for comprehensive documentation. ```APIDOC Quick Reference - Semantic Actions: URL: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/quick_reference/semantic_actions.html Spirit X3 Index: URL: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/index.html ``` -------------------------------- ### Boost.Variant Example Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/rexpr Illustrates the basic usage of Boost.Variant for creating types that can hold different types of values, similar to how `rexpr_value` is defined. ```cpp typedef boost::variant my_variant; ``` -------------------------------- ### Spirit X3 Error Handler Example Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/error_handling A C++ example demonstrating a custom error handler for Spirit X3. This handler uses the x3::error_handler to provide detailed error messages, including the expected token and the location of the error. ```c++ struct error_handler { template x3::error_handler_result on_error( Iterator& first, Iterator const& last , Exception const& x, Context const& context) { auto& error_handler = x3::get(context).get(); std::string message = "Error! Expecting: " + x3::which(x) + " here:"; error_handler(x3::where(x), message); return x3::error_handler_result::fail; } }; // Usage within a parse call: // auto parse_result = x3::parse(input.begin(), input.end(), your_grammar, x3::with(error_handler_instance)); ``` -------------------------------- ### Main Program Header Includes Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/minimal This snippet shows the essential header files required for the main program in the minimal Boost Spirit X3 example. These headers provide declarations for the Abstract Syntax Tree (AST), AST adaptation for fusion traversal, and the main parser API. ```cpp #include "ast.hpp" #include "ast_adapted.hpp" #include "employee.hpp" ``` -------------------------------- ### Boost Spirit X3 Support and Licensing Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/preface Provides information on how to get support for the Boost Spirit X3 library, directing users to the Spirit mailing list and its archives. It also states the copyright and licensing terms under which the library is distributed. ```APIDOC Support: - Questions should be directed to the Spirit mailing list. - Subscription: https://lists.sourceforge.net/lists/listinfo/spirit-general - Archives are searchable from Spirit's home page. - NNTP portal: news://news.gmane.org/gmane.comp.spirit.general - NNTP Archives: http://news.gmane.org/gmane.comp.parsers.spirit.general Copyright: - © 2001-2018 Joel de Guzman, Hartmut Kaiser License: - Distributed under the Boost Software License, Version 1.0. - See LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt ``` -------------------------------- ### Boost Spirit X3 Includes and Namespaces Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/sum___adding_numbers Essential includes and namespace directives for using Boost Spirit X3 in C++ projects. This sets up the environment for defining parsers and using Spirit's components. ```cpp #include #include #include namespace x3 = boost::spirit::x3; namespace ascii = boost::spirit::x3::ascii; using x3::double_; using ascii::space; using x3::_attr; ``` -------------------------------- ### Boost.Spirit X3 Common Notation Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/quick_reference Details the common notation used within the Boost.Spirit X3 library. This is essential for understanding the syntax and conventions employed in parser definitions and examples. ```APIDOC Common Notation: Description: Defines the standard symbols and conventions used in Boost.Spirit X3. Usage: Essential for interpreting parser definitions and examples. Reference: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/quick_reference/common_notation.html ``` -------------------------------- ### Spirit X3 Rule Declaration Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/roman Demonstrates the basic syntax for declaring a named parser 'rule' in Spirit X3, which is essential for building complex grammars by breaking them into manageable, named components. ```cpp rule const r = "some-name"; ``` -------------------------------- ### Spirit X3 Quick Reference Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/index Provides quick reference guides for key concepts in Spirit X3, including compound attribute rules, nonterminals, and parser semantic actions. These are essential for understanding the library's core components. ```C++ Compound Attribute Rules: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/quick_reference/compound_attribute_rules.html Nonterminals: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/quick_reference/non_terminals.html Parser Semantic Actions: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/quick_reference/semantic_actions.html ``` -------------------------------- ### Boost.Fusion Struct Adaptation Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/employee Adapts the 'client::ast::employee' struct to be a Boost.Fusion-compatible type. This allows Spirit X3 to seamlessly work with the struct as a tuple, enabling direct attribute assignment. ```cpp BOOST_FUSION_ADAPT_STRUCT( client::ast::employee, age, forename, surname, salary ) ``` -------------------------------- ### Boost Spirit X3 Attribute Actions for Summation Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/sum___adding_numbers Demonstrates the use of attribute actions in Boost Spirit X3 for accumulating values during parsing. The `assign` lambda initializes the sum with the first parsed number, and the `add` lambda adds subsequent parsed numbers to the accumulator. ```cpp auto assign = [&](auto& ctx){ n = _attr(ctx); }; auto add = [&](auto& ctx){ n += _attr(ctx); }; ``` -------------------------------- ### Parse Roman Numeral Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/roman Parses a Roman numeral string using Spirit X3. The `parse` function attempts to match the `roman` parser against the input range `[iter, end)`. It takes an attribute `result` to store the parsed unsigned integer. The example checks if parsing was successful and if the entire input was consumed. ```cpp bool r = parse(iter, end, roman, result); if (r && iter == end) { std::cout << "-------------------------\\n"; std::cout << "Parsing succeeded\\n"; std::cout << "result = " << result << std::endl; std::cout << "-------------------------\\n"; } else { std::string rest(iter, end); std::cout << "-------------------------\\n"; std::cout << "Parsing failed\\n"; std::cout << "stopped at: \": " << rest << "\"\\n"; std::cout << "-------------------------\\n"; } ``` -------------------------------- ### Boost.Spirit X3 Quick Reference Overview Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/quick_reference This section provides a high-level overview of the Boost.Spirit X3 quick reference, highlighting its purpose as a cheat-sheet for frequently used components. It is not exhaustive but aims to aid in recalling specific elements without extensive documentation searches. ```APIDOC Boost.Spirit X3 Quick Reference: Purpose: Provide a cheat-sheet for commonly used X3 components. Scope: Covers notation, character, numeric, string, binary parsers, directives, operators, semantic actions, attribute rules, and nonterminals. Limitations: Not intended to be a complete reference. ``` -------------------------------- ### Spirit X3 Roman Numeral Grammar Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/roman A complete example of a Spirit X3 grammar for parsing Roman numerals. It defines a namespace for the parser, includes necessary using declarations, and sets up rules with associated actions (lambda functions) for attribute manipulation. The 'roman' rule uses 'eps' for initialization and sequences parsers for thousands, hundreds, tens, and ones. ```cpp namespace parser { using x3::eps; using x3::lit; using x3::_val; using x3::_attr; using ascii::char_; auto set_zero = [](auto& ctx){ _val(ctx) = 0; }; auto add1000 = [](auto& ctx){ _val(ctx) += 1000; }; auto add = [](auto& ctx){ _val(ctx) += _attr(ctx); }; x3::rule const roman = "roman"; auto const roman_def = eps [set_zero] >> ( -(+lit('M') [add1000]) >> -hundreds [add] >> -tens [add] >> -ones [add] ) ; BOOST_SPIRIT_DEFINE(roman); } ``` -------------------------------- ### EBNF Grammar Example Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/introduction A traditional Extended Backus Naur Form (EBNF) grammar definition for a simple calculator. ```EBNF group ::= '(' expression ')' factor ::= integer | group term ::= factor (('*' factor) | ('/' factor))* expression ::= term (('+' term) | ('-' term))* ``` -------------------------------- ### Fusion Adapter for AST Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/minimal Adapts the 'employee' AST structure for use with Boost.Fusion, making it a first-class Fusion citizen. This allows for seamless integration with Fusion's sequence and algorithm capabilities. ```cpp BOOST_FUSION_ADAPT_STRUCT(client::ast::employee, age, forename, surname, salary ) ``` -------------------------------- ### Boost.Spirit X3 Tutorials Overview Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials This section lists various tutorials for Boost.Spirit X3, a C++ parsing library. The tutorials cover a range of topics, from basic usage to more advanced features. ```cpp #include // ... tutorials on: // Quick Start // Warming up // Parser Semantic Actions // Complex - Our first complex parser // Sum - adding numbers // Number List - stuffing numbers into a std::vector // Number List Redux - list syntax // Number List Attribute - one more, with style // Roman Numerals // Employee - Parsing into structs // X3 Program Structure // Annotations - Decorating the ASTs // RExpressions - Recursive ASTs! // Error Handling // Non-throwing Expectations ``` -------------------------------- ### Boost Spirit X3 Documentation Structure Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/preface Explains the organization of the Boost Spirit X3 documentation into three main parts: Tutorials for step-by-step guidance with annotated code, Abstracts for high-level summaries of key topics, and Reference for detailed formal technical information. It also mentions the use of icons to denote different types of information. ```APIDOC Documentation Structure: 1. Tutorials: Step-by-step guide with annotated code for quick user acquaintance. 2. Abstracts: High-level summary of key topics, concepts, background, and theories. 3. Reference: Detailed formal technical reference, including quick reference tables and concept models. Icons: - Note: Generally useful information. - Tip: Suggestion on how to do something. - Important: Important note requiring particular notice. - Caution: Take special care, may cause bad results. - Danger: Likely to cause serious trouble if ignored. ``` -------------------------------- ### Spirit X3 Sequence Attribute Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/employee Explains how attributes are combined in sequences using the '>>' operator. The attribute of a sequence is typically a fusion::vector (tuple) of the attributes of its constituent parsers. ```c++ "'" >> +(char_ - '"') >> '"' ``` ```c++ fusion::vector ``` -------------------------------- ### Boost.Spirit X3 Tutorials: Non-Throwing Expectations Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/quick_reference Provides guidance on using non-throwing expectations within Boost.Spirit X3, a feature for handling parsing errors without exceptions. ```APIDOC Tutorial: Non-Throwing Expectations: Topic: Handling parsing outcomes without exceptions. Reference: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/non_throwing_expectations.html ``` -------------------------------- ### Boost Spirit X3 Syntax Diagram Constructs Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/abstracts/syntax_diagram Explains the common constructs used in Boost Spirit X3 syntax diagrams to build grammars. This includes sequences, ordered choices (alternatives), optional elements, and loops (zero-or-more, one-or-more), detailing their graphical representation and PEG-specific behavior. ```APIDOC Sequence (B follows A): - Represents sequential execution of grammar rules. Ordered Choice / Alternatives: - Represents choices between grammar rules. - In PEG, the first successful branch is taken in case of ambiguity. Optional (zero-or-one): - Represents an element that may appear zero or one time. Loops: - Zero-or-more: Represents an element that may appear any number of times (including zero). - One-or-more: Represents an element that must appear at least once. - PEG loops are greedy and can fail if preceding elements consume input needed by the loop. ``` -------------------------------- ### Spirit X3 Rule Declaration Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/employee Declares a Spirit X3 rule named 'employee' that is associated with the 'client::ast::employee' struct. This rule serves as the main parser for the employee data. ```cpp x3::rule employee = "employee"; ``` -------------------------------- ### BOOST_SPIRIT_INSTANTIATE for Parser Instantiation Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/minimal Demonstrates the use of BOOST_SPIRIT_INSTANTIATE to instantiate a Boost.Spirit X3 parser for a specific configuration. This macro ties together the parser rule, iterator type, and context type, making the parser ready for use. ```cpp namespace client { namespace parser { BOOST_SPIRIT_INSTANTIATE(employee_type, iterator_type, context_type); }} ``` -------------------------------- ### BOOST_SPIRIT_DEFINE Macro Usage Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/roman Illustrates the use of the BOOST_SPIRIT_DEFINE macro to associate a rule with its definition. This macro generates the necessary functions for Spirit X3 to invoke the rule during parsing. It can be used for multiple rules at once. ```cpp BOOST_SPIRIT_DEFINE(r); // Example for multiple rules: // BOOST_SPIRIT_DEFINE(r1, r2, r3); ``` -------------------------------- ### Boost.Spirit X3 Binary Parsers Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/quick_reference Details parsers specifically designed for handling binary data streams. ```APIDOC Binary Parsers: Description: Parsers for matching and interpreting binary data. Reference: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/quick_reference/binary.html ``` -------------------------------- ### Example Semantic Action with C++14 Lambda Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/semantic_actions Demonstrates using a C++14 generic lambda as a semantic action to print the parsed attribute. This approach is often more concise for simple actions. ```cpp auto f = [](auto& ctx){ std::cout << _attr(ctx) << std::endl; }; parse(first, last, '{' >> int_[f] >> '}'); ``` -------------------------------- ### Boost Spirit X3 Abstracts Overview Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/abstracts This section provides an overview of the abstracts within the Boost Spirit X3 library. It links to detailed explanations of syntax diagrams, parsing expression grammars, and the attributes of various components, including primitive components, compound components, and nonterminals. ```cpp #include #include #include // This is a conceptual representation. Actual code would involve defining parsers. // Example: Parsing an expression with attributes // auto expression = ...; // auto result = boost::spirit::x3::parse("input_string", expression); ``` -------------------------------- ### Boost.Spirit.X3: Scalability and Layers Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/quick_start The library is structured in layers, allowing users to learn and utilize features on an as-needed basis. This approach makes the tool scalable and manageable, even for complex parsing tasks. ```C++ // Learn the minimal core and basic concepts first. // Incrementally build on examples to expose more features. // The layered structure supports a gentle learning curve. ``` -------------------------------- ### Spirit X3 '+' Operator Attribute Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/employee Demonstrates the attribute type for the Spirit X3 '+' operator, which matches one or more occurrences of a parser. The attribute is a std::vector of the attribute type of the contained parser. ```c++ +a ``` ```c++ std::vector ``` ```c++ +(char_ - '"') ``` -------------------------------- ### Boost.Spirit.X3: Header-Only Library Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/quick_start Boost.Spirit.X3 is a header-only library, meaning there are no separate libraries to link against or build. Users only need to include the Spirit distribution in their include path to use the library. ```C++ // Include the Spirit distribution in your include path // #include // No linking required, just compile and run. ``` -------------------------------- ### Spirit X3 Character Difference Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/employee Illustrates the Spirit X3 difference operator ('-') which parses the left operand but not the right. In this context, 'char_ - '"'' parses any character except a double quote. ```cpp char_ - '"' ``` -------------------------------- ### Employee Struct Definition Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/employee Defines the C++ struct 'employee' to hold parsed data, including integer age, string forename and surname, and double salary. This struct will be populated by the Spirit X3 parser. ```cpp namespace client { namespace ast { struct employee { int age; std::string forename; std::string surname; double salary; }; }} ``` -------------------------------- ### Spirit X3 Operator Equivalents Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/introduction Illustrates the mapping between EBNF syntax and Boost Spirit X3's C++ operator equivalents for sequencing, alternatives, and repetition. ```C++ // EBNF: a b (sequencing) // Spirit X3: a >> b // EBNF: a* (Kleene star) // Spirit X3: *a ``` -------------------------------- ### Example Semantic Action with Function Object Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/semantic_actions Illustrates a semantic action implemented as a C++ function object that prints the parsed attribute to standard output. This action is attached to an integer parser. ```cpp struct print_action { template void operator()(Context const& ctx) const { std::cout << _attr(ctx) << std::endl; } }; parse(first, last, '{' >> int_[print_action()] >> '}'); ``` -------------------------------- ### Boost.Spirit.X3: Practical Parsing Tool Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/quick_start Spirit.X3 is designed as a practical parsing tool, enabling the generation of fully-working parsers from formal EBNF specifications inlined within C++ code. This significantly reduces development time compared to traditional methods. ```C++ // Define parsers using EBNF syntax directly in C++. // Example: A simple integer parser // auto integer_parser = boost::spirit::x3::int_; // This approach is more maintainable than ad hoc hacks or basic regex. ``` -------------------------------- ### Spirit X3 Quoted String Parser Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/employee Defines a Spirit X3 parser for quoted strings using the 'lexeme' directive to prevent whitespace skipping. It parses characters between double quotes, excluding the closing quote. ```cpp lexeme['"' >> +(char_ - '"') >> '"']; ``` -------------------------------- ### Accessing AST Position with position_cache Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/annotation Demonstrates how to use the 'x3::position_cache' to retrieve the iterator range corresponding to an AST node within the input stream. The 'position_of' method returns the start and end positions of the parsed element. ```cpp auto pos = positions.position_of(my_ast); ``` -------------------------------- ### Include Boost Spirit X3 Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/include To use the Boost Spirit X3 library, you only need to include the main header file. This library is header-only, meaning there are no separate libraries to link against. ```cpp #include ``` -------------------------------- ### Example of Erroneous Input String Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/error_handling A C++ raw string literal representing input data that is intentionally malformed to trigger parsing errors. This input contains an incorrect type for a person's name. ```C++ std::string bad_input = R"( { 23, "Amanda", "Stefanski", 1000.99 }, { 35, "Angie", "Chilcote", 2000.99 }, { 43, 'I am not a person!' <--- this should be a person 3000.99 }, { 22, "Dorene", "Dole", 2500.99 }, { 38, "Rossana", "Rafferty", 5000.99 } )"; ``` -------------------------------- ### AST Printer Utility Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/rexpr A C++ utility to print an Abstract Syntax Tree (AST) for a 'rexpr' structure. It uses recursion and `boost::apply_visitor` to traverse and format the AST, handling nested structures and string values with proper indentation. ```C++ int const tabsize = 4; struct rexpr_printer { typedef void result_type; rexpr_printer(int indent = 0) : indent(indent) {} void operator()(rexpr const& ast) const { std::cout << '{' << std::endl; for (auto const& entry : ast.entries) { tab(indent+tabsize); std::cout << '"' << entry.first << '"' << " = "; boost::apply_visitor(rexpr_printer(indent+tabsize), entry.second); } tab(indent); std::cout << '}' << std::endl; } void operator()(std::string const& text) const { std::cout << '"' << text << '"' << std::endl; } void tab(int spaces) const { for (int i = 0; i < spaces; ++i) std::cout << ' '; } int indent; }; ``` -------------------------------- ### Spirit X3 Employee Parser Definition Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/employee Defines the Spirit X3 parser for the employee data format. It uses built-in parsers like 'int_', 'double_', 'lexeme', and custom logic for quoted strings to match the input structure. ```cpp namespace parser { namespace x3 = boost::spirit::x3; namespace ascii = boost::spirit::x3::ascii; using x3::int_; using x3::lit; using x3::double_; using x3::lexeme; using ascii::char_; x3::rule const employee = "employee"; auto const quoted_string = lexeme['"' >> +(char_ - '"') >> '"']; auto const employee_def = lit("employee") >> '{' >> int_ >> ',' >> quoted_string >> ',' >> quoted_string >> ',' >> double_ >> '}' ; BOOST_SPIRIT_DEFINE(employee); } ``` -------------------------------- ### Spirit X3 Predicates Overview Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/abstracts/syntax_diagram Explains the concept of PEG predicates as extensions to syntax diagrams. It details the And-Predicate and Not-Predicate, their behavior, and their look-ahead capabilities without consuming input. ```APIDOC Spirit X3 Predicates: Predicates are special extensions to PEG syntax diagrams that allow for conditional parsing without consuming input. 1. And-Predicate: - Tries the predicate, P. - Succeeds if P succeeds, otherwise fails. - Performs a look-ahead but does not consume input. 2. Not-Predicate: - Tries the predicate, P. - Fails if P succeeds, otherwise succeeds. - Performs a look-ahead but does not consume input. ``` -------------------------------- ### Roman Ones Parser with Symbol Table Source: https://www.boost.org/doc/libs/1_88_0/libs/spirit/doc/x3/html/spirit_x3/tutorials/roman Defines a Spirit X3 parser for Roman numeral ones (1-9) using the `x3::symbols` class. This parser associates string representations of ones with their corresponding unsigned integer values. ```cpp struct ones_ : x3::symbols { ones_() { add ("I" , 1) ("II" , 2) ("III" , 3) ("IV" , 4) ("V" , 5) ("VI" , 6) ("VII" , 7) ("VIII" , 8) ("IX" , 9) ; } } ones; ```