edn_turbo 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +9 -4
- data/bin/ppedn +3 -1
- data/ext/edn_turbo/edn_parser.cc +1337 -946
- data/ext/edn_turbo/edn_parser.h +27 -13
- data/ext/edn_turbo/edn_parser.rl +207 -145
- data/ext/edn_turbo/edn_parser_util.cc +56 -47
- data/ext/edn_turbo/main.cc +20 -17
- data/lib/edn_turbo/constants.rb +14 -0
- data/lib/edn_turbo/edn_parser.rb +5 -2
- data/lib/edn_turbo/tags.rb +46 -0
- data/lib/edn_turbo/utils.rb +34 -0
- data/lib/edn_turbo/version.rb +2 -2
- data/lib/edn_turbo.rb +10 -92
- data/test/test_output_diff.rb +56 -26
- metadata +6 -3
data/ext/edn_turbo/edn_parser.h
CHANGED
@@ -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
|
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
|
17
|
-
extern VALUE
|
18
|
-
extern VALUE
|
19
|
-
|
20
|
-
extern VALUE
|
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
|
-
|
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
|
83
|
-
static VALUE
|
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
|
-
|
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
|