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"; |
| 24 | |
| 25 | |
| 26 | auto const keyValue_def = |
| 27 | lexeme[+alnum >> '=' >> +alnum]; |
| 28 | |
| 29 | auto const identifier_def = |
| 30 | lexeme[ |
| 31 | ((alpha | char_("_")) >> *(alnum | char_("_") | char_("-") | char_("."))) |
| 32 | ]; |
| 33 | |
| 34 | auto const listPrefix_def = |
| 35 | identifier >> '['; |
| 36 | |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 37 | // 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] | 38 | auto const listSuffix_def = |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 39 | *keyValue > ']'; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 40 | |
| 41 | auto const listElement_def = |
| 42 | listPrefix > listSuffix; |
| 43 | |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 44 | auto const nodeup_def = |
| 45 | lit("..") > x3::attr(nodeup_()); |
| 46 | |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 47 | auto const container_def = |
| 48 | identifier; |
| 49 | |
| 50 | auto const path_def = |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 51 | (container | listElement | nodeup) % '/'; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 52 | |
| 53 | auto const cd_def = |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 54 | 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] | 55 | |
| 56 | BOOST_SPIRIT_DEFINE(keyValue) |
| 57 | BOOST_SPIRIT_DEFINE(identifier) |
| 58 | BOOST_SPIRIT_DEFINE(listPrefix) |
| 59 | BOOST_SPIRIT_DEFINE(listSuffix) |
| 60 | BOOST_SPIRIT_DEFINE(listElement) |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 61 | BOOST_SPIRIT_DEFINE(nodeup) |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 62 | BOOST_SPIRIT_DEFINE(container) |
| 63 | BOOST_SPIRIT_DEFINE(path) |
| 64 | BOOST_SPIRIT_DEFINE(cd) |