7#include <boost/spirit/home/x3.hpp>
24 namespace x3 = boost::spirit::x3;
27 using x3::uint_parser;
28 using boost::fusion::at_c;
31 const auto ipv6 = x3::rule<Ipv6Tag, Ipv6>{
"ipv6"};
35 const auto h16 = x3::rule<H16Tag, uint16_t>{
"h16"} = uint_parser<uint16_t, 16, 1, 4>{} -
ipv4;
38 const auto ls32 = x3::rule<Ls32Tag, Ipv6SegmentContainer>{
"ls32"} =
40 _val(ctx).segmentsAfter = _attr(ctx).toIpv6Segments();
41 _val(ctx).endsWithIpv4 =
true;
43 (
h16 >>
':' >>
h16)[([](
auto& ctx) {
44 _val(ctx).segmentsAfter.push_back(at_c<0>(_attr(ctx)));
45 _val(ctx).segmentsAfter.push_back(at_c<1>(_attr(ctx)));
46 _val(ctx).endsWithIpv4 =
false;
50 _val(ctx).segmentsBefore = _attr(ctx);
53 _val(ctx).segmentsAfter = _attr(ctx);
57 _val(ctx).endsWithIpv4 = _attr(ctx).endsWithIpv4;
60 _val(ctx).segmentsBefore.push_back(_attr(ctx));
63 _val(ctx).segmentsAfter.push_back(_attr(ctx));
65 struct Ipv6IntermediateTag;
79#define MAKE_BEFORE_ABBREVIATION_RULE(count) \
80 struct BeforeAbbreviation##count##Tag; \
81 const auto beforeAbbreviation##count = \
82 x3::rule<BeforeAbbreviation##count##Tag, Ipv6SegmentContainer>{"beforeAbbreviation" #count} = \
83 beforeAbbreviationParser(count);
94#define MAKE_ABBREVIATION_RULE(count) \
95 struct Abbreviation##count##Tag; \
96 const auto abbreviation##count = x3::rule<Abbreviation##count##Tag, Ipv6SegmentContainer>{"abbreviation" #count} = \
97 abbreviationParser(count);
110 _val(ctx).segmentsBefore = _attr(ctx).segmentsBefore;
114 _val(ctx).endsWithIpv4 = _attr(ctx).endsWithIpv4;
116 const auto ipv6Intermediate = x3::rule<Ipv6IntermediateTag, Ipv6SegmentContainer>{
"ipv6Intermediate"} =
129 auto const& segmentsBefore = _attr(ctx).segmentsBefore;
130 auto const& segmentsAfter = _attr(ctx).segmentsAfter;
133 if (segmentsBefore.size() + segmentsAfter.size() > segments.size())
139 for (std::size_t i = 0; i != segmentsBefore.size(); ++i)
140 segments[i] = segmentsBefore[i];
141 for (std::size_t i = 0; i != segmentsAfter.size(); ++i)
142 segments[i + segments.size() - segmentsAfter.size()] = segmentsAfter[i];
146 .endsWithIpv4 = _attr(ctx).endsWithIpv4,
const auto afterAbbreviationParser
Definition ipv6.hpp:70
const auto abbreviationAction
Definition ipv6.hpp:112
const auto abbreviationParser
Definition ipv6.hpp:75
const auto ipv6Intermediate
Definition ipv6.hpp:116
const auto h16
Definition ipv6.hpp:35
const auto repeatedSegmentSectionActionAfter
Definition ipv6.hpp:52
const auto ipv4
Definition ipv4.hpp:12
const auto beforeAbbreviationAction
Definition ipv6.hpp:109
const auto ipv6
Definition ipv6.hpp:31
const auto ls32
Definition ipv6.hpp:38
const auto h16ActionBefore
Definition ipv6.hpp:59
const auto repeatedSegmentSectionActionBefore
Definition ipv6.hpp:49
const auto h16ActionAfter
Definition ipv6.hpp:62
const auto beforeAbbreviationParser
Definition ipv6.hpp:67
BOOST_SPIRIT_DEFINE(ipv4)
const auto ipv6_def
Definition ipv6.hpp:127
const auto ls32Action
Definition ipv6.hpp:55
void concatContainers(ContainerType< ElementType > &lhs, ContainerType< ElementType > const &rhs)
Definition concat_containers.hpp:8
#define MAKE_BEFORE_ABBREVIATION_RULE(count)
Definition ipv6.hpp:79
#define MAKE_ABBREVIATION_RULE(count)
Definition ipv6.hpp:94
std::array< uint16_t, 8 > segments
Definition ipv6.hpp:13
std::vector< uint16_t > segmentsAfter
Definition ipv6.hpp:15
std::vector< uint16_t > segmentsBefore
Definition ipv6.hpp:14
bool endsWithIpv4
Definition ipv6.hpp:16