Menu

[94f52a]: / parser / tree_operators.hpp  Maximize  Restore  History

Download this file

107 lines (89 with data), 2.4 kB

  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
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
#ifndef CHILON_PARSER_TREE_OPERATORS_HPP
#define CHILON_PARSER_TREE_OPERATORS_HPP
#include <chilon/parser/char.hpp>
namespace chilon { namespace parser {
/**
* Denotes a binary operator.
* A binary operator can match many times and stores a vector
* e.g. 4 + 5 + 6 might store vector(4, 5, 6)
* \tparam C string of characters that form the operator.
*/
template <char... C>
struct binary_op {
typedef char_<C...> operator_parser;
};
/**
* Denotes a binary operator that can only match once.
* This is like binary_op but stores a tuple of arity two.
* e.g. 4 + 5 + 6 isn't permitted, only 4 + 5.
* \tparam C string of characters that form the operator.
*/
template <char... C>
struct singular_binary_op {
typedef char_<C...> operator_parser;
};
/**
* Denotes a prefix operator.
* \tparam C string of characters that form the operator.
*/
template <char... C>
struct prefix_op {
typedef char_<C...> operator_parser;
};
/**
* Denotes a suffix operator.
* \tparam C string of characters that form the operator.
*/
template <char... C>
struct suffix_op {
typedef char_<C...> operator_parser;
};
/**
* Denotes a stored binary tree.
* @tparam T type of tree node.
* @tparam C string of characters that form the operator.
*/
template <class T, char... C>
struct binary_tree {
binary_tree(T const& value) { value_.push_back(value); }
binary_tree() {}
std::vector<T> value_;
};
/**
* Denotes a prefixed tree entry.
* @tparam T type of tree node.
* @tparam C string of characters that form the prefix.
*/
template <class T, char... C>
struct prefixed {
prefixed(T const& value) : value_(value) {}
prefixed() {}
T value_;
};
/**
* Denotes a suffixed tree entry.
* \tparam T type of tree node.
* \tparam C string of characters that form the suffix.
*/
template <class T, char... C>
struct suffixed {
suffixed(T const& value) : value_(value) {}
suffixed() {}
T value_;
};
template <class T, class U>
struct make_tree_node;
template <class T, char... C>
struct make_tree_node<T, binary_op<C...> > {
typedef binary_tree<T, C...> type;
};
template <class T, char... C>
struct make_tree_node<T, suffix_op<C...> > {
typedef suffixed<T, C...> type;
};
template <class T, char... C>
struct make_tree_node<T, prefix_op<C...> > {
typedef prefixed<T, C...> type;
};
} }
#endif
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.