blob: 6c60dc95fc24b827daa03348579198fde6518fd1 [file] [log] [blame]
Václav Kubernát8cd63422018-03-19 17:10:13 +01001/*
2 * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
3 *
4 * Written by Václav Kubernát <kubervac@fit.cvut.cz>
5 *
6*/
7#pragma once
8#include <boost/spirit/home/x3.hpp>
9#include <vector>
10#include <boost/spirit/home/x3/support/ast/position_tagged.hpp>
11#include <boost/fusion/adapted/struct/adapt_struct.hpp>
12#include <boost/fusion/include/adapt_struct.hpp>
13#include "CTree.hpp"
14namespace x3 = boost::spirit::x3;
15namespace ascii = boost::spirit::x3::ascii;
16
17using x3::alpha;
18using x3::alnum;
19using x3::lit;
20using x3::char_;
21using x3::_attr;
22using x3::lexeme;
23using ascii::space;
24
25using nodeString = std::string;
26
27struct ParserContext
28{
29 ParserContext(const CTree& tree);
30 const CTree& m_tree;
31 std::string m_currentContext;
32};
33
34struct parser_context_tag;
35
36struct container_
37{
38 char m_first;
39 std::string m_name;
40};
41
42BOOST_FUSION_ADAPT_STRUCT(container_, m_first, m_name)
43
44struct path_
45{
46 std::vector<container_> m_nodes;
47};
48
49BOOST_FUSION_ADAPT_STRUCT(path_, m_nodes)
50
51struct cd_
52{
53 path_ m_path;
54};
55
56BOOST_FUSION_ADAPT_STRUCT(cd_, m_path)
57
58
59struct container_class
60{
61 template <typename T, typename Iterator, typename Context>
62 inline void on_success(Iterator const& first, Iterator const& last
63 , T& ast, Context const& context);
64};
65
66struct path_class
67{
68 template <typename T, typename Iterator, typename Context>
69 inline void on_success(Iterator const& first, Iterator const& last
70 , T& ast, Context const& context);
71};
72
73struct cd_class
74{
75 template <typename T, typename Iterator, typename Context>
76 inline void on_success(Iterator const& first, Iterator const& last
77 , T& ast, Context const& context);
78
79};
80
81
82typedef x3::rule<container_class, container_> container_type;
83typedef x3::rule<path_class, path_> path_type;
84typedef x3::rule<cd_class, cd_> cd_type;
85
86container_type const container = "container";
87path_type const path = "path";
88cd_type const cd = "cd";
89
90
91auto const container_def =
92 lexeme[
93 ((alpha | x3::string("_")) >> *(alnum | x3::string("_") | x3::string("-") | x3::string(".")))
94 ];
95auto const path_def =
96 container % '/';
97
98auto const cd_def =
99 lit("cd") >> path >> x3::eoi;
100
101BOOST_SPIRIT_DEFINE(container)
102BOOST_SPIRIT_DEFINE(path)
103BOOST_SPIRIT_DEFINE(cd)