1 /*=============================================================================
2 Copyright (c) 2001-2014 Joel de Guzman
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 =============================================================================*/
7 #if !defined(BOOST_SPIRIT_X3_CALC8_STATEMENT_DEF_HPP)
8 #define BOOST_SPIRIT_X3_CALC8_STATEMENT_DEF_HPP
10 #include <boost/spirit/home/x3.hpp>
11 #include <boost/spirit/home/x3/support/utility/annotate_on_success.hpp>
13 #include "ast_adapted.hpp"
14 #include "statement.hpp"
15 #include "expression.hpp"
17 #include "error_handler.hpp"
19 namespace client { namespace parser
23 using namespace x3::ascii;
25 struct statement_list_class;
26 struct variable_declaration_class;
27 struct assignment_class;
28 struct variable_class;
30 typedef x3::rule<statement_list_class, ast::statement_list> statement_list_type;
31 typedef x3::rule<variable_declaration_class, ast::variable_declaration> variable_declaration_type;
32 typedef x3::rule<assignment_class, ast::assignment> assignment_type;
33 typedef x3::rule<variable_class, ast::variable> variable_type;
35 statement_type const statement = "statement";
36 statement_list_type const statement_list = "statement_list";
37 variable_declaration_type const variable_declaration = "variable_declaration";
38 assignment_type const assignment = "assignment";
39 variable_type const variable = "variable";
41 // Import the expression rule
42 namespace { auto const& expression = client::expression(); }
44 auto const statement_list_def =
45 +(variable_declaration | assignment)
48 auto const variable_declaration_def =
49 lexeme["var" >> !(alnum | '_')] // make sure we have whole words
53 auto const assignment_def =
60 auto const variable_def = identifier;
61 auto const statement_def = statement_list;
66 , variable_declaration
71 struct statement_class : error_handler_base, x3::annotate_on_success {};
72 struct assignment_class : x3::annotate_on_success {};
73 struct variable_class : x3::annotate_on_success {};
78 parser::statement_type const& statement()
80 return parser::statement;