summaryrefslogtreecommitdiff
path: root/src/lib/eolian_cxx/grammar/context.hpp
blob: 9b5e16447047983e7d154aca1d476d6133030edf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef EOLIAN_CXX_CONTEXT_HH
#define EOLIAN_CXX_CONTEXT_HH

namespace efl { namespace eolian { namespace grammar {

struct context_null {};

template <typename Tag, typename Tail =  context_null>
struct context_cons
{
  Tag tag;
  Tail const& tail;
};
      
template <typename Tag>
struct context_cons<Tag, context_null>
{
  Tag tag;
  context_null tail;
};

template <typename NewTag, typename Tag, typename Tail>
context_cons<NewTag, context_cons<Tag, Tail>>
context_add_tag(NewTag tag, context_cons<Tag, Tail> const& context)
{
  return context_cons<NewTag, context_cons<Tag, Tail>>{tag, context};
}
template <typename NewTag>
context_cons<NewTag, context_null>
context_add_tag(NewTag tag, context_null context)
{
  return context_cons<NewTag, context_null>{tag, context};
}

template <typename Tag, typename Context>
struct tag_check;
template <typename Tag, typename Tail>
struct tag_check<Tag, context_cons<Tag, Tail>> : std::true_type {};
template <typename Tag>
struct tag_check<Tag, context_null> : std::false_type {};
template <typename Tag, typename OtherTag, typename Context>
struct tag_check<Tag, context_cons<OtherTag, Context>> : tag_check<Tag, Context> {};
      
} } }

#endif