blob: ef6b60ff74921ce82a7fafbc38fdc9defc13b225 [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";
24
25
26auto const keyValue_def =
27 lexeme[+alnum >> '=' >> +alnum];
28
29auto const identifier_def =
30 lexeme[
31 ((alpha | char_("_")) >> *(alnum | char_("_") | char_("-") | char_(".")))
32 ];
33
34auto const listPrefix_def =
35 identifier >> '[';
36
Václav Kubernát7e4e82f2018-05-14 20:04:58 +020037// 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 +020038auto const listSuffix_def =
Václav Kubernát7e4e82f2018-05-14 20:04:58 +020039 *keyValue > ']';
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020040
41auto const listElement_def =
42 listPrefix > listSuffix;
43
Václav Kubernát60d6f292018-05-25 09:45:32 +020044auto const nodeup_def =
45 lit("..") > x3::attr(nodeup_());
46
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020047auto const container_def =
48 identifier;
49
50auto const path_def =
Václav Kubernát60d6f292018-05-25 09:45:32 +020051 (container | listElement | nodeup) % '/';
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020052
53auto const cd_def =
Václav Kubernát60d6f292018-05-25 09:45:32 +020054 lit("cd") > x3::omit[x3::no_skip[space]] > path >> x3::eoi;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020055
56BOOST_SPIRIT_DEFINE(keyValue)
57BOOST_SPIRIT_DEFINE(identifier)
58BOOST_SPIRIT_DEFINE(listPrefix)
59BOOST_SPIRIT_DEFINE(listSuffix)
60BOOST_SPIRIT_DEFINE(listElement)
Václav Kubernát60d6f292018-05-25 09:45:32 +020061BOOST_SPIRIT_DEFINE(nodeup)
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020062BOOST_SPIRIT_DEFINE(container)
63BOOST_SPIRIT_DEFINE(path)
64BOOST_SPIRIT_DEFINE(cd)