OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
column_def.hpp
Go to the documentation of this file.
1//
2// Struct column
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 COLUMN_DEF_HPP_
18#define COLUMN_DEF_HPP_
19
20#include "column.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 column_parser<Iterator>::column_parser(error_handler<Iterator> & _error_handler):
32 column_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::long_type long_;
47 qi::lit_type lit;
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 %= char_('1') | lexeme[alpha >> *(alpha | char_('/'))];
58
59 datatype.add
60 ("float", ast::FLOAT)
61 ("double", ast::DOUBLE)
62 ("short", ast::SHORT)
63 ("long", ast::LONG)
64 ("character", ast::CHARACTER)
65 ("string", ast::STRING)
66 ;
67
68 column_name = lit("name") > '=' > string;
69 column_units %= lit("units") > '=' > units;
70 column_description %= lit("description") > '=' > string;
71 column_type %= lit("type") > '=' > datatype;
72 column_symbol = lit("symbol") > '=' > string;
73 column_format = lit("format_string") > '=' > string;
74 column_field = lit("field_length") > '=' > long_;
75
76 auto complainSymbol = phx::bind(&column::complainUnsupported<column::SYMBOL>::apply);
77 auto complainFormat = phx::bind(&column::complainUnsupported<column::FORMAT_STRING>::apply);
78 auto complainField = phx::bind(&column::complainUnsupported<column::FIELD_LENGTH>::apply);
79
80 column_unsupported_pre =
81 ((',' > column_symbol[_pass = complainSymbol])
82 ^ (',' > column_format[_pass = complainFormat])
83 ^ (',' > column_field[_pass = complainField])
84 );
85 column_unsupported_post =
86 ((column_symbol[_pass = complainSymbol] > ',')
87 ^ (column_format[_pass = complainFormat] > ',')
88 ^ (column_field[_pass = complainField] > ',')
89 );
90
91 start =
92 lit("&column")
93 > -column_unsupported_post
94 >> ((column_name[phx::at_c<0>(_val) = _1]
95 >> ((',' >> column_type[phx::at_c<1>(_val) = _1])
96 ^(',' >> column_units[phx::at_c<2>(_val) = _1])
97 ^(',' >> column_description[phx::at_c<3>(_val) = _1])
98 ))
99 |(column_type[phx::at_c<1>(_val) = _1]
100 >> ((',' >> column_name[phx::at_c<0>(_val) = _1])
101 ^(',' >> column_units[phx::at_c<2>(_val) = _1])
102 ^(',' >> column_description[phx::at_c<3>(_val) = _1])
103 ))
104 |(column_units[phx::at_c<2>(_val) = _1]
105 >> ((',' >> column_type[phx::at_c<1>(_val) = _1])
106 ^(',' >> column_name[phx::at_c<0>(_val) = _1])
107 ^(',' >> column_description[phx::at_c<3>(_val) = _1])
108 ))
109 |(column_description[phx::at_c<3>(_val) = _1]
110 >> ((',' >> column_type[phx::at_c<1>(_val) = _1])
111 ^(',' >> column_units[phx::at_c<2>(_val) = _1])
112 ^(',' >> column_name[phx::at_c<0>(_val) = _1])
113 ))
114 )
115 > -column_unsupported_pre
116 > lit("&end")
117 >> eps[_pass = phx::bind(&column::checkMandatories, _val)];
118
119 BOOST_SPIRIT_DEBUG_NODES(
120 (start)
121 )
122
123 on_error<fail>(start,
124 error_handler_function(_error_handler)(
125 std::string("Error! Expecting "), _4, _3));
126
127 }
128}}
129#endif /* COLUMN_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