jievro-ast 0.5.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/jievro/ast/node.rb +53 -58
- data/lib/jievro/ast/version.rb +1 -1
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49d9fe0ebd50c3c84a6de1eaa46c779a8d11477a
|
4
|
+
data.tar.gz: c73e464fb408e2eaa2df994b72df41ee454ba35d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ccd7c52df8befc996f614267283f649b744fa81cfc80dab1703620754152863711a40342144f47fbcb3bb423f4bf440f9b8c4890fb54c5810092de45ec51a85
|
7
|
+
data.tar.gz: 9b6fc18a26281e6d18c651a3689d34d16fec5ce72bcc4d74eb4923190fb84c58c21bc5830728c97ab62de6335f3d486a287f8a4f22d37f14350f2951b7c915ca
|
data/Gemfile.lock
CHANGED
data/lib/jievro/ast/node.rb
CHANGED
@@ -1,27 +1,37 @@
|
|
1
1
|
module Jievro
|
2
2
|
module Ast
|
3
3
|
class Node
|
4
|
-
|
5
|
-
TYPE_COLLECTION = '__collection'
|
4
|
+
attr_reader :id, :parent, :type
|
6
5
|
|
7
|
-
|
6
|
+
def initialize(initializer, parent = nil)
|
7
|
+
fail Exception, 'The initializer must be Hash' \
|
8
|
+
unless initializer.is_a?(Hash)
|
8
9
|
|
9
|
-
|
10
|
+
fail Exception, 'Initializer is missing __type value' \
|
11
|
+
unless initializer.key?(:__type)
|
12
|
+
|
13
|
+
@id = Ast::Node.generate_next_id
|
10
14
|
@parent = parent
|
11
|
-
@
|
15
|
+
@value = {}
|
16
|
+
@type = initializer[:__type]
|
12
17
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
initializer.keys.each do |k|
|
19
|
+
next if k == :__type
|
20
|
+
|
21
|
+
value = initializer[k]
|
22
|
+
|
23
|
+
if literal?(value)
|
24
|
+
@value[k] = value
|
25
|
+
else
|
26
|
+
if array?(value)
|
27
|
+
@value[k] = []
|
28
|
+
value.each_with_index do |v, i|
|
29
|
+
@value[k][i] = Node.new(v, self)
|
30
|
+
end
|
31
|
+
else
|
32
|
+
@value[k] = Node.new(value, self)
|
33
|
+
end
|
34
|
+
end
|
25
35
|
end
|
26
36
|
end
|
27
37
|
|
@@ -32,25 +42,12 @@ module Jievro
|
|
32
42
|
@value[key]
|
33
43
|
end
|
34
44
|
|
35
|
-
def key
|
36
|
-
@key.to_s
|
37
|
-
end
|
38
|
-
|
39
45
|
def keys
|
40
46
|
@value.keys
|
41
47
|
end
|
42
48
|
|
43
|
-
def value
|
44
|
-
fail Exception, 'Cannot get value from a non literal node' \
|
45
|
-
unless @type == TYPE_LITERAL
|
46
|
-
|
47
|
-
@value
|
48
|
-
end
|
49
|
-
|
50
49
|
def serialize
|
51
|
-
|
52
|
-
|
53
|
-
if type == TYPE_COLLECTION
|
50
|
+
if array?(@value)
|
54
51
|
serialized = []
|
55
52
|
else
|
56
53
|
serialized = {
|
@@ -59,7 +56,18 @@ module Jievro
|
|
59
56
|
end
|
60
57
|
|
61
58
|
each_with_index do |v, k|
|
62
|
-
|
59
|
+
if literal?(v)
|
60
|
+
serialized[k] = v
|
61
|
+
else
|
62
|
+
if array?(v)
|
63
|
+
serialized[k] = []
|
64
|
+
v.each_with_index do |w, i|
|
65
|
+
serialized[k][i] = w.serialize
|
66
|
+
end
|
67
|
+
else
|
68
|
+
serialized[k] = v.serialize
|
69
|
+
end
|
70
|
+
end
|
63
71
|
end
|
64
72
|
|
65
73
|
serialized
|
@@ -72,9 +80,6 @@ module Jievro
|
|
72
80
|
end
|
73
81
|
|
74
82
|
def each_with_index
|
75
|
-
fail Exception, 'Cannot iterate a literal node' \
|
76
|
-
if @type == TYPE_LITERAL
|
77
|
-
|
78
83
|
@value.keys.each do |v|
|
79
84
|
yield @value[v], v
|
80
85
|
end
|
@@ -82,33 +87,23 @@ module Jievro
|
|
82
87
|
|
83
88
|
private
|
84
89
|
|
85
|
-
def
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
@value = {}
|
92
|
-
@type = TYPE_COLLECTION
|
93
|
-
|
94
|
-
initializer.each_with_index do |e, i|
|
95
|
-
@value[i] = Node.new(e, self, i)
|
90
|
+
def literal?(value)
|
91
|
+
case value
|
92
|
+
when NilClass, FalseClass, TrueClass, String, Fixnum, Float
|
93
|
+
return true
|
94
|
+
else
|
95
|
+
return false
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
def
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
@value = {}
|
104
|
-
@type = initializer[:__type]
|
105
|
-
|
106
|
-
initializer.keys.each do |k|
|
107
|
-
# skip all the meta info
|
108
|
-
next if k.to_s.to_s.start_with?('__')
|
99
|
+
def array?(value)
|
100
|
+
value.is_a?(Array)
|
101
|
+
end
|
109
102
|
|
110
|
-
|
111
|
-
|
103
|
+
def self.generate_next_id
|
104
|
+
@id = 0 if @id.nil?
|
105
|
+
@id += 1
|
106
|
+
@id
|
112
107
|
end
|
113
108
|
end
|
114
109
|
end
|
data/lib/jievro/ast/version.rb
CHANGED
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jievro-ast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Azzalini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.9'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.9'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '3.2'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.2'
|
55
55
|
description:
|
@@ -58,8 +58,8 @@ executables: []
|
|
58
58
|
extensions: []
|
59
59
|
extra_rdoc_files: []
|
60
60
|
files:
|
61
|
-
- .gitignore
|
62
|
-
- .travis.yml
|
61
|
+
- ".gitignore"
|
62
|
+
- ".travis.yml"
|
63
63
|
- Gemfile
|
64
64
|
- Gemfile.lock
|
65
65
|
- LICENSE.txt
|
@@ -79,17 +79,17 @@ require_paths:
|
|
79
79
|
- lib
|
80
80
|
required_ruby_version: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
|
-
- - ~>
|
82
|
+
- - "~>"
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '2.0'
|
85
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
requirements: []
|
91
91
|
rubyforge_project:
|
92
|
-
rubygems_version: 2.
|
92
|
+
rubygems_version: 2.4.6
|
93
93
|
signing_key:
|
94
94
|
specification_version: 4
|
95
95
|
summary: AST model used internally by jievro-parser
|