OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
description_def.hpp
Go to the documentation of this file.
1 //
2 // Struct description
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 DESCRIPTION_DEF_HPP_
18 #define DESCRIPTION_DEF_HPP_
19 
20 #include "description.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>
30  description_parser<Iterator>::description_parser(error_handler<Iterator> & _error_handler):
31  description_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::lit_type lit;
43  qi::char_type char_;
44  qi::_val_type _val;
45 
46  quoted_string %= lexeme['"' >> +(char_ - '"') >> '"'];
47  description_text = lit("text") > '=' > quoted_string;
48  description_content = lit("contents") > '=' > quoted_string;
49 
50  start =
51  lit("&description")
52  > ((description_text[phx::at_c<0>(_val) = _1]
53  > -(',' > description_content[phx::at_c<1>(_val) = _1]))
54  |(description_content[phx::at_c<1>(_val) = _1]
55  > -(',' > description_text[phx::at_c<0>(_val) = _1])))
56  > lit("&end");
57 
58  BOOST_SPIRIT_DEBUG_NODES(
59  (start)
60  )
61 
62  on_error<fail>(start,
63  error_handler_function(_error_handler)(
64  std::string("Error! Expecting "), _4, _3));
65  }
66 }}
67 #endif /* DESCRIPTION_DEF_HPP_ */
Definition: array.hpp:33