Václav Kubernát | 8cd6342 | 2018-03-19 17:10:13 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/ |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 3 | * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/ |
Václav Kubernát | 8cd6342 | 2018-03-19 17:10:13 +0100 | [diff] [blame] | 4 | * |
| 5 | * Written by Václav Kubernát <kubervac@fit.cvut.cz> |
| 6 | * |
| 7 | */ |
| 8 | #pragma once |
| 9 | #include <boost/spirit/home/x3.hpp> |
Václav Kubernát | 8cd6342 | 2018-03-19 17:10:13 +0100 | [diff] [blame] | 10 | #include <boost/spirit/home/x3/support/ast/position_tagged.hpp> |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 11 | #include <boost/spirit/home/x3/support/utility/error_reporting.hpp> |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 12 | |
Václav Kubernát | 8cd6342 | 2018-03-19 17:10:13 +0100 | [diff] [blame] | 13 | #include <boost/fusion/adapted/struct/adapt_struct.hpp> |
| 14 | #include <boost/fusion/include/adapt_struct.hpp> |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 15 | #include <boost/fusion/include/std_pair.hpp> |
| 16 | #include <boost/variant.hpp> |
| 17 | #include <map> |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 18 | #include <vector> |
| 19 | |
Václav Kubernát | 94938b7 | 2018-05-04 15:12:24 +0200 | [diff] [blame] | 20 | #include "utils.hpp" |
Václav Kubernát | 8cd6342 | 2018-03-19 17:10:13 +0100 | [diff] [blame] | 21 | namespace x3 = boost::spirit::x3; |
| 22 | namespace ascii = boost::spirit::x3::ascii; |
| 23 | |
| 24 | using x3::alpha; |
| 25 | using x3::alnum; |
| 26 | using x3::lit; |
| 27 | using x3::char_; |
| 28 | using x3::_attr; |
| 29 | using x3::lexeme; |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 30 | using x3::expect; |
Václav Kubernát | 8cd6342 | 2018-03-19 17:10:13 +0100 | [diff] [blame] | 31 | using ascii::space; |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 32 | using boost::fusion::operator<<; |
| 33 | |
| 34 | |
| 35 | using keyValue_ = std::pair<std::string, std::string>; |
| 36 | |
Václav Kubernát | 8cd6342 | 2018-03-19 17:10:13 +0100 | [diff] [blame] | 37 | |
| 38 | struct parser_context_tag; |
| 39 | |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 40 | struct container_ { |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 41 | container_() = default; |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 42 | container_(const std::string& name); |
| 43 | |
| 44 | bool operator==(const container_& b) const; |
| 45 | |
Václav Kubernát | 8cd6342 | 2018-03-19 17:10:13 +0100 | [diff] [blame] | 46 | std::string m_name; |
| 47 | }; |
| 48 | |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 49 | |
| 50 | struct list_ { |
| 51 | std::vector<std::string> m_keys; |
| 52 | }; |
| 53 | |
| 54 | struct listElement_ { |
| 55 | listElement_() {} |
| 56 | listElement_(const std::string& listName, const std::map<std::string, std::string>& keys); |
| 57 | |
| 58 | bool operator==(const listElement_& b) const; |
| 59 | |
| 60 | std::string m_listName; |
| 61 | std::map<std::string, std::string> m_keys; |
| 62 | }; |
| 63 | |
Václav Kubernát | 8cd6342 | 2018-03-19 17:10:13 +0100 | [diff] [blame] | 64 | |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 65 | struct path_ { |
| 66 | bool operator==(const path_& b) const; |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 67 | std::vector<boost::variant<container_, listElement_>> m_nodes; |
Václav Kubernát | 8cd6342 | 2018-03-19 17:10:13 +0100 | [diff] [blame] | 68 | }; |
| 69 | |
Václav Kubernát | 8cd6342 | 2018-03-19 17:10:13 +0100 | [diff] [blame] | 70 | |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 71 | struct cd_ : x3::position_tagged { |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 72 | bool operator==(const cd_& b) const; |
Václav Kubernát | 8cd6342 | 2018-03-19 17:10:13 +0100 | [diff] [blame] | 73 | path_ m_path; |
| 74 | }; |
| 75 | |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame^] | 76 | |
| 77 | |
| 78 | BOOST_FUSION_ADAPT_STRUCT(container_, m_name) |
| 79 | BOOST_FUSION_ADAPT_STRUCT(listElement_, m_listName, m_keys) |
| 80 | BOOST_FUSION_ADAPT_STRUCT(path_, m_nodes) |
Václav Kubernát | 8cd6342 | 2018-03-19 17:10:13 +0100 | [diff] [blame] | 81 | BOOST_FUSION_ADAPT_STRUCT(cd_, m_path) |