blob: 30f69f1a94fd1495ed3d88e613a93af8341da274 [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
Václav Kubernát60d6f292018-05-25 09:45:32 +020014
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020015x3::rule<keyValue_class, keyValue_> const keyValue = "keyValue";
16x3::rule<identifier_class, std::string> const identifier = "identifier";
17x3::rule<listPrefix_class, std::string> const listPrefix = "listPrefix";
18x3::rule<listSuffix_class, std::vector<keyValue_>> const listSuffix = "listSuffix";
19x3::rule<listElement_class, listElement_> const listElement = "listElement";
Václav Kubernát60d6f292018-05-25 09:45:32 +020020x3::rule<nodeup_class, nodeup_> const nodeup = "nodeup";
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020021x3::rule<container_class, container_> const container = "container";
22x3::rule<path_class, path_> const path = "path";
23x3::rule<cd_class, cd_> const cd = "cd";
Václav Kubernátb61336d2018-05-28 17:35:03 +020024x3::rule<create_class, create_> const create = "create";
25x3::rule<delete_class, delete_> const delete_rule = "delete_rule";
26x3::rule<command_class, command_> const command = "command";
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020027
28
29auto const keyValue_def =
30 lexeme[+alnum >> '=' >> +alnum];
31
32auto const identifier_def =
33 lexeme[
34 ((alpha | char_("_")) >> *(alnum | char_("_") | char_("-") | char_(".")))
35 ];
36
37auto const listPrefix_def =
38 identifier >> '[';
39
Václav Kubernát7e4e82f2018-05-14 20:04:58 +020040// 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 +020041auto const listSuffix_def =
Václav Kubernát7e4e82f2018-05-14 20:04:58 +020042 *keyValue > ']';
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020043
44auto const listElement_def =
45 listPrefix > listSuffix;
46
Václav Kubernát60d6f292018-05-25 09:45:32 +020047auto const nodeup_def =
48 lit("..") > x3::attr(nodeup_());
49
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020050auto const container_def =
51 identifier;
52
53auto const path_def =
Václav Kubernát60d6f292018-05-25 09:45:32 +020054 (container | listElement | nodeup) % '/';
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020055
56auto const cd_def =
Václav Kubernát60d6f292018-05-25 09:45:32 +020057 lit("cd") > x3::omit[x3::no_skip[space]] > path >> x3::eoi;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020058
Václav Kubernátb61336d2018-05-28 17:35:03 +020059auto const create_def =
60 lit("create") > x3::omit[x3::no_skip[space]] > path >> x3::eoi;
61
62auto const delete_rule_def =
63 lit("delete") > x3::omit[x3::no_skip[space]] > path >> x3::eoi;
64
65auto const command_def =
66 cd | create | delete_rule;
67
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020068BOOST_SPIRIT_DEFINE(keyValue)
69BOOST_SPIRIT_DEFINE(identifier)
70BOOST_SPIRIT_DEFINE(listPrefix)
71BOOST_SPIRIT_DEFINE(listSuffix)
72BOOST_SPIRIT_DEFINE(listElement)
Václav Kubernát60d6f292018-05-25 09:45:32 +020073BOOST_SPIRIT_DEFINE(nodeup)
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020074BOOST_SPIRIT_DEFINE(container)
75BOOST_SPIRIT_DEFINE(path)
76BOOST_SPIRIT_DEFINE(cd)
Václav Kubernátb61336d2018-05-28 17:35:03 +020077BOOST_SPIRIT_DEFINE(create)
78BOOST_SPIRIT_DEFINE(delete_rule)
79BOOST_SPIRIT_DEFINE(command)