jievro-ast 0.3.1 → 0.3.2
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 +9 -6
- data/lib/jievro/ast/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3a255322b21284974bd0fd3355b312962e064fc
|
4
|
+
data.tar.gz: 41f7e711f44e2fded4df1b84451381bda69bec6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cea7140044cabf7eaf71ace097c966205d59b5166f10072adfa2478f22ba725e513dffdd57b440d23785f8e9011a870b064292b0cdbc48f08685a96c521e45db
|
7
|
+
data.tar.gz: 8093e28b845181559d24ad807471ef755bcc62d233cac1871f10119c1aade94bc3500bc42459610e0957cdc12a7feb79d5a4c7221be7b6388e784ebcec030d5f
|
data/Gemfile.lock
CHANGED
data/lib/jievro/ast/node.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
module Jievro
|
2
2
|
module Ast
|
3
3
|
class Node
|
4
|
+
TYPE_LITERAL = '__literal'
|
5
|
+
TYPE_COLLECTION = '__collection'
|
6
|
+
|
4
7
|
attr_reader :parent, :type, :value
|
5
8
|
|
6
9
|
def initialize(initializer, parent = nil, key = nil)
|
@@ -39,7 +42,7 @@ module Jievro
|
|
39
42
|
|
40
43
|
def value
|
41
44
|
fail Exception, 'Cannot get value from a non literal node' \
|
42
|
-
unless @type ==
|
45
|
+
unless @type == TYPE_LITERAL
|
43
46
|
|
44
47
|
@value
|
45
48
|
end
|
@@ -49,14 +52,14 @@ module Jievro
|
|
49
52
|
end
|
50
53
|
|
51
54
|
def each
|
52
|
-
each_with_index do |v,
|
55
|
+
each_with_index do |v, _|
|
53
56
|
yield v
|
54
57
|
end
|
55
58
|
end
|
56
59
|
|
57
60
|
def each_with_index
|
58
|
-
fail Exception, 'Cannot
|
59
|
-
if @type ==
|
61
|
+
fail Exception, 'Cannot iterate a literal node' \
|
62
|
+
if @type == TYPE_LITERAL
|
60
63
|
|
61
64
|
@value.keys.each do |v|
|
62
65
|
yield @value[v], v
|
@@ -67,12 +70,12 @@ module Jievro
|
|
67
70
|
|
68
71
|
def initialize_as_literal(initializer)
|
69
72
|
@value = initializer
|
70
|
-
@type =
|
73
|
+
@type = TYPE_LITERAL
|
71
74
|
end
|
72
75
|
|
73
76
|
def initialize_as_array(initializer)
|
74
77
|
@value = {}
|
75
|
-
@type =
|
78
|
+
@type = TYPE_COLLECTION
|
76
79
|
|
77
80
|
initializer.each_with_index do |e, i|
|
78
81
|
@value[i] = Node.new(e, self, i)
|
data/lib/jievro/ast/version.rb
CHANGED