blob: c6f3ab5cd5af444585935e6f8287f1b153a070b0 [file] [log] [blame]
Václav Kubernát0a2a2e82018-05-11 13:59:12 +02001/*
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
14x3::rule<keyValue_class, keyValue_> const keyValue = "keyValue";
15x3::rule<identifier_class, std::string> const identifier = "identifier";
16x3::rule<listPrefix_class, std::string> const listPrefix = "listPrefix";
17x3::rule<listSuffix_class, std::vector<keyValue_>> const listSuffix = "listSuffix";
18x3::rule<listElement_class, listElement_> const listElement = "listElement";
19x3::rule<container_class, container_> const container = "container";
20x3::rule<path_class, path_> const path = "path";
21x3::rule<cd_class, cd_> const cd = "cd";
22
23
24auto const keyValue_def =
25 lexeme[+alnum >> '=' >> +alnum];
26
27auto const identifier_def =
28 lexeme[
29 ((alpha | char_("_")) >> *(alnum | char_("_") | char_("-") | char_(".")))
30 ];
31
32auto const listPrefix_def =
33 identifier >> '[';
34
Václav Kubernát7e4e82f2018-05-14 20:04:58 +020035// even though we don't allow no keys to be supplied, the star allows me to check which keys are missing
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020036auto const listSuffix_def =
Václav Kubernát7e4e82f2018-05-14 20:04:58 +020037 *keyValue > ']';
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020038
39auto const listElement_def =
40 listPrefix > listSuffix;
41
42auto const container_def =
43 identifier;
44
45auto const path_def =
46 (container | listElement) % '/';
47
48auto const cd_def =
Václav Kubernát7e4e82f2018-05-14 20:04:58 +020049 lit("cd") > x3::omit[x3::no_skip[space]] > path >> x3::eoi;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020050
51BOOST_SPIRIT_DEFINE(keyValue)
52BOOST_SPIRIT_DEFINE(identifier)
53BOOST_SPIRIT_DEFINE(listPrefix)
54BOOST_SPIRIT_DEFINE(listSuffix)
55BOOST_SPIRIT_DEFINE(listElement)
56BOOST_SPIRIT_DEFINE(container)
57BOOST_SPIRIT_DEFINE(path)
58BOOST_SPIRIT_DEFINE(cd)