alaCarte Maps
Renderer for OpenStreetMap tiles
eval_grammar.cpp
Go to the documentation of this file.
1 
23 #include <boost/spirit/include/qi.hpp>
24 #include <boost/spirit/include/phoenix_core.hpp>
25 #include <boost/spirit/include/phoenix_operator.hpp>
26 #include <boost/spirit/include/phoenix_fusion.hpp>
27 #include <boost/spirit/include/phoenix_object.hpp>
28 #include <boost/spirit/include/phoenix_stl.hpp>
29 #include <boost/spirit/include/phoenix_bind.hpp>
30 #include <boost/spirit/include/phoenix.hpp>
31 
32 
36 #include "server/eval/eval.hpp"
37 #include "server/eval/stleaf.hpp"
38 
39 
40 namespace phx = boost::phoenix;
41 
42 
43 namespace eval {
44 
45 
47 struct Lvl1Operator : public qi::symbols<char, op::BinaryOperationEnum>
48 {
50  {
51  this->add
52  ("==", op::Equal)
53  ("!=", op::Unequal)
54  ("<", op::Less)
55  ("<=", op::LessEqual)
56  (">", op::Greater)
57  (">=", op::GreaterEqual)
58  ("eq", op::StringEqual)
59  ("ne", op::StringUnequal);
60  }
62 
64 struct Lvl2Operator : public qi::symbols<char, op::BinaryOperationEnum>
65 {
67  {
68  this->add
69  ("+", op::Add)
70  ("-", op::Minus);
71  }
73 
75 struct Lvl3Operator : public qi::symbols<char, op::BinaryOperationEnum>
76 {
78  {
79  this->add
80  ("*", op::Mul);
81  }
83 
85 struct Lvl4Operator : public qi::symbols<char, op::BinaryOperationEnum>
86 {
88  {
89  this->add
90  ("/", op::Div)
91  (".", op::Concatination);
92  }
94 
96 struct FunctionOperators : public qi::symbols<char, op::FunctionEnum>
97 {
99  {
100  this->add
101  // Canonical
102  ("boolean", op::Boolean)
103  ("str", op::Str)
104  ("num", op::Num)
105  // Mathematics
106  ("sqrt", op::Sqrt)
107  ("int", op::Int)
108  ("not", op::Not)
109  //Functions
110  ("tag", op::Tag)
111  ("cond", op::Cond)
112  ("colgen", op::Colgen);
113  }
114 } FuncOpSymbols;
115 
116 
117 
118 
119 
125  : EvalGrammer::base_type(rule_lvl1_expr, "eval-MainGrammar")
126  //, start("test-MainRule")
127 {
128  using namespace qi::labels;
129  using boost::phoenix::new_;
130  using boost::phoenix::construct;
131  using boost::phoenix::val;
132  auto& _1 = qi::_1;
133  auto& _2 = qi::_2;
134  auto& _3 = qi::_3;
135 
136  rule_string = (('\'' > *(qi::char_ - '\'') > '\'') | +qi::char_("a-zA-Z_0-9#"));
137 
138  rule_func_expr = ( FuncOpSymbols >> '(' >> (rule_lvl1_expr % ',') >> ')' )
139  [
140  _val = phx::construct<STNode::node_ptr>(phx::new_<FunctionOperationNode>(_1, _2))
141  ]
142  | ( '(' >> rule_lvl1_expr >> ')')
143  [
144  _val = phx::construct<STNode::node_ptr>(phx::new_<FunctionOperationNode>(_1))
145  ];
146 
148  [
149  _val = phx::construct<STNode::node_ptr>(phx::new_<BinaryOperationNode>(_1, _2, _3))
150  ]
151  | rule_func_expr[_val = _1]
153  [
154  _val = phx::construct<STNode::node_ptr>(phx::new_<BinaryOperationNode>(phx::construct<STNode::node_ptr>(phx::new_<STLeaf>(_1)), _2, _3))
155  ]
156  | rule_string
157  [
158  _val = phx::construct<STNode::node_ptr>(phx::new_<STLeaf>(_1))
159  ];
160 
162  [
163  _val = phx::construct<STNode::node_ptr>(phx::new_<BinaryOperationNode>(_1, _2, _3))
164  ]
165  | rule_lvl4_expr[_val = _1];
166 
168  [
169  _val = phx::construct<STNode::node_ptr>(phx::new_<BinaryOperationNode>(_1, _2, _3))
170  ]
171  | rule_lvl3_expr[_val = _1];
172 
173 
175  [
176  _val = phx::construct<STNode::node_ptr>(phx::new_<BinaryOperationNode>(_1, _2, _3))
177  ]
178  | rule_lvl2_expr[_val = _1];
179 
180 
181  rule_lvl3_expr.name("lvl 3");
182  rule_lvl2_expr.name("lvl 2");
183  rule_lvl1_expr.name("lvl 1");
184  rule_string.name("string");
185 
186  /*debug(rule_lvl3_expr);
187  debug(rule_lvl2_expr);
188  debug(rule_lvl1_expr);
189  debug(rule_string);*/
190 }
191 
192 
193 
194 }
eval::Lvl4Operator Lvl4OpSymbols
Grammar used to parse eval expressions.
Symbol parser for level 3 operations.
eval::Lvl3Operator Lvl3OpSymbols
qi::rule< ItType, STNode::node_ptr(), Skipper > rule_lvl2_expr
rule for lvl 2 operations
qi::rule< ItType, string()> rule_string
rule for a simple string
eval::FunctionOperators FuncOpSymbols
qi::rule< ItType, STNode::node_ptr(), Skipper > rule_func_expr
rule for function expressions
qi::rule< ItType, STNode::node_ptr(), Skipper > rule_lvl1_expr
rule for lvl 1 operations
This file is part of alaCarte.
eval::Lvl1Operator Lvl1OpSymbols
qi::rule< ItType, STNode::node_ptr(), Skipper > rule_lvl4_expr
rule for lvl 4 operations
Symbol parser for level 1 operations.
Symbol parser for the function operations.
Symbol parser for level 2 operations.
qi::rule< ItType, STNode::node_ptr(), Skipper > rule_lvl3_expr
rule for lvl 3 operations
eval::Lvl2Operator Lvl2OpSymbols
EvalGrammer()
Creates an eval grammar.
Symbol parser for level 4 operations.