Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/ |
| 3 | * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/ |
| 4 | * |
| 5 | * Written by Václav Kubernát <kubervac@fit.cvut.cz> |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | #pragma once |
| 10 | |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 11 | #include "ast_commands.hpp" |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 12 | #include "ast_handlers.hpp" |
| 13 | |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 14 | |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 15 | x3::rule<keyValue_class, keyValue_> const keyValue = "keyValue"; |
| 16 | x3::rule<identifier_class, std::string> const identifier = "identifier"; |
| 17 | x3::rule<listPrefix_class, std::string> const listPrefix = "listPrefix"; |
| 18 | x3::rule<listSuffix_class, std::vector<keyValue_>> const listSuffix = "listSuffix"; |
| 19 | x3::rule<listElement_class, listElement_> const listElement = "listElement"; |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 20 | x3::rule<nodeup_class, nodeup_> const nodeup = "nodeup"; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 21 | x3::rule<container_class, container_> const container = "container"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 22 | x3::rule<leaf_class, leaf_> const leaf = "leaf"; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 23 | x3::rule<path_class, path_> const path = "path"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 24 | x3::rule<data_string_class, std::string> const data_string = "data_string"; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 25 | x3::rule<cd_class, cd_> const cd = "cd"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 26 | x3::rule<set_class, set_> const set = "set"; |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 27 | x3::rule<create_class, create_> const create = "create"; |
| 28 | x3::rule<delete_class, delete_> const delete_rule = "delete_rule"; |
| 29 | x3::rule<command_class, command_> const command = "command"; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 30 | |
Václav Kubernát | 4137845 | 2018-06-06 16:29:40 +0200 | [diff] [blame^] | 31 | #if __clang__ |
| 32 | #pragma GCC diagnostic push |
| 33 | #pragma GCC diagnostic ignored "-Woverloaded-shift-op-parentheses" |
| 34 | #endif |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 35 | |
| 36 | auto const keyValue_def = |
Václav Kubernát | 4137845 | 2018-06-06 16:29:40 +0200 | [diff] [blame^] | 37 | lexeme[+alnum > '=' > +alnum]; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 38 | |
| 39 | auto const identifier_def = |
| 40 | lexeme[ |
| 41 | ((alpha | char_("_")) >> *(alnum | char_("_") | char_("-") | char_("."))) |
| 42 | ]; |
| 43 | |
| 44 | auto const listPrefix_def = |
| 45 | identifier >> '['; |
| 46 | |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 47 | // even though we don't allow no keys to be supplied, the star allows me to check which keys are missing |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 48 | auto const listSuffix_def = |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 49 | *keyValue > ']'; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 50 | |
| 51 | auto const listElement_def = |
| 52 | listPrefix > listSuffix; |
| 53 | |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 54 | auto const nodeup_def = |
| 55 | lit("..") > x3::attr(nodeup_()); |
| 56 | |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 57 | auto const container_def = |
| 58 | identifier; |
| 59 | |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 60 | auto const leaf_def = |
| 61 | identifier; |
| 62 | |
| 63 | // leaf cannot be in the middle of a path, however, I need the grammar's attribute to be a vector of variants |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 64 | auto const path_def = |
Václav Kubernát | 4137845 | 2018-06-06 16:29:40 +0200 | [diff] [blame^] | 65 | (x3::expect[container | listElement | nodeup | leaf]) % '/'; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 66 | |
| 67 | auto const data_string_def = |
| 68 | lexeme[+char_]; |
| 69 | |
| 70 | auto const space_separator = |
| 71 | x3::omit[x3::no_skip[space]]; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 72 | |
| 73 | auto const cd_def = |
Václav Kubernát | 4137845 | 2018-06-06 16:29:40 +0200 | [diff] [blame^] | 74 | lit("cd") >> space_separator > path; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 75 | |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 76 | auto const create_def = |
Václav Kubernát | 4137845 | 2018-06-06 16:29:40 +0200 | [diff] [blame^] | 77 | lit("create") >> space_separator > path; |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 78 | |
| 79 | auto const delete_rule_def = |
Václav Kubernát | 4137845 | 2018-06-06 16:29:40 +0200 | [diff] [blame^] | 80 | lit("delete") >> space_separator > path; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 81 | |
| 82 | auto const set_def = |
Václav Kubernát | 4137845 | 2018-06-06 16:29:40 +0200 | [diff] [blame^] | 83 | lit("set") >> space_separator > path > data_string; |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 84 | |
| 85 | auto const command_def = |
Václav Kubernát | 4137845 | 2018-06-06 16:29:40 +0200 | [diff] [blame^] | 86 | x3::expect[cd | create | delete_rule | set] >> x3::eoi; |
| 87 | |
| 88 | #if __clang__ |
| 89 | #pragma GCC diagnostic pop |
| 90 | #endif |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 91 | |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 92 | BOOST_SPIRIT_DEFINE(keyValue) |
| 93 | BOOST_SPIRIT_DEFINE(identifier) |
| 94 | BOOST_SPIRIT_DEFINE(listPrefix) |
| 95 | BOOST_SPIRIT_DEFINE(listSuffix) |
| 96 | BOOST_SPIRIT_DEFINE(listElement) |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 97 | BOOST_SPIRIT_DEFINE(nodeup) |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 98 | BOOST_SPIRIT_DEFINE(container) |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 99 | BOOST_SPIRIT_DEFINE(leaf) |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 100 | BOOST_SPIRIT_DEFINE(path) |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 101 | BOOST_SPIRIT_DEFINE(data_string) |
| 102 | BOOST_SPIRIT_DEFINE(set) |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 103 | BOOST_SPIRIT_DEFINE(cd) |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 104 | BOOST_SPIRIT_DEFINE(create) |
| 105 | BOOST_SPIRIT_DEFINE(delete_rule) |
| 106 | BOOST_SPIRIT_DEFINE(command) |