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