1 #ifndef STAN_LANG_GRAMMARS_INDEXES_GRAMMAR_HPP 2 #define STAN_LANG_GRAMMARS_INDEXES_GRAMMAR_HPP 3 4 #include <stan/lang/ast.hpp> 5 #include <stan/lang/grammars/expression_grammar.hpp> 6 #include <stan/lang/grammars/semantic_actions.hpp> 7 #include <stan/lang/grammars/whitespace_grammar.hpp> 8 #include <boost/spirit/include/qi.hpp> 9 #include <string> 10 #include <sstream> 11 #include <vector> 12 13 namespace stan { 14 15 namespace lang { 16 17 // needed to break circularity of expression grammar including indexes 18 template <typename Iterator> 19 struct expression_grammar; 20 21 template <typename Iterator> 22 struct indexes_grammar 23 : boost::spirit::qi::grammar<Iterator, 24 std::vector<idx>(scope), 25 whitespace_grammar<Iterator> > { 26 variable_map& var_map_; 27 std::stringstream& error_msgs_; 28 expression_grammar<Iterator>& expression_g; 29 30 indexes_grammar(variable_map& var_map, 31 std::stringstream& error_msgs, 32 expression_grammar<Iterator>& eg); 33 34 boost::spirit::qi::rule<Iterator, 35 std::vector<idx>(scope), 36 whitespace_grammar<Iterator> > 37 indexes_r; 38 39 boost::spirit::qi::rule<Iterator, 40 idx(scope), 41 whitespace_grammar<Iterator> > 42 index_r; 43 44 boost::spirit::qi::rule<Iterator, 45 boost::spirit::qi::unused_type, 46 whitespace_grammar<Iterator> > 47 close_indexes_r; 48 49 50 boost::spirit::qi::rule<Iterator, 51 uni_idx(scope), 52 whitespace_grammar<Iterator> > 53 uni_index_r; 54 55 boost::spirit::qi::rule<Iterator, 56 multi_idx(scope), 57 whitespace_grammar<Iterator> > 58 multi_index_r; 59 60 boost::spirit::qi::rule<Iterator, 61 omni_idx(scope), 62 whitespace_grammar<Iterator> > 63 omni_index_r; 64 65 boost::spirit::qi::rule<Iterator, 66 lb_idx(scope), 67 whitespace_grammar<Iterator> > 68 lb_index_r; 69 70 boost::spirit::qi::rule<Iterator, 71 ub_idx(scope), 72 whitespace_grammar<Iterator> > 73 ub_index_r; 74 75 76 boost::spirit::qi::rule<Iterator, 77 lub_idx(scope), 78 whitespace_grammar<Iterator> > 79 lub_index_r; 80 81 boost::spirit::qi::rule<Iterator, 82 expression(scope), 83 whitespace_grammar<Iterator> > 84 int_expression_r; 85 }; 86 87 } 88 } 89 #endif 90