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 | |
| 14 | x3::rule<keyValue_class, keyValue_> const keyValue = "keyValue"; |
| 15 | x3::rule<identifier_class, std::string> const identifier = "identifier"; |
| 16 | x3::rule<listPrefix_class, std::string> const listPrefix = "listPrefix"; |
| 17 | x3::rule<listSuffix_class, std::vector<keyValue_>> const listSuffix = "listSuffix"; |
| 18 | x3::rule<listElement_class, listElement_> const listElement = "listElement"; |
| 19 | x3::rule<container_class, container_> const container = "container"; |
| 20 | x3::rule<path_class, path_> const path = "path"; |
| 21 | x3::rule<cd_class, cd_> const cd = "cd"; |
| 22 | |
| 23 | |
| 24 | auto const keyValue_def = |
| 25 | lexeme[+alnum >> '=' >> +alnum]; |
| 26 | |
| 27 | auto const identifier_def = |
| 28 | lexeme[ |
| 29 | ((alpha | char_("_")) >> *(alnum | char_("_") | char_("-") | char_("."))) |
| 30 | ]; |
| 31 | |
| 32 | auto const listPrefix_def = |
| 33 | identifier >> '['; |
| 34 | |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 35 | // 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] | 36 | auto const listSuffix_def = |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 37 | *keyValue > ']'; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 38 | |
| 39 | auto const listElement_def = |
| 40 | listPrefix > listSuffix; |
| 41 | |
| 42 | auto const container_def = |
| 43 | identifier; |
| 44 | |
| 45 | auto const path_def = |
| 46 | (container | listElement) % '/'; |
| 47 | |
| 48 | auto const cd_def = |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 49 | 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] | 50 | |
| 51 | BOOST_SPIRIT_DEFINE(keyValue) |
| 52 | BOOST_SPIRIT_DEFINE(identifier) |
| 53 | BOOST_SPIRIT_DEFINE(listPrefix) |
| 54 | BOOST_SPIRIT_DEFINE(listSuffix) |
| 55 | BOOST_SPIRIT_DEFINE(listElement) |
| 56 | BOOST_SPIRIT_DEFINE(container) |
| 57 | BOOST_SPIRIT_DEFINE(path) |
| 58 | BOOST_SPIRIT_DEFINE(cd) |