edn_turbo 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,7 @@
4
4
  #include <string>
5
5
  #include <sstream>
6
6
  #include <vector>
7
+ #include <stack>
7
8
 
8
9
  #include <ruby/ruby.h>
9
10
 
@@ -11,20 +12,28 @@
11
12
  namespace edn
12
13
  {
13
14
  extern VALUE rb_mEDNT;
14
- extern VALUE EDNT_MAKE_EDN_SYMBOL;
15
+ extern VALUE EDNT_MAKE_SYMBOL_METHOD;
16
+ extern VALUE EDNT_MAKE_LIST_METHOD;
15
17
  extern VALUE EDNT_MAKE_SET_METHOD;
16
- extern VALUE EDNT_TAGGED_ELEM;
17
- extern VALUE EDNT_BIND_META_TO_VALUE;
18
- extern VALUE EDNT_STR_INT_TO_BIGNUM;
19
- extern VALUE EDNT_STR_DBL_TO_BIGNUM;
20
- extern VALUE EDNT_EOF;
18
+ extern VALUE EDNT_MAKE_BIG_DECIMAL_METHOD;
19
+ extern VALUE EDNT_TAGGED_ELEM_METHOD;
20
+ extern VALUE EDNT_EXTENDED_VALUE_METHOD;
21
+
22
+ extern VALUE EDNT_STRING_TO_I_METHOD;
23
+ extern VALUE EDNT_STRING_TO_F_METHOD;
24
+
25
+ extern VALUE EDNT_EOF_CONST;
26
+
21
27
 
22
28
  //
23
29
  // C-extension EDN Parser class representation
24
30
  class Parser
25
31
  {
26
32
  public:
27
- Parser() : p(NULL), pe(NULL), eof(NULL), line_number(1) { }
33
+ Parser() : p(NULL), pe(NULL), eof(NULL), line_number(1) {
34
+ new_meta_list();
35
+ }
36
+ ~Parser() { reset_state(); del_top_meta_list(); }
28
37
 
29
38
  // change input source
30
39
  void set_source(const char* src, std::size_t len);
@@ -46,7 +55,7 @@ namespace edn
46
55
  const char* eof;
47
56
  std::size_t line_number;
48
57
  std::vector<VALUE> discard;
49
- std::vector<VALUE> metadata;
58
+ std::stack<std::vector<VALUE>* > metadata;
50
59
 
51
60
  void reset_state();
52
61
 
@@ -67,7 +76,9 @@ namespace edn
67
76
  const char* parse_tagged (const char *p, const char *pe, VALUE& v);
68
77
  const char* parse_meta (const char *p, const char *pe);
69
78
 
70
- bool parse_next(VALUE& value);
79
+ enum eTokenState { TOKEN_OK, TOKEN_ERROR, TOKEN_IS_DISCARD, TOKEN_IS_META };
80
+
81
+ eTokenState parse_next(VALUE& value);
71
82
 
72
83
  // defined in edn_parser_unicode.cc
73
84
  static bool to_utf8(const char *s, std::size_t len, std::string& rslt);
@@ -79,13 +90,16 @@ namespace edn
79
90
  static bool parse_byte_stream (const char *p, const char *pe, VALUE& rslt, bool encode);
80
91
  static bool parse_escaped_char(const char *p, const char *pe, VALUE& rslt);
81
92
 
82
- static VALUE make_edn_symbol(VALUE sym);
83
- static VALUE make_ruby_set(VALUE elems);
84
- static VALUE tagged_element(VALUE name, VALUE data);
93
+ static VALUE make_edn_type(ID method, VALUE value);
94
+ static VALUE make_edn_type(ID method, VALUE value1, VALUE value2);
85
95
 
86
96
  // metadata
87
97
  VALUE ruby_meta();
88
- VALUE bind_meta_to_value(VALUE value);
98
+ void new_meta_list() { metadata.push( new std::vector<VALUE>() ); }
99
+ void del_top_meta_list() { delete metadata.top(); metadata.pop(); }
100
+ void append_to_meta(VALUE m) { metadata.top()->push_back(m); }
101
+ bool meta_empty() const { return metadata.top()->empty(); }
102
+ std::size_t meta_size() const { return metadata.top()->size(); }
89
103
 
90
104
  // utility method to convert a primitive in string form to a
91
105
  // ruby type