edn_turbo 0.3.3 → 0.4.0
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 +38 -26
- data/Rakefile +7 -0
- data/ext/edn_turbo/edn_parser.cc +6 -6
- data/ext/edn_turbo/edn_parser.h +2 -0
- data/ext/edn_turbo/edn_parser.rl +3 -3
- data/ext/edn_turbo/edn_parser_util.cc +9 -2
- data/ext/edn_turbo/main.cc +12 -7
- data/lib/edn_turbo/edn_parser.rb +13 -22
- data/lib/edn_turbo/version.rb +2 -2
- data/lib/edn_turbo.rb +8 -41
- data/test/test_output_diff.rb +1 -1
- metadata +18 -7
- data/lib/edn_turbo/constants.rb +0 -14
- data/lib/edn_turbo/tags.rb +0 -46
- data/lib/edn_turbo/utils.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dee3d60eb30152a9410b1d125c8d6f2023c37001
|
4
|
+
data.tar.gz: 14e6a1cd7eb1b3d2a60d90574106763d7b2c39fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5da016b9239aea39cbe482263e697b8072e458ee4e89b692eae1b0c7a255107124f169a315eaab62955ab2969a08028a06392b9fffe4600e951ee94c6548d575
|
7
|
+
data.tar.gz: 908e2484578f51a0c7ff96328e48e8b4c2f037d19430efd26297d6398e951e2d8a05073364ff87e77b3d857453817101b9da3c7a0458548bd370fbdefcb70528
|
data/README.md
CHANGED
@@ -1,39 +1,44 @@
|
|
1
1
|
edn_turbo
|
2
|
-
|
2
|
+
=========
|
3
3
|
|
4
|
-
|
4
|
+
Fast Ragel-based EDN parser for Ruby.
|
5
5
|
|
6
|
-
|
7
|
-
[edn](https://github.com/relevance/edn-ruby)
|
8
|
-
|
6
|
+
`edn_turbo` is a parser plugin for
|
7
|
+
[edn](https://github.com/relevance/edn-ruby). With a few exceptions
|
8
|
+
`edn_turbo` provides the same functionality as the edn gem, but since
|
9
|
+
the `edn_turbo` parser is implemented in C, it is an order of
|
10
|
+
magintude faster.
|
9
11
|
|
10
|
-
As of v0.2.0, `edn_turbo` requires `edn` to support tagged elements
|
11
|
-
using a similar API and return types. Eventually, I'd like to bundle
|
12
|
-
`edn_turbo` as an optional parser for `edn`.
|
13
12
|
|
14
13
|
Some quick sample runs comparing time output of file reads using `edn`
|
15
14
|
and `edn_turbo` (see [issue 12](https://github.com/relevance/edn-ruby/issues/12)):
|
16
15
|
|
17
|
-
```
|
18
|
-
|
16
|
+
```irb(main):001:0> require 'benchmark'
|
17
|
+
=> true
|
18
|
+
irb(main):002:0> require 'edn'
|
19
|
+
=> true
|
20
|
+
irb(main):003:0> s = "[{\"x\" {\"id\" \"/model/952\", \"model_name\" \"person\", \"ancestors\" [\"record\" \"asset\"], \"format\" \"edn\"}, \"id\" 952, \"name\" nil, \"model_name\" \"person\", \"rel\" {}, \"description\" nil, \"age\" nil, \"updated_at\" nil, \"created_at\" nil, \"anniversary\" nil, \"job\" nil, \"start_date\" nil, \"username\" nil, \"vacation_start\" nil, \"vacation_end\" nil, \"expenses\" nil, \"rate\" nil, \"display_name\" nil, \"gross_profit_per_month\" nil}]"
|
19
21
|
=> "[{\"x\" {\"id\" \"/model/952\", \"model_name\" \"person\", \"ancestors\" [\"record\" \"asset\"], \"format\" \"edn\"}, \"id\" 952, \"name\" nil, \"model_name\" \"person\", \"rel\" {}, \"description\" nil, \"age\" nil, \"updated_at\" nil, \"created_at\" nil, \"anniversary\" nil, \"job\" nil, \"start_date\" nil, \"username\" nil, \"vacation_start\" nil, \"vacation_end\" nil, \"expenses\" nil, \"rate\" nil, \"display_name\" nil, \"gross_profit_per_month\" nil}]"
|
20
|
-
irb(main):
|
21
|
-
=> 0.
|
22
|
-
irb(main):
|
23
|
-
=>
|
24
|
-
irb(main):
|
25
|
-
=>
|
26
|
-
irb(main):
|
27
|
-
=>
|
22
|
+
irb(main):004:0> Benchmark.realtime { 100.times { EDN::read(s) } }
|
23
|
+
=> 0.083543
|
24
|
+
irb(main):005:0> Benchmark.realtime { 100000.times { EDN::read(s) } }
|
25
|
+
=> 73.901049
|
26
|
+
irb(main):006:0> require 'edn_turbo'
|
27
|
+
=> true
|
28
|
+
irb(main):007:0> Benchmark.realtime { 100.times { EDN::read(s) } }
|
29
|
+
=> 0.007321
|
30
|
+
irb(main):008:0> Benchmark.realtime { 100000.times { EDN::read(s) } }
|
31
|
+
=> 2.866411
|
28
32
|
```
|
29
33
|
|
34
|
+
|
30
35
|
Dependencies
|
31
36
|
============
|
32
37
|
|
33
38
|
- ruby gems:
|
34
|
-
- [rake 10.3
|
35
|
-
- [rake-compiler 0.9
|
36
|
-
- [edn 1.
|
39
|
+
- [rake 10.3](http://rake.rubyforge.org)
|
40
|
+
- [rake-compiler 0.9](http://rake-compiler.rubyforge.org)
|
41
|
+
- [edn 1.1](https://github.com/relevance/edn-ruby)
|
37
42
|
- [icu4c](http://icu-project.org/apiref/icu4c/)
|
38
43
|
|
39
44
|
|
@@ -50,21 +55,22 @@ Notes:
|
|
50
55
|
Usage
|
51
56
|
=====
|
52
57
|
|
53
|
-
|
58
|
+
Simply require 'edn_turbo' instead of 'edn'. Otherwise (with the exceptions noted below)
|
59
|
+
the API is the same as the edn gem.
|
54
60
|
|
55
61
|
```ruby
|
56
62
|
require 'edn_turbo'
|
57
63
|
|
58
64
|
File.open(filename) do |file|
|
59
|
-
output =
|
65
|
+
output = EDN.read(file)
|
60
66
|
pp output if output != EOF
|
61
67
|
end
|
62
68
|
|
63
69
|
# also accepts a string
|
64
|
-
pp
|
70
|
+
pp EDN.read("[ 1 2 3 abc ]")
|
65
71
|
|
66
72
|
# metadata
|
67
|
-
e =
|
73
|
+
e = EDN.read('^String ^:foo ^{:foo false :tag Boolean :bar 2} [1 2]')
|
68
74
|
pp e # -> [1, 2]
|
69
75
|
pp e.metadata # -> {:foo=>true, :tag=>#<EDN::Type::Symbol:0x007fdbea8a29b0 @symbol=:String>, :bar=>2}
|
70
76
|
|
@@ -75,7 +81,7 @@ Or instantiate and reuse an instance of a parser:
|
|
75
81
|
```ruby
|
76
82
|
require 'edn_turbo'
|
77
83
|
|
78
|
-
p =
|
84
|
+
p = EDN::new_parser
|
79
85
|
File.open(filename) do |file|
|
80
86
|
output = p.parse(file)
|
81
87
|
pp output if output != EOF
|
@@ -98,9 +104,15 @@ Or instantiate and reuse an instance of a parser:
|
|
98
104
|
end
|
99
105
|
```
|
100
106
|
|
107
|
+
Differences with edn gem
|
108
|
+
========================
|
109
|
+
Currently, `edn_turbo` cannot read multiple EDN values from a stream
|
110
|
+
the way that `edn-ruby`'s parser can. `edn_turbo` expects string input
|
111
|
+
and has no way to control ruby streams of other types.
|
101
112
|
|
102
113
|
Known problems
|
103
114
|
==============
|
115
|
+
|
104
116
|
v0.3.2:
|
105
117
|
|
106
118
|
- Some unhandled corner cases with operators and spacing
|
data/Rakefile
CHANGED
@@ -13,6 +13,13 @@ RAGEL_PARSER_SRC_PATH = "#{EXT_PATH}/#{RAGEL_PARSER_SRC}"
|
|
13
13
|
GEN_CC_PARSER_SRC = "edn_parser.cc"
|
14
14
|
GEN_CC_PARSER_SRC_PATH = "#{EXT_PATH}/#{GEN_CC_PARSER_SRC}"
|
15
15
|
|
16
|
+
task :irb do
|
17
|
+
sh "irb -I lib -r edn_turbo"
|
18
|
+
sh "reset"
|
19
|
+
end
|
20
|
+
|
21
|
+
task :runthru => [:clean, :default, :test]
|
22
|
+
|
16
23
|
Rake::ExtensionTask.new("#{NAME}") do |extension|
|
17
24
|
extension.lib_dir = LIB_DIR
|
18
25
|
extension.source_pattern = "*.{cc,h}"
|
data/ext/edn_turbo/edn_parser.cc
CHANGED
@@ -2273,7 +2273,7 @@ tr5:
|
|
2273
2273
|
// parse_value() read an element we care
|
2274
2274
|
// about. Bind the metadata to it and add it to
|
2275
2275
|
// the sequence
|
2276
|
-
e = Parser::make_edn_type(EDNT_EXTENDED_VALUE_METHOD, e, ruby_meta());
|
2276
|
+
e = Parser::make_edn_type(rb_mEDNT, EDNT_EXTENDED_VALUE_METHOD, e, ruby_meta());
|
2277
2277
|
rb_ary_push(elems, e);
|
2278
2278
|
}
|
2279
2279
|
} else {
|
@@ -2471,7 +2471,7 @@ tr5:
|
|
2471
2471
|
// parse_value() read an element we care
|
2472
2472
|
// about. Bind the metadata to it and add it to
|
2473
2473
|
// the sequence
|
2474
|
-
e = Parser::make_edn_type(EDNT_EXTENDED_VALUE_METHOD, e, ruby_meta());
|
2474
|
+
e = Parser::make_edn_type(rb_mEDNT, EDNT_EXTENDED_VALUE_METHOD, e, ruby_meta());
|
2475
2475
|
rb_ary_push(elems, e);
|
2476
2476
|
}
|
2477
2477
|
} else {
|
@@ -2671,7 +2671,7 @@ tr5:
|
|
2671
2671
|
// parse_value() read an element we care
|
2672
2672
|
// about. Bind the metadata to it and add it to
|
2673
2673
|
// the sequence
|
2674
|
-
e = Parser::make_edn_type(EDNT_EXTENDED_VALUE_METHOD, e, ruby_meta());
|
2674
|
+
e = Parser::make_edn_type(rb_mEDNT, EDNT_EXTENDED_VALUE_METHOD, e, ruby_meta());
|
2675
2675
|
rb_ary_push(elems, e);
|
2676
2676
|
}
|
2677
2677
|
} else {
|
@@ -2994,7 +2994,7 @@ tr5:
|
|
2994
2994
|
// parse_value() read an element we care
|
2995
2995
|
// about. Bind the metadata to it and add it to
|
2996
2996
|
// the sequence
|
2997
|
-
e = Parser::make_edn_type(EDNT_EXTENDED_VALUE_METHOD, e, ruby_meta());
|
2997
|
+
e = Parser::make_edn_type(rb_mEDNT, EDNT_EXTENDED_VALUE_METHOD, e, ruby_meta());
|
2998
2998
|
rb_ary_push(elems, e);
|
2999
2999
|
}
|
3000
3000
|
} else {
|
@@ -3680,7 +3680,7 @@ tr4:
|
|
3680
3680
|
// metadata sequence to it
|
3681
3681
|
if (!meta_empty() && meta_size() == meta_sz) {
|
3682
3682
|
// this will empty the metadata sequence too
|
3683
|
-
result = Parser::make_edn_type(EDNT_EXTENDED_VALUE_METHOD, result, ruby_meta());
|
3683
|
+
result = Parser::make_edn_type(rb_mEDNT, EDNT_EXTENDED_VALUE_METHOD, result, ruby_meta());
|
3684
3684
|
}
|
3685
3685
|
{p = (( np))-1;}
|
3686
3686
|
}
|
@@ -3849,7 +3849,7 @@ tr3:
|
|
3849
3849
|
else {
|
3850
3850
|
// a value was read and there's a pending metadata
|
3851
3851
|
// sequence. Bind them.
|
3852
|
-
value = Parser::make_edn_type(EDNT_EXTENDED_VALUE_METHOD, value, ruby_meta());
|
3852
|
+
value = Parser::make_edn_type(rb_mEDNT, EDNT_EXTENDED_VALUE_METHOD, value, ruby_meta());
|
3853
3853
|
state = TOKEN_OK;
|
3854
3854
|
}
|
3855
3855
|
} else if (!discard.empty()) {
|
data/ext/edn_turbo/edn_parser.h
CHANGED
@@ -12,6 +12,7 @@
|
|
12
12
|
namespace edn
|
13
13
|
{
|
14
14
|
extern VALUE rb_mEDNT;
|
15
|
+
extern VALUE EDN_MODULE_SYMBOL;
|
15
16
|
extern VALUE EDNT_MAKE_SYMBOL_METHOD;
|
16
17
|
extern VALUE EDNT_MAKE_LIST_METHOD;
|
17
18
|
extern VALUE EDNT_MAKE_SET_METHOD;
|
@@ -92,6 +93,7 @@ namespace edn
|
|
92
93
|
|
93
94
|
static VALUE make_edn_type(ID method, VALUE value);
|
94
95
|
static VALUE make_edn_type(ID method, VALUE value1, VALUE value2);
|
96
|
+
static VALUE make_edn_type(VALUE module, ID method, VALUE value1, VALUE value2);
|
95
97
|
|
96
98
|
// metadata
|
97
99
|
VALUE ruby_meta();
|
data/ext/edn_turbo/edn_parser.rl
CHANGED
@@ -600,7 +600,7 @@ const char* edn::Parser::parse_symbol(const char *p, const char *pe, VALUE& s)
|
|
600
600
|
// parse_value() read an element we care
|
601
601
|
// about. Bind the metadata to it and add it to
|
602
602
|
// the sequence
|
603
|
-
e = Parser::make_edn_type(EDNT_EXTENDED_VALUE_METHOD, e, ruby_meta());
|
603
|
+
e = Parser::make_edn_type(rb_mEDNT, EDNT_EXTENDED_VALUE_METHOD, e, ruby_meta());
|
604
604
|
rb_ary_push(elems, e);
|
605
605
|
}
|
606
606
|
} else {
|
@@ -1089,7 +1089,7 @@ const char* edn::Parser::parse_meta(const char *p, const char *pe)
|
|
1089
1089
|
// metadata sequence to it
|
1090
1090
|
if (!meta_empty() && meta_size() == meta_sz) {
|
1091
1091
|
// this will empty the metadata sequence too
|
1092
|
-
result = Parser::make_edn_type(EDNT_EXTENDED_VALUE_METHOD, result, ruby_meta());
|
1092
|
+
result = Parser::make_edn_type(rb_mEDNT, EDNT_EXTENDED_VALUE_METHOD, result, ruby_meta());
|
1093
1093
|
}
|
1094
1094
|
fexec np;
|
1095
1095
|
}
|
@@ -1151,7 +1151,7 @@ VALUE edn::Parser::parse(const char* src, std::size_t len)
|
|
1151
1151
|
else {
|
1152
1152
|
// a value was read and there's a pending metadata
|
1153
1153
|
// sequence. Bind them.
|
1154
|
-
value = Parser::make_edn_type(EDNT_EXTENDED_VALUE_METHOD, value, ruby_meta());
|
1154
|
+
value = Parser::make_edn_type(rb_mEDNT, EDNT_EXTENDED_VALUE_METHOD, value, ruby_meta());
|
1155
1155
|
state = TOKEN_OK;
|
1156
1156
|
}
|
1157
1157
|
} else if (!discard.empty()) {
|
@@ -249,13 +249,20 @@ namespace edn
|
|
249
249
|
// get a set representation from the ruby side. See edn_turbo.rb
|
250
250
|
VALUE Parser::make_edn_type(ID method, VALUE sym)
|
251
251
|
{
|
252
|
-
|
252
|
+
VALUE edn_module = rb_const_get(rb_cObject, edn::EDN_MODULE_SYMBOL);
|
253
|
+
prot_args args(edn_module, method, sym);
|
253
254
|
return edn_prot_rb_funcall( edn_wrap_funcall2, reinterpret_cast<VALUE>(&args) );
|
254
255
|
}
|
255
256
|
|
256
257
|
VALUE Parser::make_edn_type(ID method, VALUE name, VALUE data)
|
257
258
|
{
|
258
|
-
|
259
|
+
VALUE module = rb_const_get(rb_cObject, edn::EDN_MODULE_SYMBOL);
|
260
|
+
return make_edn_type(module, method, name, data);
|
261
|
+
}
|
262
|
+
|
263
|
+
VALUE Parser::make_edn_type(VALUE module, ID method, VALUE name, VALUE data)
|
264
|
+
{
|
265
|
+
prot_args args(module, method, name, data);
|
259
266
|
return edn_prot_rb_funcall( edn_wrap_funcall2, reinterpret_cast<VALUE>(&args) );
|
260
267
|
}
|
261
268
|
|
data/ext/edn_turbo/main.cc
CHANGED
@@ -13,7 +13,9 @@ namespace edn {
|
|
13
13
|
|
14
14
|
VALUE rb_mEDNT;
|
15
15
|
|
16
|
-
//
|
16
|
+
// Symbols used to call into the ruby world.
|
17
|
+
VALUE EDN_MODULE_SYMBOL = Qnil;
|
18
|
+
|
17
19
|
VALUE EDNT_MAKE_SYMBOL_METHOD = Qnil;
|
18
20
|
VALUE EDNT_MAKE_LIST_METHOD = Qnil;
|
19
21
|
VALUE EDNT_MAKE_SET_METHOD = Qnil;
|
@@ -28,7 +30,7 @@ namespace edn {
|
|
28
30
|
VALUE EDNT_EOF_CONST = Qnil;
|
29
31
|
|
30
32
|
//
|
31
|
-
//
|
33
|
+
// Wrappers to hook the class w/ the C-api.
|
32
34
|
static void delete_parser(edn::Parser *ptr) {
|
33
35
|
delete ptr;
|
34
36
|
}
|
@@ -50,7 +52,7 @@ namespace edn {
|
|
50
52
|
|
51
53
|
|
52
54
|
//
|
53
|
-
//
|
55
|
+
// Called by the constructor - sets the source if passed.
|
54
56
|
static VALUE initialize(int argc, VALUE* argv, VALUE self)
|
55
57
|
{
|
56
58
|
Parser* p = get_parser(self);
|
@@ -133,12 +135,14 @@ void Init_edn_turbo(void)
|
|
133
135
|
VALUE rb_cParser = rb_define_class_under(edn::rb_mEDNT, "Parser", rb_cObject);
|
134
136
|
rb_define_alloc_func(rb_cParser, edn::alloc_obj);
|
135
137
|
rb_define_method(rb_cParser, "initialize", (VALUE(*)(ANYARGS)) &edn::initialize, -1 );
|
136
|
-
rb_define_method(rb_cParser, "ext_set_stream", (VALUE(*)(ANYARGS)) &edn::set_source, 1 );
|
137
138
|
rb_define_method(rb_cParser, "ext_eof", (VALUE(*)(ANYARGS)) &edn::eof, 0 );
|
138
|
-
|
139
|
-
rb_define_method(rb_cParser, "
|
139
|
+
|
140
|
+
rb_define_method(rb_cParser, "set_input", (VALUE(*)(ANYARGS)) &edn::set_source, 1 );
|
141
|
+
rb_define_method(rb_cParser, "parse", (VALUE(*)(ANYARGS)) &edn::read, 1 );
|
142
|
+
rb_define_method(rb_cParser, "read", (VALUE(*)(ANYARGS)) &edn::next, 0 );
|
140
143
|
|
141
144
|
// bind ruby methods we'll call - these should be defined in edn_turbo.rb
|
145
|
+
edn::EDN_MODULE_SYMBOL = rb_intern("EDN");
|
142
146
|
edn::EDNT_MAKE_SYMBOL_METHOD = rb_intern("symbol");
|
143
147
|
edn::EDNT_MAKE_LIST_METHOD = rb_intern("list");
|
144
148
|
edn::EDNT_MAKE_SET_METHOD = rb_intern("set");
|
@@ -150,5 +154,6 @@ void Init_edn_turbo(void)
|
|
150
154
|
edn::EDNT_STRING_TO_F_METHOD = rb_intern("to_f");
|
151
155
|
|
152
156
|
// so we can return EOF directly
|
153
|
-
|
157
|
+
VALUE edn_module = rb_const_get(rb_cObject, edn::EDN_MODULE_SYMBOL);
|
158
|
+
edn::EDNT_EOF_CONST = rb_const_get(edn_module, rb_intern("EOF"));
|
154
159
|
}
|
data/lib/edn_turbo/edn_parser.rb
CHANGED
@@ -1,31 +1,22 @@
|
|
1
|
-
require 'edn'
|
2
|
-
require 'bigdecimal'
|
3
|
-
|
4
1
|
module EDNT
|
2
|
+
# Bind the given meta to the value.
|
3
|
+
def self.extend_for_meta(value, ext_meta)
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
# initialize() is defined in the c-side (main.cc)
|
9
|
-
|
10
|
-
# call the c-side method
|
11
|
-
def set_input(data)
|
12
|
-
ext_set_stream(data)
|
13
|
-
end
|
5
|
+
meta = ext_meta
|
14
6
|
|
15
|
-
|
16
|
-
|
17
|
-
|
7
|
+
metadata = meta.reduce({}) do |acc, m|
|
8
|
+
case m
|
9
|
+
when Symbol then acc.merge(m => true)
|
10
|
+
when EDN::Type::Symbol then acc.merge(:tag => m)
|
11
|
+
else acc.merge(m)
|
12
|
+
end
|
18
13
|
end
|
19
14
|
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
if !metadata.empty?
|
16
|
+
value.extend EDN::Metadata
|
17
|
+
value.metadata = metadata
|
23
18
|
end
|
24
19
|
|
20
|
+
value
|
25
21
|
end
|
26
|
-
|
27
|
-
def self.big_decimal(str)
|
28
|
-
BigDecimal.new(str)
|
29
|
-
end
|
30
|
-
|
31
22
|
end
|
data/lib/edn_turbo/version.rb
CHANGED
data/lib/edn_turbo.rb
CHANGED
@@ -1,42 +1,9 @@
|
|
1
|
-
require_relative 'edn_turbo/constants'
|
2
|
-
require_relative 'edn_turbo/tags'
|
3
|
-
require_relative 'edn_turbo/utils'
|
4
|
-
require_relative 'edn_turbo/version'
|
5
|
-
require_relative 'edn_turbo/edn_parser'
|
6
|
-
require_relative 'edn_turbo/edn_turbo'
|
7
|
-
|
8
|
-
require 'set'
|
9
1
|
require 'edn'
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
begin
|
19
|
-
data = input.instance_of?(String) ? input : input.read
|
20
|
-
|
21
|
-
Parser.new.parse(data)
|
22
|
-
rescue EOFError
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
# ----------------------------------------------------------------------------
|
28
|
-
# handles creation of various EDN representations
|
29
|
-
#
|
30
|
-
def self.symbol(elem)
|
31
|
-
EDN::Type::Symbol.new(elem)
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.list(*elems)
|
35
|
-
EDN::Type::List.new(*elems)
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.set(*elems)
|
39
|
-
Set.new(*elems)
|
40
|
-
end
|
41
|
-
|
42
|
-
end # EDN namespace
|
2
|
+
require 'edn_turbo/version'
|
3
|
+
require 'edn_turbo/edn_parser'
|
4
|
+
require 'edn_turbo/edn_turbo'
|
5
|
+
|
6
|
+
# Replace the parser in the EDN module with the C based one.
|
7
|
+
module EDN
|
8
|
+
self.parser = EDNT::Parser
|
9
|
+
end
|
data/test/test_output_diff.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: edn_turbo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ed Porras
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: edn
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: Optimization for parsing of EDN files using ragel in a c++ extension
|
56
70
|
email: ed@motologic.com
|
57
71
|
executables:
|
@@ -75,10 +89,7 @@ files:
|
|
75
89
|
- ext/edn_turbo/extconf.rb
|
76
90
|
- ext/edn_turbo/main.cc
|
77
91
|
- lib/edn_turbo.rb
|
78
|
-
- lib/edn_turbo/constants.rb
|
79
92
|
- lib/edn_turbo/edn_parser.rb
|
80
|
-
- lib/edn_turbo/tags.rb
|
81
|
-
- lib/edn_turbo/utils.rb
|
82
93
|
- lib/edn_turbo/version.rb
|
83
94
|
- test/test_output_diff.rb
|
84
95
|
homepage: http://rubygems.org/gems/edn_turbo
|
data/lib/edn_turbo/constants.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'edn'
|
2
|
-
|
3
|
-
module EDNT
|
4
|
-
|
5
|
-
# Object returned when there is nothing to return
|
6
|
-
|
7
|
-
NOTHING = EDN::NOTHING
|
8
|
-
|
9
|
-
# Object to return when we hit end of file. Cant be nil or :eof
|
10
|
-
# because either of those could be something in the EDN data.
|
11
|
-
|
12
|
-
EOF = EDN::EOF
|
13
|
-
|
14
|
-
end
|
data/lib/edn_turbo/tags.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'edn'
|
2
|
-
|
3
|
-
module EDNT
|
4
|
-
|
5
|
-
# ----------------------------------------------------------------------------
|
6
|
-
# register a tagged element
|
7
|
-
#
|
8
|
-
TAGS = {
|
9
|
-
# built-in tagged elements
|
10
|
-
"inst" => lambda { |*a| DateTime.parse(*a) },
|
11
|
-
"uuid" => lambda { |*a| String.new(*a) }
|
12
|
-
}
|
13
|
-
|
14
|
-
def self.register(tag, func = nil, &block)
|
15
|
-
# don't allow re-registration of built-in tags
|
16
|
-
if tag != "inst" && tag != "uuid"
|
17
|
-
if block_given?
|
18
|
-
func = block
|
19
|
-
end
|
20
|
-
|
21
|
-
if func.nil?
|
22
|
-
func = lambda { |x| x }
|
23
|
-
end
|
24
|
-
|
25
|
-
if func.is_a?(Class)
|
26
|
-
TAGS[tag] = lambda { |*args| func.new(*args) }
|
27
|
-
else
|
28
|
-
TAGS[tag] = func
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.unregister(tag)
|
34
|
-
TAGS[tag] = nil
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.tagged_element(tag, element)
|
38
|
-
func = TAGS[tag]
|
39
|
-
if func
|
40
|
-
func.call(element)
|
41
|
-
else
|
42
|
-
EDN::Type::Unknown.new(tag, element)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
data/lib/edn_turbo/utils.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'edn'
|
2
|
-
|
3
|
-
module EDNT
|
4
|
-
|
5
|
-
# ============================================================================
|
6
|
-
# emulate EDN::Metadata
|
7
|
-
module Metadata
|
8
|
-
attr_accessor :metadata
|
9
|
-
end
|
10
|
-
|
11
|
-
# ----------------------------------------------------------------------------
|
12
|
-
# bind the given meta to the value
|
13
|
-
#
|
14
|
-
def self.extend_for_meta(value, ext_meta)
|
15
|
-
|
16
|
-
meta = ext_meta
|
17
|
-
|
18
|
-
metadata = meta.reduce({}) do |acc, m|
|
19
|
-
case m
|
20
|
-
when Symbol then acc.merge(m => true)
|
21
|
-
when EDN::Type::Symbol then acc.merge(:tag => m)
|
22
|
-
else acc.merge(m)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
if !metadata.empty?
|
27
|
-
value.extend Metadata
|
28
|
-
value.metadata = metadata
|
29
|
-
end
|
30
|
-
|
31
|
-
value
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|