MyLang
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
myparser_ast_plus.hpp
Go to the documentation of this file.
1 #ifndef MYPARSER_AST_PLUS_HPP
2 #define MYPARSER_AST_PLUS_HPP
3 
4 #include "myparser_ast.hpp"
5 
6 namespace myparser {
7 
8 template <size_t I>
9 class NodeSpace: public NodeListIndexed<I> {
10 public:
11  inline NodeSpace(const Input &input):
12  NodeListIndexed<I>(input) {}
13 
14  // virtual ~NodeSpace() {}
15 
16  virtual bool empty() const {
17  return true;
18  }
19 };
20 
21 template <class T, class E>
22 class NodeData: public NodeTextOrError<E> {
23 private:
24  const T *data;
25 
26 public:
27  inline NodeData(
28  const Input &input, std::string &&value
29  ): NodeTextOrError<E>(input, std::move(value)) {
30  std::istringstream conv(value);
31  data = new T;
32  if (conv >> *data && conv.eof()) {
33  // success
34  } else {
35  delete data;
36  data = nullptr;
37  }
38  }
39 
40  virtual ~NodeData() {
41  if (data) {
42  delete data;
43  }
44  }
45 
46  virtual bool accepted() const {
47  return data;
48  }
49 
50  inline const T &getData() {
51  return *data;
52  }
53 };
54 
55 /*
56 specialization example:
57 
58 template <size_t I>
59 class NodeTyped<BuiltinSpace, NodeListIndexed<I>>:
60 public NodeTypedProto<BuiltinSpace, NodeSpace<I>> {
61 public:
62  using NodeTypedProto<BuiltinSpace, NodeSpace<I>>::NodeTypedProto;
63 };
64 */
65 
66 }
67 
68 #endif
NodeSpace(const Input &input)
Definition: myparser_ast_plus.hpp:11
virtual bool accepted() const
Definition: myparser_ast_plus.hpp:46
Definition: myparser_ast.hpp:183
Definition: myparser_ast.hpp:137
NodeData(const Input &input, std::string &&value)
Definition: myparser_ast_plus.hpp:27
const T & getData()
Definition: myparser_ast_plus.hpp:50
virtual ~NodeData()
Definition: myparser_ast_plus.hpp:40
Definition: myparser_ast_plus.hpp:22
const T * data
Definition: myparser_ast_plus.hpp:24
virtual bool empty() const
Definition: myparser_ast_plus.hpp:16
std::string::const_iterator Input
Definition: myparser_ast.hpp:8
Definition: myparser_ast_plus.hpp:9