OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
column_def.hpp
Go to the documentation of this file.
1 //
2 // Copyright & License: See Copyright.readme in src directory
3 //
4 
9 #ifndef COLUMN_DEF_HPP_
10 #define COLUMN_DEF_HPP_
11 
12 #include "column.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  column_parser<Iterator>::column_parser(error_handler<Iterator> & _error_handler):
24  column_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::long_type long_;
39  qi::lit_type lit;
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 %= char_('1') | lexeme[alpha >> *(alpha | char_('/'))];
50 
51  datatype.add
52  ("float", ast::FLOAT)
53  ("double", ast::DOUBLE)
54  ("short", ast::SHORT)
55  ("long", ast::LONG)
56  ("character", ast::CHARACTER)
57  ("string", ast::STRING)
58  ;
59 
60  column_name = lit("name") > '=' > string;
61  column_units %= lit("units") > '=' > units;
62  column_description %= lit("description") > '=' > string;
63  column_type %= lit("type") > '=' > datatype;
64  column_symbol = lit("symbol") > '=' > string;
65  column_format = lit("format_string") > '=' > string;
66  column_field = lit("field_length") > '=' > long_;
67 
68  auto complainSymbol = phx::bind(&column::complainUnsupported<column::SYMBOL>::apply);
69  auto complainFormat = phx::bind(&column::complainUnsupported<column::FORMAT_STRING>::apply);
70  auto complainField = phx::bind(&column::complainUnsupported<column::FIELD_LENGTH>::apply);
71 
72  column_unsupported_pre =
73  ((',' > column_symbol[_pass = complainSymbol])
74  ^ (',' > column_format[_pass = complainFormat])
75  ^ (',' > column_field[_pass = complainField])
76  );
77  column_unsupported_post =
78  ((column_symbol[_pass = complainSymbol] > ',')
79  ^ (column_format[_pass = complainFormat] > ',')
80  ^ (column_field[_pass = complainField] > ',')
81  );
82 
83  start =
84  lit("&column")
85  > -column_unsupported_post
86  >> ((column_name[phx::at_c<0>(_val) = _1]
87  >> ((',' >> column_type[phx::at_c<1>(_val) = _1])
88  ^(',' >> column_units[phx::at_c<2>(_val) = _1])
89  ^(',' >> column_description[phx::at_c<3>(_val) = _1])
90  ))
91  |(column_type[phx::at_c<1>(_val) = _1]
92  >> ((',' >> column_name[phx::at_c<0>(_val) = _1])
93  ^(',' >> column_units[phx::at_c<2>(_val) = _1])
94  ^(',' >> column_description[phx::at_c<3>(_val) = _1])
95  ))
96  |(column_units[phx::at_c<2>(_val) = _1]
97  >> ((',' >> column_type[phx::at_c<1>(_val) = _1])
98  ^(',' >> column_name[phx::at_c<0>(_val) = _1])
99  ^(',' >> column_description[phx::at_c<3>(_val) = _1])
100  ))
101  |(column_description[phx::at_c<3>(_val) = _1]
102  >> ((',' >> column_type[phx::at_c<1>(_val) = _1])
103  ^(',' >> column_units[phx::at_c<2>(_val) = _1])
104  ^(',' >> column_name[phx::at_c<0>(_val) = _1])
105  ))
106  )
107  > -column_unsupported_pre
108  > lit("&end")
109  >> eps[_pass = phx::bind(&column::checkMandatories, _val)];
110 
111  BOOST_SPIRIT_DEBUG_NODES(
112  (start)
113  )
114 
115  on_error<fail>(start,
116  error_handler_function(_error_handler)(
117  std::string("Error! Expecting "), _4, _3));
118 
119  }
120 }}
121 #endif /* COLUMN_DEF_HPP_ */
constexpr double alpha
The fine structure constant, no dimension.
Definition: Physics.h:79
datatype
Definition: ast.hpp:20