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 | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame^] | 40 | |
| 41 | struct nodeup_ { |
| 42 | bool operator==(const nodeup_&) const |
| 43 | { |
| 44 | return true; |
| 45 | } |
| 46 | }; |
| 47 | |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 48 | struct container_ { |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 49 | container_() = default; |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 50 | container_(const std::string& name); |
| 51 | |
| 52 | bool operator==(const container_& b) const; |
| 53 | |
Václav Kubernát | 8cd6342 | 2018-03-19 17:10:13 +0100 | [diff] [blame] | 54 | std::string m_name; |
| 55 | }; |
| 56 | |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 57 | |
| 58 | struct list_ { |
| 59 | std::vector<std::string> m_keys; |
| 60 | }; |
| 61 | |
| 62 | struct listElement_ { |
| 63 | listElement_() {} |
| 64 | listElement_(const std::string& listName, const std::map<std::string, std::string>& keys); |
| 65 | |
| 66 | bool operator==(const listElement_& b) const; |
| 67 | |
Václav Kubernát | 0b76a04 | 2018-05-16 20:16:47 +0200 | [diff] [blame] | 68 | std::string m_name; |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 69 | std::map<std::string, std::string> m_keys; |
| 70 | }; |
| 71 | |
Václav Kubernát | 8cd6342 | 2018-03-19 17:10:13 +0100 | [diff] [blame] | 72 | |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 73 | struct path_ { |
| 74 | bool operator==(const path_& b) const; |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame^] | 75 | std::vector<boost::variant<container_, listElement_, nodeup_>> m_nodes; |
Václav Kubernát | 8cd6342 | 2018-03-19 17:10:13 +0100 | [diff] [blame] | 76 | }; |
| 77 | |
Václav Kubernát | 8cd6342 | 2018-03-19 17:10:13 +0100 | [diff] [blame] | 78 | |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 79 | struct cd_ : x3::position_tagged { |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 80 | bool operator==(const cd_& b) const; |
Václav Kubernát | 8cd6342 | 2018-03-19 17:10:13 +0100 | [diff] [blame] | 81 | path_ m_path; |
| 82 | }; |
| 83 | |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 84 | BOOST_FUSION_ADAPT_STRUCT(container_, m_name) |
Václav Kubernát | 0b76a04 | 2018-05-16 20:16:47 +0200 | [diff] [blame] | 85 | BOOST_FUSION_ADAPT_STRUCT(listElement_, m_name, m_keys) |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 86 | BOOST_FUSION_ADAPT_STRUCT(path_, m_nodes) |
Václav Kubernát | 8cd6342 | 2018-03-19 17:10:13 +0100 | [diff] [blame] | 87 | BOOST_FUSION_ADAPT_STRUCT(cd_, m_path) |