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 | |
| 11 | #include "ast.hpp" |
| 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"; |
| 22 | x3::rule<path_class, path_> const path = "path"; |
| 23 | x3::rule<cd_class, cd_> const cd = "cd"; |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame^] | 24 | x3::rule<create_class, create_> const create = "create"; |
| 25 | x3::rule<delete_class, delete_> const delete_rule = "delete_rule"; |
| 26 | x3::rule<command_class, command_> const command = "command"; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 27 | |
| 28 | |
| 29 | auto const keyValue_def = |
| 30 | lexeme[+alnum >> '=' >> +alnum]; |
| 31 | |
| 32 | auto const identifier_def = |
| 33 | lexeme[ |
| 34 | ((alpha | char_("_")) >> *(alnum | char_("_") | char_("-") | char_("."))) |
| 35 | ]; |
| 36 | |
| 37 | auto const listPrefix_def = |
| 38 | identifier >> '['; |
| 39 | |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 40 | // 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] | 41 | auto const listSuffix_def = |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 42 | *keyValue > ']'; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 43 | |
| 44 | auto const listElement_def = |
| 45 | listPrefix > listSuffix; |
| 46 | |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 47 | auto const nodeup_def = |
| 48 | lit("..") > x3::attr(nodeup_()); |
| 49 | |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 50 | auto const container_def = |
| 51 | identifier; |
| 52 | |
| 53 | auto const path_def = |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 54 | (container | listElement | nodeup) % '/'; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 55 | |
| 56 | auto const cd_def = |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 57 | lit("cd") > x3::omit[x3::no_skip[space]] > path >> x3::eoi; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 58 | |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame^] | 59 | auto const create_def = |
| 60 | lit("create") > x3::omit[x3::no_skip[space]] > path >> x3::eoi; |
| 61 | |
| 62 | auto const delete_rule_def = |
| 63 | lit("delete") > x3::omit[x3::no_skip[space]] > path >> x3::eoi; |
| 64 | |
| 65 | auto const command_def = |
| 66 | cd | create | delete_rule; |
| 67 | |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 68 | BOOST_SPIRIT_DEFINE(keyValue) |
| 69 | BOOST_SPIRIT_DEFINE(identifier) |
| 70 | BOOST_SPIRIT_DEFINE(listPrefix) |
| 71 | BOOST_SPIRIT_DEFINE(listSuffix) |
| 72 | BOOST_SPIRIT_DEFINE(listElement) |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 73 | BOOST_SPIRIT_DEFINE(nodeup) |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 74 | BOOST_SPIRIT_DEFINE(container) |
| 75 | BOOST_SPIRIT_DEFINE(path) |
| 76 | BOOST_SPIRIT_DEFINE(cd) |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame^] | 77 | BOOST_SPIRIT_DEFINE(create) |
| 78 | BOOST_SPIRIT_DEFINE(delete_rule) |
| 79 | BOOST_SPIRIT_DEFINE(command) |