blob: cdff9f5bdc6da04a777b03408285d67faee4c6f0 [file] [log] [blame]
Václav Kubernát9ae8cc42020-03-25 19:17:41 +01001/*
2 * Copyright (C) 2020 CESNET, https://photonics.cesnet.cz/
3 *
4 * Written by Václav Kubernát <kubernat@cesnet.cz>
5 *
6*/
7
8#pragma once
9
10#include <boost/spirit/home/x3.hpp>
11#include "ast_values.hpp"
12#include "ast_handlers.hpp"
13#include "common_parsers.hpp"
14#include "schema.hpp"
15namespace x3 = boost::spirit::x3;
16
17using x3::char_;
18using x3::double_;
19using x3::int8;
20using x3::int16;
21using x3::int32;
22using x3::int64;
23using x3::uint8;
24using x3::uint16;
25using x3::uint32;
26using x3::uint64;
27
28x3::rule<leaf_data_class, leaf_data_> const leaf_data = "leaf_data";
29x3::rule<leaf_data_enum_class, enum_> const leaf_data_enum = "leaf_data_enum";
30x3::rule<leaf_data_base_class<yang::LeafDataTypes::Decimal>, double> const leaf_data_decimal = "leaf_data_decimal";
31x3::rule<leaf_data_base_class<yang::LeafDataTypes::Bool>, bool> const leaf_data_bool = "leaf_data_bool";
32x3::rule<leaf_data_base_class<yang::LeafDataTypes::Int8>, int8_t> const leaf_data_int8 = "leaf_data_int8";
33x3::rule<leaf_data_base_class<yang::LeafDataTypes::Uint8>, uint8_t> const leaf_data_uint8 = "leaf_data_uint8";
34x3::rule<leaf_data_base_class<yang::LeafDataTypes::Int16>, int16_t> const leaf_data_int16 = "leaf_data_int16";
35x3::rule<leaf_data_base_class<yang::LeafDataTypes::Uint16>, uint16_t> const leaf_data_uint16 = "leaf_data_uint16";
36x3::rule<leaf_data_base_class<yang::LeafDataTypes::Int32>, int32_t> const leaf_data_int32 = "leaf_data_int32";
37x3::rule<leaf_data_base_class<yang::LeafDataTypes::Uint32>, uint32_t> const leaf_data_uint32 = "leaf_data_uint32";
38x3::rule<leaf_data_base_class<yang::LeafDataTypes::Int64>, int64_t> const leaf_data_int64 = "leaf_data_int64";
39x3::rule<leaf_data_base_class<yang::LeafDataTypes::Uint64>, uint64_t> const leaf_data_uint64 = "leaf_data_uint64";
40x3::rule<leaf_data_base_class<yang::LeafDataTypes::String>, std::string> const leaf_data_string = "leaf_data_string";
41x3::rule<leaf_data_binary_data_class, std::string> const leaf_data_binary_data = "leaf_data_binary_data";
42x3::rule<leaf_data_base_class<yang::LeafDataTypes::Binary>, binary_> const leaf_data_binary = "leaf_data_binary";
43x3::rule<leaf_data_identityRef_data_class, identityRef_> const leaf_data_identityRef_data = "leaf_data_identityRef_data";
44x3::rule<leaf_data_identityRef_class, identityRef_> const leaf_data_identityRef = "leaf_data_identityRef";
45
46x3::rule<createSetSuggestions_class<yang::LeafDataTypes::Enum>, x3::unused_type> const createEnumSuggestions = "createEnumSuggestions";
47x3::rule<createSetSuggestions_class<yang::LeafDataTypes::IdentityRef>, x3::unused_type> const createIdentitySuggestions = "createIdentitySuggestions";
48
49auto const createEnumSuggestions_def =
50 x3::eps;
51
52auto const leaf_data_enum_def =
53 createEnumSuggestions >> +char_;
54
55auto const leaf_data_decimal_def =
56 double_;
57
58struct bool_symbol_table : x3::symbols<bool> {
59 bool_symbol_table()
60 {
61 add
62 ("true", true)
63 ("false", false);
64 }
65} const bool_rule;
66
67auto const leaf_data_bool_def =
68 bool_rule;
69auto const leaf_data_int8_def =
70 int8;
71auto const leaf_data_int16_def =
72 int16;
73auto const leaf_data_int32_def =
74 int32;
75auto const leaf_data_int64_def =
76 int64;
77auto const leaf_data_uint8_def =
78 uint8;
79auto const leaf_data_uint16_def =
80 uint16;
81auto const leaf_data_uint32_def =
82 uint32;
83auto const leaf_data_uint64_def =
84 uint64;
85auto const leaf_data_string_def =
86 '\'' >> *(char_-'\'') >> '\'' |
87 '\"' >> *(char_-'\"') >> '\"';
88
89// This intermediate rule is neccessary for coercing to std::string.
90auto const leaf_data_binary_data_def =
91 +(x3::alnum | char_('+') | char_('/')) >> -char_('=') >> -char_('=');
92
93auto const leaf_data_binary_def =
94 leaf_data_binary_data;
95
96auto const leaf_data_identityRef_data_def =
97 -module >> node_identifier;
98
99auto const createIdentitySuggestions_def =
100 x3::eps;
101
102auto const leaf_data_identityRef_def =
103 createIdentitySuggestions >> leaf_data_identityRef_data;
104
105auto const leaf_data_def =
106x3::no_skip[x3::expect[
107 leaf_data_enum |
108 leaf_data_decimal |
109 leaf_data_bool |
110 leaf_data_int8 |
111 leaf_data_int16 |
112 leaf_data_int32 |
113 leaf_data_int64 |
114 leaf_data_uint8 |
115 leaf_data_uint16 |
116 leaf_data_uint32 |
117 leaf_data_uint64 |
118 leaf_data_binary |
119 leaf_data_identityRef |
120 leaf_data_string]];
121
122BOOST_SPIRIT_DEFINE(leaf_data)
123BOOST_SPIRIT_DEFINE(leaf_data_enum)
124BOOST_SPIRIT_DEFINE(leaf_data_decimal)
125BOOST_SPIRIT_DEFINE(leaf_data_bool)
126BOOST_SPIRIT_DEFINE(leaf_data_int8)
127BOOST_SPIRIT_DEFINE(leaf_data_int16)
128BOOST_SPIRIT_DEFINE(leaf_data_int32)
129BOOST_SPIRIT_DEFINE(leaf_data_int64)
130BOOST_SPIRIT_DEFINE(leaf_data_uint8)
131BOOST_SPIRIT_DEFINE(leaf_data_uint16)
132BOOST_SPIRIT_DEFINE(leaf_data_uint32)
133BOOST_SPIRIT_DEFINE(leaf_data_uint64)
134BOOST_SPIRIT_DEFINE(leaf_data_string)
135BOOST_SPIRIT_DEFINE(leaf_data_binary_data)
136BOOST_SPIRIT_DEFINE(leaf_data_binary)
137BOOST_SPIRIT_DEFINE(leaf_data_identityRef_data)
138BOOST_SPIRIT_DEFINE(leaf_data_identityRef)
139BOOST_SPIRIT_DEFINE(createEnumSuggestions)
140BOOST_SPIRIT_DEFINE(createIdentitySuggestions)