OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
array_def.hpp
Go to the documentation of this file.
1 //
2 // Struct array
3 //
4 // Copyright (c) 2015, Christof Metzger-Kraus, Helmholtz-Zentrum Berlin
5 // All rights reserved
6 //
7 // This file is part of OPAL.
8 //
9 // OPAL is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
16 //
17 #ifndef ARRAY_DEF_HPP_
18 #define ARRAY_DEF_HPP_
19 
20 #include "array.hpp"
21 
22 #include <boost/spirit/include/phoenix_core.hpp>
23 #include <boost/spirit/include/phoenix_operator.hpp>
24 #include <boost/spirit/include/phoenix_fusion.hpp>
25 #include <boost/spirit/include/phoenix_bind.hpp>
26 
27 namespace SDDS { namespace parser
28 {
29  template <typename Iterator>
31  array_parser::base_type(start)
32  {
33  using qi::on_error;
34  using qi::fail;
35  using phx::function;
36  typedef function<error_handler<Iterator> > error_handler_function;
37 
38  // qi::_1_type _1;
39  qi::_3_type _3;
40  qi::_4_type _4;
41  qi::lexeme_type lexeme;
42  qi::char_type char_;
43  qi::lit_type lit;
44  qi::long_type long_;
45  qi::short_type short_;
46  qi::alpha_type alpha;
47  qi::alnum_type alnum;
48  // qi::_val_type _val;
49  qi::_pass_type _pass;
50  qi::eps_type eps;
51 
52  quoted_string %= lexeme['"' >> +(char_ - '"') >> '"'];
53  string %= quoted_string
54  | lexeme[(alpha | char_("@:#+-%._$&/")) >> *(alnum | char_("@:#+-%._$&/"))];
55  units %= lexeme[alpha >> *(alpha | '/')]
56  | lit('1');
57 
58  arraytype.add
59  ("float", ast::FLOAT)
60  ("double", ast::DOUBLE)
61  ("short", ast::SHORT)
62  ("long", ast::LONG)
63  ("character", ast::CHARACTER)
64  ("string", ast::STRING)
65  ;
66 
67  array_name = lit("mode") > '=' > string;
68  array_symbol = lit("symbol") > '=' > string;
69  array_units = lit("units") > '=' > units;
70  array_description = lit("description") > '=' > string;
71  array_format = lit("format_string") > '=' > string;
72  array_group = lit("group_name") > '=' > string;
73  array_type = lit("type") > '=' > arraytype;
74  array_field = lit("field_length") > '=' > long_;
75  array_dimensions = lit("dimensions") > '=' > long_;
76 
77  auto complainArray = phx::bind(&array::complainUnsupported<array::ARRAY>::apply);
78  auto complainName = phx::bind(&array::complainUnsupported<array::NAME>::apply);
79  auto complainSymbol= phx::bind(&array::complainUnsupported<array::SYMBOL>::apply);
80  auto complainUnits = phx::bind(&array::complainUnsupported<array::UNITS>::apply);
81  auto complainDescription = phx::bind(&array::complainUnsupported<array::DESCRIPTION>::apply);
82  auto complainFormat= phx::bind(&array::complainUnsupported<array::FORMAT_STRING>::apply);
83  auto complainGroup = phx::bind(&array::complainUnsupported<array::GROUP_NAME>::apply);
84  auto complainType = phx::bind(&array::complainUnsupported<array::TYPE>::apply);
85  auto complainField = phx::bind(&array::complainUnsupported<array::FIELD_LENGTH>::apply);
86  auto complainDimensions = phx::bind(&array::complainUnsupported<array::DIMENSIONS>::apply);
87 
89  ((',' > array_name[_pass = complainName])
90  ^ (',' > array_symbol[_pass = complainSymbol])
91  ^ (',' > array_units[_pass = complainUnits])
92  ^ (',' > array_description[_pass = complainDescription])
93  ^ (',' > array_format[_pass = complainFormat])
94  ^ (',' > array_group[_pass = complainGroup])
95  ^ (',' > array_type[_pass = complainType])
96  ^ (',' > array_field[_pass = complainField])
97  ^ (',' > array_dimensions[_pass = complainDimensions])
98  );
100  ((array_name[_pass = complainName] > ',')
101  ^ (array_symbol[_pass = complainSymbol] > ',')
102  ^ (array_units[_pass = complainUnits] > ',')
103  ^ (array_description[_pass = complainDescription] > ',')
104  ^ (array_format[_pass = complainFormat] > ',')
105  ^ (array_group[_pass = complainGroup] > ',')
106  ^ (array_type[_pass = complainType] > ',')
107  ^ (array_field[_pass = complainField] > ',')
108  ^ (array_dimensions[_pass = complainDimensions] > ',')
109  );
110 
111  start =
112  lit("&array")[_pass = complainArray]
113  > lit("&end");
114 
115  BOOST_SPIRIT_DEBUG_NODES(
116  (start)
117  )
118 
119  on_error<fail>(start,
120  error_handler_function(_error_handler)(
121  std::string("Error! Expecting "), _4, _3));
122  }
123 }}
124 #endif /* ARRAY_DEF_HPP_ */
constexpr double alpha
The fine structure constant, no dimension.
Definition: Physics.h:78
Definition: array.hpp:33
@ STRING
Definition: ast.hpp:33
@ DOUBLE
Definition: ast.hpp:29
@ LONG
Definition: ast.hpp:31
@ FLOAT
Definition: ast.hpp:28
@ CHARACTER
Definition: ast.hpp:32
@ SHORT
Definition: ast.hpp:30
qi::rule< Iterator, std::string(), skipper< Iterator > > array_format
Definition: array.hpp:115
qi::rule< Iterator, array(), skipper< Iterator > > start
Definition: array.hpp:113
qi::rule< Iterator, std::string(), skipper< Iterator > > array_symbol
Definition: array.hpp:115
qi::rule< Iterator, ast::nil(), skipper< Iterator > > array_unsupported_post
Definition: array.hpp:121
qi::rule< Iterator, ast::nil(), skipper< Iterator > > array_unsupported_pre
Definition: array.hpp:120
qi::rule< Iterator, long(), skipper< Iterator > > array_dimensions
Definition: array.hpp:118
array_parser(error_handler< Iterator > &_error_handler)
Definition: array_def.hpp:30
qi::rule< Iterator, std::string(), skipper< Iterator > > array_description
Definition: array.hpp:115
qi::rule< Iterator, std::string(), skipper< Iterator > > quoted_string
Definition: array.hpp:116
qi::rule< Iterator, std::string(), skipper< Iterator > > array_units
Definition: array.hpp:115
qi::rule< Iterator, std::string(), skipper< Iterator > > array_name
Definition: array.hpp:114
qi::symbols< char, ast::datatype > arraytype
Definition: array.hpp:122
qi::rule< Iterator, std::string(), skipper< Iterator > > units
Definition: array.hpp:116
qi::rule< Iterator, std::string(), skipper< Iterator > > array_group
Definition: array.hpp:116
qi::rule< Iterator, std::string(), skipper< Iterator > > string
Definition: array.hpp:116
qi::rule< Iterator, ast::datatype, skipper< Iterator > > array_type
Definition: array.hpp:119
qi::rule< Iterator, long(), skipper< Iterator > > array_field
Definition: array.hpp:117