gimlr 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile +4 -0
- data/LICENSE +9 -0
- data/README.md +35 -0
- data/gimlr.gemspec +21 -0
- data/lib/gimlr.rb +70 -0
- data/lib/gimlr/version.rb +3 -0
- data/script.rb +28 -0
- data/test/test_file.giml +23 -0
- data/test/test_file.yaml +25 -0
- metadata +56 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9c5de8044c66cb06efd884e7f8fe321de09a1229
|
4
|
+
data.tar.gz: 610e7aa70c8054e80e63f05d7b6a21ced694abe3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0dbba19794a5ab30c5100439b689f662a8451505f964c7464562e093a6625907234eb2fcf3b772e984ae8dacd2b10b2ab69582da6f453c40eaa56ab415d24e80
|
7
|
+
data.tar.gz: 151edcff93860bdf0293aa05184dd37a4c746263be6f2fa7e1c66038e8eb3e1cce5514dd8b9f3694ddaf6a9cf54056f7ce816951771eb43a098095afb56419fc
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2014 gazay
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# gimlr
|
2
|
+
|
3
|
+
Ruby parser for GIML.
|
4
|
+
|
5
|
+
## Benchmarks
|
6
|
+
|
7
|
+
Small files (which in test folder):
|
8
|
+
|
9
|
+
```
|
10
|
+
Calculating -------------------------------------
|
11
|
+
gimlr 1.487k i/100ms
|
12
|
+
yaml 541.000 i/100ms
|
13
|
+
-------------------------------------------------
|
14
|
+
gimlr 15.244k (± 3.7%) i/s - 153.161k
|
15
|
+
yaml 5.777k (± 5.1%) i/s - 57.887k
|
16
|
+
|
17
|
+
Comparison:
|
18
|
+
gimlr: 15244.1 i/s
|
19
|
+
yaml: 5776.5 i/s - 2.64x slower
|
20
|
+
```
|
21
|
+
|
22
|
+
Big files (~43k lines - just replicated data with same structure as test/test_files)
|
23
|
+
|
24
|
+
```
|
25
|
+
Calculating -------------------------------------
|
26
|
+
gimlr 1.000 i/100ms
|
27
|
+
yaml 1.000 i/100ms
|
28
|
+
-------------------------------------------------
|
29
|
+
gimlr 17.822 (±11.2%) i/s - 883.000
|
30
|
+
yaml 3.536 (± 0.0%) i/s - 177.000
|
31
|
+
|
32
|
+
Comparison:
|
33
|
+
gimlr: 17.8 i/s
|
34
|
+
yaml: 3.5 i/s - 5.04x slower
|
35
|
+
```
|
data/gimlr.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'gimlr/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'gimlr'
|
7
|
+
s.version = Gimlr::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['gazay']
|
10
|
+
s.licenses = ['MIT']
|
11
|
+
s.email = ['alex.gaziev@gmail.com']
|
12
|
+
s.homepage = 'https://github.com/gazay/gimlr'
|
13
|
+
s.summary = %q{Ruby parser for GIML}
|
14
|
+
s.description = %q{First, fast and simple parser for GIML}
|
15
|
+
|
16
|
+
s.rubyforge_project = 'gimlr'
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.require_paths = ['lib']
|
21
|
+
end
|
data/lib/gimlr.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
module Gimlr
|
2
|
+
extend self
|
3
|
+
|
4
|
+
TYPES = [':text:', ':num:', ':list:', ':vlist:'].freeze
|
5
|
+
TYPE_CHAR = ':'.freeze
|
6
|
+
COMMENT_CHAR = '#'.freeze
|
7
|
+
LIST_NEW_LINE_CHAR = '-'.freeze
|
8
|
+
|
9
|
+
def parse_string(content)
|
10
|
+
parse content
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse_file(file_path)
|
14
|
+
File.open(file_path, 'r') do |f|
|
15
|
+
parse f
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def parse(enum)
|
22
|
+
result = {}
|
23
|
+
var = nil
|
24
|
+
var_type = nil
|
25
|
+
enum.each_line do |line|
|
26
|
+
var, var_type, result = parse_line line, result, var, var_type
|
27
|
+
end
|
28
|
+
|
29
|
+
result
|
30
|
+
end
|
31
|
+
|
32
|
+
def parse_line(line, result, var, var_type)
|
33
|
+
return var, var_type, result if line.start_with? COMMENT_CHAR
|
34
|
+
if line.start_with?(TYPE_CHAR) && TYPES.find { |t| line.start_with? t }
|
35
|
+
var_type, var = line.split(' ')
|
36
|
+
elsif var
|
37
|
+
case var_type
|
38
|
+
when TYPES[0]
|
39
|
+
result[var] ||= ''
|
40
|
+
result[var] << line
|
41
|
+
when TYPES[1]
|
42
|
+
if line.chomp != ''
|
43
|
+
if line =~ /\./
|
44
|
+
result[var] = line.to_f
|
45
|
+
else
|
46
|
+
result[var] = line.to_i
|
47
|
+
end
|
48
|
+
end
|
49
|
+
when TYPES[2]
|
50
|
+
if line[2..-1]
|
51
|
+
result[var] ||= []
|
52
|
+
result[var] += line.
|
53
|
+
gsub('\, ', '\,\ ').
|
54
|
+
split(', ').
|
55
|
+
map { |it| it.gsub('\,\ ', ', ').chomp }
|
56
|
+
end
|
57
|
+
else
|
58
|
+
if line[2..-1]
|
59
|
+
result[var] ||= []
|
60
|
+
if line.start_with? LIST_NEW_LINE_CHAR
|
61
|
+
result[var] << line[2..-1].chomp
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
[var, var_type, result]
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
data/script.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path('../../lib/gimlr.rb', __FILE__)
|
2
|
+
require 'yaml'
|
3
|
+
require 'byebug'
|
4
|
+
require 'benchmark/ips'
|
5
|
+
require 'ruby-prof'
|
6
|
+
|
7
|
+
path = File.expand_path('../test_file.giml', __FILE__)
|
8
|
+
|
9
|
+
path2 = File.expand_path('../test_file.yaml', __FILE__)
|
10
|
+
|
11
|
+
#puts GIMLR.parse_file(path)
|
12
|
+
|
13
|
+
Benchmark.ips do |x|
|
14
|
+
x.config(time: 10, warmup: 5)
|
15
|
+
x.report('gimlr') { Gimlr.parse_file(path) }
|
16
|
+
x.report('yaml') { YAML.load_file(path2) }
|
17
|
+
|
18
|
+
x.compare!
|
19
|
+
end
|
20
|
+
|
21
|
+
=begin
|
22
|
+
RubyProf.start
|
23
|
+
Gimlr.parse_file(path)
|
24
|
+
result = RubyProf.stop
|
25
|
+
|
26
|
+
printer = RubyProf::GraphHtmlPrinter.new(result)
|
27
|
+
printer.print(STDOUT)
|
28
|
+
=end
|
data/test/test_file.giml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Some not interesting things
|
2
|
+
|
3
|
+
:text: this_is_text
|
4
|
+
Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text
|
5
|
+
Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text
|
6
|
+
|
7
|
+
:num: this_is_num
|
8
|
+
12345
|
9
|
+
|
10
|
+
:num: this_another_num
|
11
|
+
# Some comment
|
12
|
+
123.234
|
13
|
+
|
14
|
+
:list: this_is_array
|
15
|
+
1, 2, 3, 4, 5, 1, 2, 3, 4, 5
|
16
|
+
|
17
|
+
:vlist: this_is_another_array
|
18
|
+
- 1
|
19
|
+
- 2
|
20
|
+
- 3
|
21
|
+
- 4
|
22
|
+
- 5
|
23
|
+
- 6
|
data/test/test_file.yaml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
text:
|
2
|
+
Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text
|
3
|
+
Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text
|
4
|
+
|
5
|
+
num:
|
6
|
+
12345
|
7
|
+
|
8
|
+
another_num:
|
9
|
+
1234.324
|
10
|
+
|
11
|
+
list:
|
12
|
+
- "1"
|
13
|
+
- "2"
|
14
|
+
- "3"
|
15
|
+
- "4"
|
16
|
+
- "5"
|
17
|
+
- "6"
|
18
|
+
|
19
|
+
another_list:
|
20
|
+
- "1"
|
21
|
+
- "2"
|
22
|
+
- "3"
|
23
|
+
- "4"
|
24
|
+
- "5"
|
25
|
+
- "6"
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gimlr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- gazay
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: First, fast and simple parser for GIML
|
14
|
+
email:
|
15
|
+
- alex.gaziev@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- Gemfile
|
22
|
+
- LICENSE
|
23
|
+
- README.md
|
24
|
+
- gimlr.gemspec
|
25
|
+
- lib/gimlr.rb
|
26
|
+
- lib/gimlr/version.rb
|
27
|
+
- script.rb
|
28
|
+
- test/test_file.giml
|
29
|
+
- test/test_file.yaml
|
30
|
+
homepage: https://github.com/gazay/gimlr
|
31
|
+
licenses:
|
32
|
+
- MIT
|
33
|
+
metadata: {}
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project: gimlr
|
50
|
+
rubygems_version: 2.2.2
|
51
|
+
signing_key:
|
52
|
+
specification_version: 4
|
53
|
+
summary: Ruby parser for GIML
|
54
|
+
test_files:
|
55
|
+
- test/test_file.giml
|
56
|
+
- test/test_file.yaml
|