truth_serum 0.4.2 → 0.4.3
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/lib/truth_serum/lexer.rb +4 -1
- data/lib/truth_serum/parser.rb +12 -26
- data/lib/truth_serum/token.rb +8 -0
- data/lib/truth_serum/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 590e540a36b34b56954e0faf0fba315eb8042a6b
|
4
|
+
data.tar.gz: f833f7c7ac478dbf6c9734df218645bfc2d5dd1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 738641475d633e50d67471307cd8ecf1e871aa5219bd64e15ae0714872e50ea1ac279dce7e2414e18c917ea4d3e63ff865cd7dc610a57ee79dd42e6c1fdce4a6
|
7
|
+
data.tar.gz: f5ddc48b3fff0bd64cfd70f8ea10564aad0950967735eb18c19b07ae50fcc6a39537d46ede6186e15d1ef0629a6de55bb880a755676bbb74476c9db9c270e89a
|
data/lib/truth_serum/lexer.rb
CHANGED
@@ -82,6 +82,8 @@ module TruthSerum
|
|
82
82
|
append("\r")
|
83
83
|
when 'n'
|
84
84
|
append("\n")
|
85
|
+
when nil
|
86
|
+
append('\\') # EOF, treat preceding \ as literal
|
85
87
|
else # '\\' '"' and everything else is passed verbatim
|
86
88
|
append(char)
|
87
89
|
end
|
@@ -98,7 +100,8 @@ module TruthSerum
|
|
98
100
|
end
|
99
101
|
|
100
102
|
def emit(type)
|
101
|
-
|
103
|
+
@buffer ||= ''
|
104
|
+
super(Token.new(type, @buffer))
|
102
105
|
@buffer = nil
|
103
106
|
end
|
104
107
|
end
|
data/lib/truth_serum/parser.rb
CHANGED
@@ -8,19 +8,15 @@ module TruthSerum
|
|
8
8
|
# convert result stream to hash
|
9
9
|
def execute
|
10
10
|
@negate = false
|
11
|
-
|
11
|
+
@hash = {
|
12
12
|
terms: [],
|
13
13
|
negative_terms: [],
|
14
14
|
filters: {},
|
15
15
|
negative_filters: {}
|
16
16
|
}
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
result = merge_result(result, stream.shift)
|
21
|
-
end
|
22
|
-
|
23
|
-
result
|
18
|
+
super
|
19
|
+
@hash
|
24
20
|
end
|
25
21
|
|
26
22
|
state :start do
|
@@ -109,32 +105,22 @@ module TruthSerum
|
|
109
105
|
type = @negate ? :negative_terms : :terms
|
110
106
|
@negate = false
|
111
107
|
|
112
|
-
|
108
|
+
if @hash.key?(type)
|
109
|
+
@hash[type] << term
|
110
|
+
else
|
111
|
+
@hash[type] = [term]
|
112
|
+
end
|
113
113
|
end
|
114
114
|
|
115
115
|
def emit_filter(key, value)
|
116
116
|
type = @negate ? :negative_filters : :filters
|
117
117
|
@negate = false
|
118
118
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
def merge_result(x, y)
|
124
|
-
result = x.merge({})
|
125
|
-
y.each do |key, value|
|
126
|
-
if result.key?(key)
|
127
|
-
if value.is_a?(Hash)
|
128
|
-
result[key] = result[key].merge(value)
|
129
|
-
elsif value.is_a?(Array)
|
130
|
-
result[key] = result[key] + value
|
131
|
-
end
|
132
|
-
else
|
133
|
-
result[key] = value
|
134
|
-
end
|
119
|
+
if @hash.key?(type)
|
120
|
+
@hash[type][key] = value
|
121
|
+
else
|
122
|
+
@hash[type] = { key => value }
|
135
123
|
end
|
136
|
-
|
137
|
-
result
|
138
124
|
end
|
139
125
|
end
|
140
126
|
end
|
data/lib/truth_serum/token.rb
CHANGED
data/lib/truth_serum/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: truth_serum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chakrit Wichian
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|