sequitur 0.1.23 → 0.1.24
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/.rubocop.yml +11 -437
- data/CHANGELOG.md +3 -0
- data/LICENSE.txt +1 -1
- data/Rakefile +0 -2
- data/examples/integer_sample.rb +0 -1
- data/examples/porridge.rb +9 -9
- data/examples/word_sample.rb +4 -5
- data/lib/sequitur/constants.rb +4 -1
- data/lib/sequitur/digram.rb +2 -2
- data/lib/sequitur/dynamic_grammar.rb +3 -4
- data/lib/sequitur/formatter/base_formatter.rb +1 -1
- data/lib/sequitur/formatter/base_text.rb +3 -7
- data/lib/sequitur/formatter/debug.rb +0 -1
- data/lib/sequitur/grammar_visitor.rb +1 -1
- data/lib/sequitur/production.rb +200 -205
- data/lib/sequitur/production_ref.rb +9 -12
- data/lib/sequitur/sequitur_grammar.rb +135 -137
- data/lib/sequitur/symbol_sequence.rb +24 -27
- data/lib/sequitur.rb +4 -5
- data/spec/sequitur/digram_spec.rb +13 -12
- data/spec/sequitur/dynamic_grammar_spec.rb +5 -11
- data/spec/sequitur/formatter/base_text_spec.rb +70 -72
- data/spec/sequitur/formatter/debug_spec.rb +90 -92
- data/spec/sequitur/grammar_visitor_spec.rb +70 -71
- data/spec/sequitur/production_ref_spec.rb +92 -92
- data/spec/sequitur/production_spec.rb +30 -34
- data/spec/sequitur/sequitur_grammar_spec.rb +47 -46
- data/spec/sequitur/symbol_sequence_spec.rb +102 -105
- data/spec/spec_helper.rb +0 -1
- metadata +4 -5
- data/.travis.yml +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1ba8348f20a1e800b1c7001090916dbe05159177471452fdcfa8925bc975431
|
4
|
+
data.tar.gz: a8002cab5a1f7ae7b20b347f4a5f79e92a2f979dca1fad2dad83e153f5969d22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a116b242f218d0c08740a0432b641f88dbaa7f65dd67b02a5339be208927c835db4965d6e3ede344d7d93a4bbea6d4468692c4b237f1f18a8bbd3f6ffb54037
|
7
|
+
data.tar.gz: 2b7ea3e4acf58cb45ed3c0b7081a35201c2a8aa5285e163e9845fd82f082e7dcfb563a063d566c2561bb81944cefec6a67d0d2203b2080cb12fd73f6ace3c53e
|
data/.rubocop.yml
CHANGED
@@ -1,456 +1,30 @@
|
|
1
1
|
AllCops:
|
2
2
|
Exclude:
|
3
|
-
- 'exp/**/*'
|
4
3
|
- 'lab/**/*'
|
5
|
-
|
6
|
-
Gemspec/DateAssignment:
|
7
|
-
Enabled: true
|
8
|
-
|
9
|
-
Layout/ArgumentAlignment:
|
10
|
-
Enabled: false
|
11
|
-
|
12
|
-
Layout/ArrayAlignment:
|
13
|
-
Enabled: true
|
14
|
-
EnforcedStyle: with_fixed_indentation
|
15
|
-
|
16
|
-
Layout/CaseIndentation:
|
17
|
-
Enabled: false
|
18
|
-
|
19
|
-
Layout/ClosingHeredocIndentation:
|
20
|
-
Enabled: false
|
21
|
-
|
22
|
-
Layout/CommentIndentation:
|
23
|
-
Enabled: false
|
24
|
-
|
25
|
-
Layout/ElseAlignment:
|
26
|
-
Enabled: false
|
27
|
-
|
28
|
-
Layout/EmptyLines:
|
29
|
-
Enabled: false
|
30
|
-
|
31
|
-
Layout/EndAlignment:
|
32
|
-
Enabled: false
|
33
|
-
|
4
|
+
|
34
5
|
Layout/EndOfLine:
|
35
|
-
Enabled:
|
36
|
-
EnforcedStyle: lf
|
37
|
-
|
38
|
-
Layout/FirstArgumentIndentation:
|
39
|
-
Enabled: false
|
40
|
-
|
41
|
-
Layout/HashAlignment:
|
42
|
-
Enabled: false
|
43
|
-
|
44
|
-
Layout/IndentationWidth:
|
45
|
-
Enabled: false
|
46
|
-
|
47
|
-
Layout/IndentationConsistency:
|
48
|
-
Enabled: true
|
49
|
-
|
50
|
-
Layout/HeredocIndentation:
|
51
|
-
Enabled: false
|
52
|
-
|
53
|
-
Layout/LineEndStringConcatenationIndentation:
|
54
|
-
Enabled: true
|
55
|
-
|
56
|
-
Layout/MultilineHashBraceLayout:
|
57
|
-
Enabled: true
|
58
|
-
|
59
|
-
Layout/MultilineMethodCallBraceLayout:
|
60
|
-
Enabled: true
|
61
|
-
EnforcedStyle: same_line
|
62
|
-
|
63
|
-
Layout/SpaceAroundOperators:
|
64
|
-
Enabled: true
|
65
|
-
|
66
|
-
Layout/SpaceBeforeBrackets:
|
67
|
-
Enabled: true
|
68
|
-
|
69
|
-
Layout/SpaceInsideParens:
|
70
|
-
Enabled: true
|
71
|
-
|
72
|
-
Layout/IndentationStyle:
|
73
|
-
Enabled: true
|
74
|
-
|
75
|
-
Layout/SpaceAroundMethodCallOperator:
|
76
|
-
Enabled: true
|
77
|
-
|
78
|
-
Layout/TrailingEmptyLines:
|
79
|
-
Enabled: true
|
80
|
-
|
81
|
-
Layout/TrailingWhitespace:
|
82
|
-
Enabled: true
|
83
|
-
|
84
|
-
Lint/AmbiguousAssignment:
|
85
|
-
Enabled: true
|
86
|
-
|
87
|
-
Lint/AmbiguousRange:
|
88
|
-
Enabled: true
|
89
|
-
|
90
|
-
Lint/DeprecatedConstants:
|
91
|
-
Enabled: true
|
92
|
-
|
93
|
-
Lint/DuplicateBranch:
|
94
|
-
Enabled: true
|
95
|
-
|
96
|
-
Lint/DuplicateRegexpCharacterClassElement:
|
97
|
-
Enabled: true
|
98
|
-
|
99
|
-
Lint/EmptyBlock:
|
100
|
-
Enabled: true
|
101
|
-
|
102
|
-
Lint/EmptyClass:
|
103
|
-
Enabled: false
|
104
|
-
|
105
|
-
Lint/EmptyInPattern:
|
106
|
-
Enabled: true
|
107
|
-
|
108
|
-
Lint/LambdaWithoutLiteralBlock:
|
109
|
-
Enabled: true
|
110
|
-
|
111
|
-
Lint/Loop:
|
112
|
-
Enabled: true
|
113
|
-
|
114
|
-
Lint/NoReturnInBeginEndBlocks:
|
115
|
-
Enabled: true
|
116
|
-
|
117
|
-
Lint/NumberedParameterAssignment:
|
118
|
-
Enabled: true
|
119
|
-
|
120
|
-
Lint/OrAssignmentToConstant:
|
121
|
-
Enabled: true
|
122
|
-
|
123
|
-
Lint/RaiseException:
|
124
|
-
Enabled: true
|
125
|
-
|
126
|
-
Lint/RedundantDirGlobSort:
|
127
|
-
Enabled: true
|
128
|
-
|
129
|
-
Lint/RescueException:
|
130
|
-
Enabled: true
|
131
|
-
|
132
|
-
Lint/StructNewOverride:
|
133
|
-
Enabled: true
|
134
|
-
|
135
|
-
Lint/SymbolConversion:
|
136
|
-
Enabled: true
|
137
|
-
|
138
|
-
Lint/ToEnumArguments:
|
139
|
-
Enabled: true
|
140
|
-
|
141
|
-
Lint/TripleQuotes:
|
142
|
-
Enabled: true
|
143
|
-
|
144
|
-
Lint/UnexpectedBlockArity:
|
145
|
-
Enabled: true
|
146
|
-
|
147
|
-
Lint/UnmodifiedReduceAccumulator:
|
148
|
-
Enabled: true
|
149
|
-
|
150
|
-
Lint/UnusedMethodArgument:
|
151
|
-
Enabled: true
|
152
|
-
|
153
|
-
Lint/UselessAccessModifier:
|
154
|
-
Enabled: true
|
155
|
-
|
156
|
-
Lint/Void:
|
157
|
-
Enabled: false
|
158
|
-
|
159
|
-
Lint/UselessAssignment:
|
160
|
-
Enabled: true
|
6
|
+
Enabled: false # Make source portable!
|
161
7
|
|
162
8
|
Metrics/AbcSize:
|
163
|
-
|
164
|
-
|
165
|
-
Metrics/BlockLength:
|
166
|
-
Enabled: true
|
167
|
-
Max: 350
|
168
|
-
|
169
|
-
Metrics/BlockNesting:
|
170
|
-
Enabled: true
|
171
|
-
Max: 5
|
9
|
+
Max: 22
|
172
10
|
|
173
11
|
Metrics/ClassLength:
|
174
|
-
|
175
|
-
|
176
|
-
|
12
|
+
Max: 150
|
13
|
+
|
177
14
|
Metrics/CyclomaticComplexity:
|
178
|
-
|
179
|
-
|
180
|
-
Layout/LineLength:
|
181
|
-
Enabled: false
|
182
|
-
Max: 90
|
15
|
+
Max: 10
|
183
16
|
|
184
17
|
Metrics/MethodLength:
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
Metrics/ModuleLength:
|
189
|
-
Enabled: true
|
190
|
-
Max: 500
|
191
|
-
|
18
|
+
Max: 50
|
19
|
+
|
192
20
|
Metrics/PerceivedComplexity:
|
193
|
-
|
194
|
-
|
195
|
-
Naming/ConstantName:
|
196
|
-
Enabled: false
|
197
|
-
|
198
|
-
Naming/ClassAndModuleCamelCase:
|
199
|
-
Enabled: false
|
200
|
-
|
201
|
-
Naming/BlockParameterName:
|
202
|
-
Enabled: true
|
203
|
-
|
204
|
-
Naming/InclusiveLanguage:
|
205
|
-
Enabled: true
|
21
|
+
Max: 10
|
206
22
|
|
207
23
|
Naming/MethodParameterName:
|
208
24
|
Enabled: false
|
209
|
-
|
210
|
-
Naming/MethodName:
|
211
|
-
Enabled: false
|
212
|
-
|
25
|
+
|
213
26
|
Naming/VariableName:
|
214
27
|
Enabled: false
|
215
28
|
|
216
|
-
Style/AccessorGrouping:
|
217
|
-
Enabled: false
|
218
|
-
|
219
|
-
Style/Alias:
|
220
|
-
Enabled: true
|
221
|
-
|
222
|
-
Style/ArgumentsForwarding:
|
223
|
-
Enabled: true
|
224
|
-
|
225
|
-
Style/AsciiComments:
|
226
|
-
Enabled: false
|
227
|
-
|
228
|
-
Style/BarePercentLiterals:
|
229
|
-
Enabled: false
|
230
|
-
|
231
|
-
Style/BlockComments:
|
232
|
-
Enabled: false
|
233
|
-
|
234
|
-
Style/CharacterLiteral:
|
235
|
-
Enabled: false
|
236
|
-
|
237
|
-
Style/ClassCheck:
|
238
|
-
Enabled: false
|
239
|
-
|
240
|
-
Style/ClassVars:
|
241
|
-
Enabled: false
|
242
|
-
|
243
|
-
Style/CollectionCompact:
|
244
|
-
Enabled: true
|
245
|
-
|
246
|
-
Style/ColonMethodCall:
|
247
|
-
Enabled: false
|
248
|
-
|
249
|
-
Style/CommentAnnotation:
|
250
|
-
Enabled: false
|
251
|
-
|
252
29
|
Style/CommentedKeyword:
|
253
|
-
Enabled: false
|
254
|
-
|
255
|
-
Style/ConditionalAssignment:
|
256
|
-
Enabled: false
|
257
|
-
|
258
|
-
Style/DefWithParentheses:
|
259
|
-
Enabled: true
|
260
|
-
|
261
|
-
Style/Documentation:
|
262
|
-
Enabled: false
|
263
|
-
|
264
|
-
Style/DocumentDynamicEvalDefinition:
|
265
|
-
Enabled: false
|
266
|
-
|
267
|
-
Style/EmptyElse:
|
268
|
-
Enabled: true
|
269
|
-
EnforcedStyle: empty
|
270
|
-
|
271
|
-
Style/ExpandPathArguments:
|
272
|
-
Enabled: false
|
273
|
-
|
274
|
-
Style/ExponentialNotation:
|
275
|
-
Enabled: true
|
276
|
-
|
277
|
-
Style/GuardClause:
|
278
|
-
Enabled: false
|
279
|
-
|
280
|
-
Style/HashEachMethods:
|
281
|
-
Enabled: true
|
282
|
-
|
283
|
-
Style/HashExcept:
|
284
|
-
Enabled: true
|
285
|
-
|
286
|
-
Style/HashTransformKeys:
|
287
|
-
Enabled: true
|
288
|
-
|
289
|
-
Style/HashTransformValues:
|
290
|
-
Enabled: true
|
291
|
-
|
292
|
-
Style/IfUnlessModifier:
|
293
|
-
Enabled: false
|
294
|
-
|
295
|
-
Style/InPatternThen:
|
296
|
-
Enabled: true
|
297
|
-
|
298
|
-
Style/InverseMethods:
|
299
|
-
Enabled: false
|
300
|
-
|
301
|
-
Style/MissingRespondToMissing:
|
302
|
-
Enabled: false
|
303
|
-
|
304
|
-
Style/MultilineInPatternThen:
|
305
|
-
Enabled: true
|
306
|
-
|
307
|
-
Style/NegatedIfElseCondition:
|
308
|
-
Enabled: true
|
309
|
-
|
310
|
-
Style/Next:
|
311
|
-
Enabled: false
|
312
|
-
|
313
|
-
Style/NilLambda:
|
314
|
-
Enabled: true
|
315
|
-
|
316
|
-
Style/NumericLiterals:
|
317
|
-
Enabled: false
|
318
|
-
|
319
|
-
Style/QuotedSymbols:
|
320
|
-
Enabled: true
|
321
|
-
|
322
|
-
Style/RaiseArgs:
|
323
|
-
Enabled: true
|
324
|
-
|
325
|
-
Style/RedundantArgument:
|
326
|
-
Enabled: true
|
327
|
-
|
328
|
-
Style/RedundantReturn:
|
329
|
-
Enabled: false
|
330
|
-
|
331
|
-
Style/RedundantSelf:
|
332
|
-
Enabled: true
|
333
|
-
|
334
|
-
Style/RedundantSelfAssignmentBranch:
|
335
|
-
Enabled: true
|
336
|
-
|
337
|
-
Style/RegexpLiteral:
|
338
|
-
Enabled: false
|
339
|
-
|
340
|
-
Style/PercentLiteralDelimiters:
|
341
|
-
Enabled: false
|
342
|
-
|
343
|
-
Style/StderrPuts:
|
344
|
-
Enabled: false
|
345
|
-
|
346
|
-
Style/StringLiterals:
|
347
|
-
Enabled: true
|
348
|
-
|
349
|
-
Style/SwapValues:
|
350
|
-
Enabled: true
|
351
|
-
|
352
|
-
Style/TernaryParentheses:
|
353
|
-
Enabled: false
|
354
|
-
|
355
|
-
Style/UnlessElse:
|
356
|
-
Enabled: false
|
357
|
-
|
358
|
-
# Rubocop complains when it doesn't find an explicit setting for the following cops:
|
359
|
-
Layout/EmptyLinesAroundAttributeAccessor:
|
360
|
-
Enabled: true
|
361
|
-
|
362
|
-
Lint/BinaryOperatorWithIdenticalOperands:
|
363
|
-
Enabled: true
|
364
|
-
|
365
|
-
Lint/DeprecatedOpenSSLConstant:
|
366
|
-
Enabled: true
|
367
|
-
|
368
|
-
Lint/DuplicateElsifCondition:
|
369
|
-
Enabled: true
|
370
|
-
|
371
|
-
Lint/DuplicateRescueException:
|
372
|
-
Enabled: true
|
373
|
-
|
374
|
-
Lint/EmptyConditionalBody:
|
375
|
-
Enabled: true
|
376
|
-
|
377
|
-
Lint/FloatComparison:
|
378
|
-
Enabled: true
|
379
|
-
|
380
|
-
Lint/MissingSuper:
|
381
|
-
Enabled: true
|
382
|
-
|
383
|
-
Lint/MixedRegexpCaptureTypes:
|
384
|
-
Enabled: true
|
385
|
-
|
386
|
-
Lint/OutOfRangeRegexpRef:
|
387
|
-
Enabled: true
|
388
|
-
|
389
|
-
Lint/SelfAssignment:
|
390
|
-
Enabled: true
|
391
|
-
|
392
|
-
Lint/TopLevelReturnWithArgument:
|
393
|
-
Enabled: true
|
394
|
-
|
395
|
-
Lint/UnreachableLoop:
|
396
|
-
Enabled: true
|
397
|
-
|
398
|
-
Style/ArrayCoercion:
|
399
|
-
Enabled: true
|
400
|
-
|
401
|
-
Style/BisectedAttrAccessor:
|
402
|
-
Enabled: true
|
403
|
-
|
404
|
-
Style/CaseLikeIf:
|
405
|
-
Enabled: true
|
406
|
-
|
407
|
-
Style/EndlessMethod:
|
408
|
-
Enabled: true
|
409
|
-
|
410
|
-
Style/ExplicitBlockArgument:
|
411
|
-
Enabled: true
|
412
|
-
|
413
|
-
Style/GlobalStdStream:
|
414
|
-
Enabled: true
|
415
|
-
|
416
|
-
Style/HashAsLastArrayItem:
|
417
|
-
Enabled: true
|
418
|
-
|
419
|
-
Style/HashConversion:
|
420
|
-
Enabled: true
|
421
|
-
|
422
|
-
Style/HashLikeCase:
|
423
|
-
Enabled: true
|
424
|
-
|
425
|
-
Style/IfWithBooleanLiteralBranches:
|
426
|
-
Enabled: true
|
427
|
-
|
428
|
-
Style/OptionalBooleanParameter:
|
429
|
-
Enabled: true
|
430
|
-
|
431
|
-
Style/RedundantAssignment:
|
432
|
-
Enabled: true
|
433
|
-
|
434
|
-
Style/RedundantFetchBlock:
|
435
|
-
Enabled: true
|
436
|
-
|
437
|
-
Style/RedundantFileExtensionInRequire:
|
438
|
-
Enabled: true
|
439
|
-
|
440
|
-
Style/RedundantRegexpCharacterClass:
|
441
|
-
Enabled: true
|
442
|
-
|
443
|
-
Style/RedundantRegexpEscape:
|
444
|
-
Enabled: true
|
445
|
-
|
446
|
-
Style/SingleArgumentDig:
|
447
|
-
Enabled: true
|
448
|
-
|
449
|
-
Style/SlicingWithRange:
|
450
|
-
Enabled: true
|
451
|
-
|
452
|
-
Style/StringChars:
|
453
|
-
Enabled: true
|
454
|
-
|
455
|
-
Style/StringConcatenation:
|
456
|
-
Enabled: true
|
30
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
data/Rakefile
CHANGED
data/examples/integer_sample.rb
CHANGED
@@ -10,7 +10,6 @@ input_sequence = [1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5]
|
|
10
10
|
# Generate the grammar from the sequence
|
11
11
|
grammar = Sequitur.build_from(input_sequence)
|
12
12
|
|
13
|
-
|
14
13
|
# Use a formatter to display the grammar rules on the console output
|
15
14
|
formatter = Sequitur::Formatter::BaseText.new($stdout)
|
16
15
|
|
data/examples/porridge.rb
CHANGED
@@ -3,16 +3,16 @@
|
|
3
3
|
require 'sequitur' # Load the Sequitur library
|
4
4
|
|
5
5
|
# Purpose: demo to show that sequitur gem works on example from sequitur.info website
|
6
|
-
input_sequence =
|
7
|
-
pease porridge hot,
|
8
|
-
pease porridge cold,
|
9
|
-
pease porridge in the pot,
|
10
|
-
nine days old.
|
6
|
+
input_sequence = <<~SNIPPET
|
7
|
+
pease porridge hot,
|
8
|
+
pease porridge cold,
|
9
|
+
pease porridge in the pot,
|
10
|
+
nine days old.
|
11
11
|
|
12
|
-
some like it hot,
|
13
|
-
some like it cold,
|
14
|
-
some like it in the pot,
|
15
|
-
nine days old.
|
12
|
+
some like it hot,
|
13
|
+
some like it cold,
|
14
|
+
some like it in the pot,
|
15
|
+
nine days old.
|
16
16
|
SNIPPET
|
17
17
|
|
18
18
|
grammar = Sequitur.build_from(input_sequence)
|
data/examples/word_sample.rb
CHANGED
@@ -7,10 +7,10 @@ require 'sequitur' # Load the Sequitur library
|
|
7
7
|
#
|
8
8
|
|
9
9
|
# Raw input is one String containing repeated sentences...
|
10
|
-
raw_input =
|
11
|
-
Error: unknown character '?' at position 6
|
12
|
-
Error: illegal character '%' at position 20
|
13
|
-
Error: unknown character '/' at position 9
|
10
|
+
raw_input = <<~SNIPPET
|
11
|
+
Error: unknown character '?' at position 6
|
12
|
+
Error: illegal character '%' at position 20
|
13
|
+
Error: unknown character '/' at position 9
|
14
14
|
SNIPPET
|
15
15
|
|
16
16
|
# Convert into a sequence of words
|
@@ -18,7 +18,6 @@ input_sequence = raw_input.scan(/\w+/)
|
|
18
18
|
# Generate the grammar from the sequence
|
19
19
|
grammar = Sequitur.build_from(input_sequence)
|
20
20
|
|
21
|
-
|
22
21
|
# Use a formatter to display the grammar rules on the console output
|
23
22
|
formatter = Sequitur::Formatter::BaseText.new($stdout)
|
24
23
|
|
data/lib/sequitur/constants.rb
CHANGED
@@ -4,8 +4,10 @@
|
|
4
4
|
# Purpose: definition of Sequitur constants.
|
5
5
|
|
6
6
|
module Sequitur # Module used as a namespace
|
7
|
+
# rubocop:disable Naming/ConstantName
|
8
|
+
|
7
9
|
# The version number of the gem.
|
8
|
-
Version = '0.1.
|
10
|
+
Version = '0.1.24'
|
9
11
|
|
10
12
|
# Brief description of the gem.
|
11
13
|
Description = 'Ruby implementation of the Sequitur algorithm'
|
@@ -23,6 +25,7 @@ module Sequitur # Module used as a namespace
|
|
23
25
|
"#{startdir}/" # Append trailing slash character to it
|
24
26
|
end
|
25
27
|
end
|
28
|
+
# rubocop:enable Naming/ConstantName
|
26
29
|
end # module
|
27
30
|
|
28
31
|
# End of file
|
data/lib/sequitur/digram.rb
CHANGED
@@ -37,13 +37,13 @@ module Sequitur # Module for classes implementing the Sequitur algorithm
|
|
37
37
|
# @param other [Digram] another to compare with
|
38
38
|
# @return [true/false]
|
39
39
|
def ==(other)
|
40
|
-
|
40
|
+
key == other.key
|
41
41
|
end
|
42
42
|
|
43
43
|
# Does the digram consists of twice the same symbols?
|
44
44
|
# @return [true/false] true when symbols.first == symbols.last
|
45
45
|
def repeating?
|
46
|
-
|
46
|
+
symbols[0] == symbols[1]
|
47
47
|
end
|
48
48
|
end # class
|
49
49
|
end # module
|
@@ -34,8 +34,7 @@ module Sequitur # Module for classes implementing the Sequitur algorithm
|
|
34
34
|
# Each production rule is emitted per line.
|
35
35
|
# @return [String]
|
36
36
|
def to_string
|
37
|
-
|
38
|
-
return rule_text
|
37
|
+
productions.map(&:to_string).join("\n")
|
39
38
|
end
|
40
39
|
|
41
40
|
# Add a given production to the grammar.
|
@@ -58,7 +57,7 @@ module Sequitur # Module for classes implementing the Sequitur algorithm
|
|
58
57
|
puts("Removed: #{prod.to_string}") if trace
|
59
58
|
prod.clear_rhs
|
60
59
|
|
61
|
-
|
60
|
+
prod
|
62
61
|
end
|
63
62
|
|
64
63
|
# Add the given token to the grammar.
|
@@ -83,7 +82,7 @@ module Sequitur # Module for classes implementing the Sequitur algorithm
|
|
83
82
|
# Factory method. Returns a visitor for this grammar.
|
84
83
|
# @return [GrammarVisitor]
|
85
84
|
def visitor
|
86
|
-
|
85
|
+
GrammarVisitor.new(self)
|
87
86
|
end
|
88
87
|
|
89
88
|
protected
|
@@ -19,7 +19,7 @@ module Sequitur
|
|
19
19
|
# and render the visit events in the output stream.
|
20
20
|
# @param aGrmOrVisitor [DynamicGrammar or GrammarVisitor]
|
21
21
|
def render(aGrmOrVisitor)
|
22
|
-
a_visitor = if aGrmOrVisitor.
|
22
|
+
a_visitor = if aGrmOrVisitor.is_a?(GrammarVisitor)
|
23
23
|
aGrmOrVisitor
|
24
24
|
else
|
25
25
|
aGrmOrVisitor.visitor
|
@@ -12,6 +12,8 @@ module Sequitur
|
|
12
12
|
# # Render the grammar (through a visitor)
|
13
13
|
# formatter.run(some_grammar.visitor)
|
14
14
|
class BaseText < BaseFormatter
|
15
|
+
attr_reader :prod_lookup
|
16
|
+
|
15
17
|
# Constructor.
|
16
18
|
# @param anIO [IO] The output stream to which the rendered grammar
|
17
19
|
# is written.
|
@@ -73,17 +75,11 @@ module Sequitur
|
|
73
75
|
|
74
76
|
private
|
75
77
|
|
76
|
-
# Read accessor of the production lookup
|
77
|
-
def prod_lookup
|
78
|
-
return @prod_lookup
|
79
|
-
end
|
80
|
-
|
81
78
|
# Generate a name of a given production.
|
82
79
|
# @param aProduction [Production]
|
83
80
|
def prod_name(aProduction)
|
84
81
|
prod_index = prod_lookup[aProduction]
|
85
|
-
|
86
|
-
return name
|
82
|
+
prod_index.zero? ? 'start' : "P#{prod_index}"
|
87
83
|
end
|
88
84
|
end # class
|
89
85
|
end # module
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Sequitur # Module for classes implementing the Sequitur algorithm
|
4
|
-
# A visitor class dedicated in the visit of Grammar.
|
4
|
+
# A visitor class dedicated in the visit of Grammar.
|
5
5
|
class GrammarVisitor
|
6
6
|
# Link to the grammar to visit
|
7
7
|
attr_reader(:grammar)
|