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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78089ff494b1a687a567d483eb155e9891c69a991e8f4b045bf024e7365c58df
4
- data.tar.gz: 820b61382a22d1c283f552ee637507dd9a511efa1d7f66656decd64f67304c8b
3
+ metadata.gz: 20cf60d5066716b3eaa148e33f1e8c598387573170e1005d034f3128e6b971cb
4
+ data.tar.gz: 2770afd2a3a625f281089401c2a2ef47a6c61843d09026e9d999ee79139fe54e
5
5
  SHA512:
6
- metadata.gz: 063d2c8607b7d7708d0dea3fa78eebe3a883135cf2e2a46e5db7d5e0b80f6d21dd084b7a554718b54d45866eeecddf784857eb247a4a1de4ac924b8293aedd50
7
- data.tar.gz: 9dff522e48073f756d4aa0e2377ff754b8fbefe0caaf8fb830383e47d14be7bb354e55c1ef2355fca1259dc255002e732f5089bd9269727973e2979de6a9d6e2
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 parse_nonempty_moves
81
- moves = parse_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
- FakeCommutator.new(parse_moves_with_triggers)
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
- FakeCommutator.new(parse_moves_with_triggers)
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 = parse_nonempty_moves
157
+ first_part = parse_nonempty_moves_with_triggers
142
158
  skip_spaces
143
- complain('middle of pure commutator') unless @scanner.getch == ','
144
- second_part = parse_nonempty_moves
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 = parse_nonempty_moves
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 = parse_nonempty_moves
208
+ setup_or_first_part = parse_nonempty_moves_with_triggers
166
209
  skip_spaces
167
- separator = @scanner.getch
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TwistyPuzzles
4
- VERSION = '0.0.12'
4
+ VERSION = '0.0.13'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twisty_puzzles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernhard F. Brodowsky