twisty_puzzles 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/twisty_puzzles/parser.rb +53 -10
- data/lib/twisty_puzzles/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20cf60d5066716b3eaa148e33f1e8c598387573170e1005d034f3128e6b971cb
|
4
|
+
data.tar.gz: 2770afd2a3a625f281089401c2a2ef47a6c61843d09026e9d999ee79139fe54e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bdf4691d6efea522b259510bcdb405820784870566948d47b653c91e2d8ca495d9946e17f0d9f703ee234bf0758b3a59969dc52e4f91eafa94659c624ac3930
|
7
|
+
data.tar.gz: b28d42481604cbec6b748b025a3293eed64e2c7a90b0e6186c6eadeed63352f81b562e835f54bf6b4fbc9905bf047c917b269896c5504628c7d9c7352c1b70ec
|
@@ -77,8 +77,8 @@ module TwistyPuzzles # rubocop:disable Style/Documentation
|
|
77
77
|
end
|
78
78
|
|
79
79
|
# Parses at least one move.
|
80
|
-
def
|
81
|
-
moves =
|
80
|
+
def parse_nonempty_moves_with_triggers
|
81
|
+
moves = parse_moves_with_triggers
|
82
82
|
complain('move') if moves.empty?
|
83
83
|
moves
|
84
84
|
end
|
@@ -117,10 +117,26 @@ module TwistyPuzzles # rubocop:disable Style/Documentation
|
|
117
117
|
if @scanner.peek(1) == OPENING_BRACKET
|
118
118
|
parse_commutator_internal
|
119
119
|
else
|
120
|
-
|
120
|
+
parse_commutator_no_brackets
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
+
def parse_commutator_no_brackets
|
125
|
+
setup_or_first_part_or_algorithm = parse_moves_with_triggers
|
126
|
+
skip_spaces
|
127
|
+
if @scanner.eos? || !SEPARATORS.include?(@scanner.peek(1))
|
128
|
+
return FakeCommutator.new(setup_or_first_part_or_algorithm)
|
129
|
+
end
|
130
|
+
|
131
|
+
setup_or_first_part = setup_or_first_part_or_algorithm
|
132
|
+
complain('move') if setup_or_first_part.empty?
|
133
|
+
separator = parse_separator
|
134
|
+
comm = parse_commutator_internal_after_separator(setup_or_first_part, separator)
|
135
|
+
skip_spaces
|
136
|
+
complain('end of commutator') unless @scanner.eos?
|
137
|
+
comm
|
138
|
+
end
|
139
|
+
|
124
140
|
def parse_algorithm
|
125
141
|
skip_spaces
|
126
142
|
parse_moves_with_triggers
|
@@ -131,40 +147,67 @@ module TwistyPuzzles # rubocop:disable Style/Documentation
|
|
131
147
|
if @scanner.peek(1) == OPENING_BRACKET
|
132
148
|
parse_pure_commutator
|
133
149
|
else
|
134
|
-
|
150
|
+
parse_pure_commutator_no_brackets
|
135
151
|
end
|
136
152
|
end
|
137
153
|
|
138
154
|
def parse_pure_commutator
|
139
155
|
skip_spaces
|
140
156
|
parse_open_bracket
|
141
|
-
first_part =
|
157
|
+
first_part = parse_nonempty_moves_with_triggers
|
142
158
|
skip_spaces
|
143
|
-
|
144
|
-
second_part =
|
159
|
+
parse_comma
|
160
|
+
second_part = parse_nonempty_moves_with_triggers
|
145
161
|
skip_spaces
|
146
162
|
parse_close_bracket
|
147
163
|
PureCommutator.new(first_part, second_part)
|
148
164
|
end
|
149
165
|
|
166
|
+
def parse_pure_commutator_no_brackets
|
167
|
+
first_part_or_algorithm = parse_moves_with_triggers
|
168
|
+
skip_spaces
|
169
|
+
if @scanner.eos? || !@scanner.peek(1) == ','
|
170
|
+
return FakeCommutator.new(first_part_or_algorithm)
|
171
|
+
end
|
172
|
+
|
173
|
+
first_part = first_part_or_algorithm
|
174
|
+
complain('move') if first_part.empty?
|
175
|
+
parse_comma
|
176
|
+
second_part = parse_nonempty_moves_with_triggers
|
177
|
+
skip_spaces
|
178
|
+
PureCommutator.new(first_part, second_part)
|
179
|
+
end
|
180
|
+
|
181
|
+
def parse_comma
|
182
|
+
complain('middle of pure commutator') unless @scanner.getch == ','
|
183
|
+
end
|
184
|
+
|
150
185
|
def parse_commutator_internal_after_separator(setup_or_first_part, separator)
|
151
186
|
if [':', ';'].include?(separator)
|
152
187
|
inner_commutator = parse_setup_commutator_inner
|
153
188
|
SetupCommutator.new(setup_or_first_part, inner_commutator)
|
154
189
|
elsif separator == ','
|
155
|
-
second_part =
|
190
|
+
second_part = parse_nonempty_moves_with_triggers
|
156
191
|
PureCommutator.new(setup_or_first_part, second_part)
|
157
192
|
else
|
158
193
|
complain('end of setup or middle of pure commutator') unless @scanner.eos?
|
159
194
|
end
|
160
195
|
end
|
161
196
|
|
197
|
+
SEPARATORS = %w[; : ,].freeze
|
198
|
+
|
199
|
+
def parse_separator
|
200
|
+
separator = @scanner.getch
|
201
|
+
complain('separator between commutator parts') unless SEPARATORS.include?(separator)
|
202
|
+
separator
|
203
|
+
end
|
204
|
+
|
162
205
|
def parse_commutator_internal
|
163
206
|
skip_spaces
|
164
207
|
parse_open_bracket
|
165
|
-
setup_or_first_part =
|
208
|
+
setup_or_first_part = parse_nonempty_moves_with_triggers
|
166
209
|
skip_spaces
|
167
|
-
separator =
|
210
|
+
separator = parse_separator
|
168
211
|
comm = parse_commutator_internal_after_separator(setup_or_first_part, separator)
|
169
212
|
skip_spaces
|
170
213
|
parse_close_bracket
|