yoga 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -1
- data/lib/yoga/parser/helpers.rb +8 -10
- data/lib/yoga/scanner.rb +2 -2
- data/lib/yoga/utils.rb +5 -16
- data/lib/yoga/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: d47b133334a8a84e8376462babbbe7ead6a966bd
|
4
|
+
data.tar.gz: d2b5d18e263caf245c93677658dadb1c5c66f36b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd9eb5267207071585e630dcf03186a0e7f8ac748b578fc207330a2560544f649573d7ebe299fe4820ec53a473e01fc2980048b9484979fb9cb5781b2576fb32
|
7
|
+
data.tar.gz: 14c809c089f72ddfd86d64dad0d4834d6d7faabfe0386efcc487550c0c4615cb81ee5c6cd1bced90b92bf462a6182a040737d81567079b64d602116ffb91d57b
|
data/.rubocop.yml
CHANGED
data/lib/yoga/parser/helpers.rb
CHANGED
@@ -173,8 +173,8 @@ module Yoga
|
|
173
173
|
# @return [::Array] The collected nodes from the yielding process.
|
174
174
|
def collect(ending, join = nil)
|
175
175
|
children = []
|
176
|
-
join = Utils.flatten_into_set(
|
177
|
-
ending = Utils.flatten_into_set(
|
176
|
+
join = Utils.flatten_into_set(join) if join
|
177
|
+
ending = Utils.flatten_into_set(ending) if ending
|
178
178
|
|
179
179
|
return [] if (ending && peek?(ending)) || (!ending && !join)
|
180
180
|
|
@@ -196,9 +196,8 @@ module Yoga
|
|
196
196
|
#
|
197
197
|
# @param tokens [<::Symbol>] The possible kinds.
|
198
198
|
# @return [::Boolean]
|
199
|
-
def peek?(
|
200
|
-
|
201
|
-
tokens.include?(peek.kind)
|
199
|
+
def peek?(tokens)
|
200
|
+
Utils.flatten_into_set(tokens).include?(peek.kind)
|
202
201
|
end
|
203
202
|
|
204
203
|
# Peeks out to a specific point in the future to match. This is an
|
@@ -210,8 +209,7 @@ module Yoga
|
|
210
209
|
# @param tokens [<::Symbol>] The kinds of tokens to check for.
|
211
210
|
# @return [::Boolean]
|
212
211
|
def peek_out?(to, tokens)
|
213
|
-
|
214
|
-
tokens.include?(peek_out(to).kind)
|
212
|
+
Utils.flatten_into_set(tokens).include?(peek_out(to).kind)
|
215
213
|
end
|
216
214
|
|
217
215
|
# Shifts to the next token, and returns the old token.
|
@@ -229,10 +227,10 @@ module Yoga
|
|
229
227
|
#
|
230
228
|
# @param tokens [<::Symbol>] The expected tokens.
|
231
229
|
# @return [Yoga::Token]
|
232
|
-
def expect(
|
230
|
+
def expect(tokens)
|
233
231
|
tokens = Utils.flatten_into_set(tokens)
|
234
|
-
return shift if peek?(
|
235
|
-
error(tokens
|
232
|
+
return shift if peek?(tokens)
|
233
|
+
error(tokens)
|
236
234
|
end
|
237
235
|
|
238
236
|
# Retrieves the first set for the given node name.
|
data/lib/yoga/scanner.rb
CHANGED
@@ -171,8 +171,8 @@ module Yoga
|
|
171
171
|
def update_line_information
|
172
172
|
return unless (lines = @scanner[0].scan(LINE)).any?
|
173
173
|
@line += lines.size
|
174
|
-
@
|
175
|
-
|
174
|
+
line_index = @scanner.string.rindex(LINE, @scanner.charpos)
|
175
|
+
@last_line_at = line_index < 0 ? 0 : line_index + 1
|
176
176
|
end
|
177
177
|
end
|
178
178
|
end
|
data/lib/yoga/utils.rb
CHANGED
@@ -15,22 +15,11 @@ module Yoga
|
|
15
15
|
# The array to flatten into a set.
|
16
16
|
# @return [::Set<Yoga::Token>]
|
17
17
|
def flatten_into_set(tokens)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
#
|
24
|
-
# @param tokens [<Yoga::Token>, ::Set<Yoga::Token>, ::Enumerable]
|
25
|
-
# The array to flatten into a set.
|
26
|
-
# @return [<Yoga::Token>]
|
27
|
-
def flatten_into_array(tokens)
|
28
|
-
tokens.flat_map do |part|
|
29
|
-
if part.is_a?(::Enumerable)
|
30
|
-
flatten_into_array(part)
|
31
|
-
else
|
32
|
-
part
|
33
|
-
end
|
18
|
+
case tokens
|
19
|
+
when ::Set then tokens
|
20
|
+
when ::Array then ::Set.new(tokens)
|
21
|
+
else
|
22
|
+
::Set.new(tokens.to_a)
|
34
23
|
end
|
35
24
|
end
|
36
25
|
end
|
data/lib/yoga/version.rb
CHANGED