#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