OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
parameter_def.hpp
Go to the documentation of this file.
1 //
2 // Copyright & License: See Copyright.readme in src directory
3 //
4 
9 #ifndef PARAMETER_DEF_HPP_
10 #define PARAMETER_DEF_HPP_
11 
12 #include "parameter.hpp"
13 
14 #include <boost/spirit/include/phoenix_core.hpp>
15 #include <boost/spirit/include/phoenix_operator.hpp>
16 #include <boost/spirit/include/phoenix_fusion.hpp>
17 #include <boost/spirit/include/phoenix_object.hpp>
18 #include <boost/spirit/include/phoenix_bind.hpp>
19 
20 namespace SDDS { namespace parser
21 {
22  template <typename Iterator>
23  parameter_parser<Iterator>::parameter_parser(error_handler<Iterator> & _error_handler):
24  parameter_parser::base_type(start)
25  {
26  using qi::on_error;
27  using qi::on_success;
28  using qi::fail;
29  using phx::function;
30  typedef function<error_handler<Iterator> > error_handler_function;
31 
32  // qi::_0_type _0;
33  qi::_1_type _1;
34  qi::_3_type _3;
35  qi::_4_type _4;
36  qi::lexeme_type lexeme;
37  qi::char_type char_;
38  qi::lit_type lit;
39  qi::long_type long_;
40  qi::alpha_type alpha;
41  qi::alnum_type alnum;
42  qi::_val_type _val;
43  qi::_pass_type _pass;
44  qi::eps_type eps;
45 
46  quoted_string %= lexeme['"' >> +(char_ - '"') >> '"'];
47  string %= quoted_string
48  | lexeme[(alpha | char_("@:#+-%._$&/")) >> *(alnum | char_("@:#+-%._$&/"))];
49  units %= lexeme[alpha >> *(alpha | char_('/'))]
50  | char_('1');
51 
52  datatype.add
53  ("float", ast::FLOAT)
54  ("double", ast::DOUBLE)
55  ("short", ast::SHORT)
56  ("long", ast::LONG)
57  ("character", ast::CHARACTER)
58  ("string", ast::STRING)
59  ;
60 
61  parameter_name = lit("name") > '=' > string;
62  parameter_units %= lit("units") > '=' > units;
63  parameter_description %= lit("description") > '=' > string;
64  parameter_type %= lit("type") > '=' > datatype;
65  parameter_symbol = lit("symbol") > '=' > string;
66  parameter_format = lit("format_string") > '=' > string;
67  parameter_fixed = lit("fixed_value") > long_;
68 
69  auto complainSymbol = phx::bind(&parameter::complainUnsupported<parameter::SYMBOL>::apply);
70  auto complainFormat = phx::bind(&parameter::complainUnsupported<parameter::FORMAT_STRING>::apply);
71  auto complainFixed = phx::bind(&parameter::complainUnsupported<parameter::FIXED_VALUE>::apply);
72 
73  parameter_unsupported_pre =
74  ((',' > parameter_symbol[_pass = complainSymbol])
75  ^ (',' > parameter_format[_pass = complainFormat])
76  ^ (',' > parameter_fixed[_pass = complainFixed])
77  );
78  parameter_unsupported_post =
79  ((parameter_symbol[_pass = complainSymbol] > ',')
80  ^ (parameter_format[_pass = complainFormat] > ',')
81  ^ (parameter_fixed[_pass = complainFixed] > ',')
82  );
83 
84  start =
85  lit("&parameter")
86  > -parameter_unsupported_post
87  >> ((parameter_name[phx::at_c<0>(_val) = _1]
88  >> ((',' >> parameter_type[phx::at_c<1>(_val) = _1])
89  ^(',' >> parameter_units[phx::at_c<2>(_val) = _1])
90  ^(',' >> parameter_description[phx::at_c<3>(_val) = _1])
91  ))
92  |(parameter_type[phx::at_c<1>(_val) = _1]
93  >> ((',' >> parameter_name[phx::at_c<0>(_val) = _1])
94  ^(',' >> parameter_units[phx::at_c<2>(_val) = _1])
95  ^(',' >> parameter_description[phx::at_c<3>(_val) = _1])
96  ))
97  |(parameter_units[phx::at_c<2>(_val) = _1]
98  >> ((',' >> parameter_type[phx::at_c<1>(_val) = _1])
99  ^(',' >> parameter_name[phx::at_c<0>(_val) = _1])
100  ^(',' >> parameter_description[phx::at_c<3>(_val) = _1])
101  ))
102  |(parameter_description[phx::at_c<3>(_val) = _1]
103  >> ((',' >> parameter_type[phx::at_c<1>(_val) = _1])
104  ^(',' >> parameter_units[phx::at_c<2>(_val) = _1])
105  ^(',' >> parameter_name[phx::at_c<0>(_val) = _1])
106  ))
107  )
108  > -parameter_unsupported_pre
109  > lit("&end")
110  >> eps[_pass = phx::bind(&parameter::checkMandatories, _val)];
111 
112  BOOST_SPIRIT_DEBUG_NODES(
113  (start)
114  )
115 
116  on_error<fail>(start,
117  error_handler_function(_error_handler)(
118  std::string("Error! Expecting "), _4, _3));
119 
120  }
121 }}
122 #endif /* PARAMETER_DEF_HPP_ */
constexpr double alpha
The fine structure constant, no dimension.
Definition: Physics.h:79
datatype
Definition: ast.hpp:20