summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/metaparse/example/meta_hs/bind.hpp
blob: 29316084a393adee29ce40b50b4d36dc72ece15f (plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef META_HS_BIND_HPP
#define META_HS_BIND_HPP

// Copyright Abel Sinkovics (abel@sinkovics.hu)  2012.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)

#include <lazy.hpp>
#include <ast.hpp>

#include <boost/mpl/at.hpp>
#include <boost/mpl/insert.hpp>
#include <boost/mpl/pair.hpp>

template <class AST, class TopEnv, class Env>
struct bind;

template <class V, class TopEnv, class Env>
struct bind<ast::value<V>, TopEnv, Env>
{
  typedef lazy::value<V> type;
};

template <class Name, class TopEnv, class Env>
struct bind<ast::ref<Name>, TopEnv, Env> :
  bind<typename boost::mpl::at<Env, Name>::type, TopEnv, Env>
{};

template <class F, class Arg, class TopEnv, class Env>
struct bind<ast::application<F, Arg>, TopEnv, Env> 
{
  typedef
    lazy::application<
      typename bind<F, TopEnv, Env>::type,
      typename bind<Arg, TopEnv, Env>::type
    >
    type;
};

template <class F, class ArgName, class TopEnv, class Env>
struct bind<ast::lambda<F, ArgName>, TopEnv, Env>
{
  typedef bind type;
  
  template <class ArgValue>
  struct apply :
    bind<
      F,
      TopEnv,
      typename boost::mpl::insert<
        Env,
        boost::mpl::pair<ArgName, ast::value<ArgValue> >
      >::type
    >::type
  {};
};

template <class E, class TopEnv, class Env>
struct bind<ast::top_bound<E>, TopEnv, Env> : bind<E, TopEnv, TopEnv> {};

#endif