sequitur 0.1.22 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8120ed261178fac280e46bcd3cc35edf3717603031738349f5177114b9fe8bc0
4
- data.tar.gz: f799bff2dfaa09c0649e6416a789ab684e226e6eb1ccba974db8670932174050
3
+ metadata.gz: a1ba8348f20a1e800b1c7001090916dbe05159177471452fdcfa8925bc975431
4
+ data.tar.gz: a8002cab5a1f7ae7b20b347f4a5f79e92a2f979dca1fad2dad83e153f5969d22
5
5
  SHA512:
6
- metadata.gz: ec4f16080571ec66e2256898b0f414815d430484ef5221d53e99acf8982da870ddb4a459158005c6f52107ccf7ef52af0e55cdd8a2b4b9982ff6066e189651b0
7
- data.tar.gz: 95a95f2f8b5812e3e859b94909432d25f629682b1afa6aed8a6c17439d4e57b3d8abd055f3be3f4e4008a7927de22ee2201174f3ee602fd3c680623b7261c554
6
+ metadata.gz: 2a116b242f218d0c08740a0432b641f88dbaa7f65dd67b02a5339be208927c835db4965d6e3ede344d7d93a4bbea6d4468692c4b237f1f18a8bbd3f6ffb54037
7
+ data.tar.gz: 2b7ea3e4acf58cb45ed3c0b7081a35201c2a8aa5285e163e9845fd82f082e7dcfb563a063d566c2561bb81944cefec6a67d0d2203b2080cb12fd73f6ace3c53e
data/.rubocop.yml CHANGED
@@ -1,199 +1,30 @@
1
1
  AllCops:
2
2
  Exclude:
3
- - 'exp/**/*'
4
3
  - 'lab/**/*'
5
-
6
- Layout/CaseIndentation:
7
- Enabled: false
8
-
9
- Layout/ClosingHeredocIndentation:
10
- Enabled: false
11
-
12
- Layout/CommentIndentation:
13
- Enabled: false
14
-
15
- Layout/ElseAlignment:
16
- Enabled: false
17
-
18
- Layout/EmptyLines:
19
- Enabled: false
20
-
21
- Layout/EndAlignment:
22
- Enabled: false
23
-
4
+
24
5
  Layout/EndOfLine:
25
- Enabled: true
26
- EnforcedStyle: lf
27
-
28
- Layout/IndentationWidth:
29
- Enabled: false
30
-
31
- Layout/IndentationConsistency:
32
- Enabled: true
33
-
34
- Layout/IndentHeredoc:
35
- Enabled: false
36
-
37
- Layout/MultilineHashBraceLayout:
38
- Enabled: true
39
-
40
- Layout/SpaceAroundOperators:
41
- Enabled: true
42
-
43
- Layout/SpaceInsideParens:
44
- Enabled: true
45
-
46
- Layout/Tab:
47
- Enabled: true
48
-
49
- Layout/TrailingBlankLines:
50
- Enabled: true
51
-
52
- Layout/TrailingWhitespace:
53
- Enabled: true
54
-
55
- Lint/Loop:
56
- Enabled: true
57
-
58
- Lint/RescueException:
59
- Enabled: true
60
-
61
- Lint/UnusedMethodArgument:
62
- Enabled: true
63
-
64
- Lint/UselessAccessModifier:
65
- Enabled: true
66
-
67
- Lint/Void:
68
- Enabled: false
69
-
70
- Lint/UselessAssignment:
71
- Enabled: true
6
+ Enabled: false # Make source portable!
72
7
 
73
8
  Metrics/AbcSize:
74
- Enabled: false
75
-
76
- Metrics/BlockLength:
77
- Enabled: true
78
- Max: 350
9
+ Max: 22
79
10
 
80
11
  Metrics/ClassLength:
81
- Enabled: true
82
- Max: 350
83
-
12
+ Max: 150
13
+
84
14
  Metrics/CyclomaticComplexity:
85
- Enabled: false
86
-
87
- Metrics/LineLength:
88
- Enabled: false
89
- Max: 90
15
+ Max: 10
90
16
 
91
17
  Metrics/MethodLength:
92
- Enabled: true
93
- Max: 40
94
-
95
- Metrics/ModuleLength:
96
- Enabled: true
97
- Max: 500
98
-
18
+ Max: 50
19
+
99
20
  Metrics/PerceivedComplexity:
100
- Enabled: false
21
+ Max: 10
101
22
 
102
- Naming/ConstantName:
23
+ Naming/MethodParameterName:
103
24
  Enabled: false
104
-
105
- Naming/ClassAndModuleCamelCase:
106
- Enabled: false
107
-
108
- Naming/UncommunicativeBlockParamName:
109
- Enabled: true
110
25
 
111
- Naming/UncommunicativeMethodParamName:
112
- Enabled: false
113
-
114
26
  Naming/VariableName:
115
27
  Enabled: false
116
28
 
117
- Style/Alias:
118
- Enabled: true
119
-
120
- Layout/AlignHash:
121
- Enabled: false
122
-
123
- Style/AsciiComments:
124
- Enabled: false
125
-
126
- Style/BarePercentLiterals:
127
- Enabled: false
128
-
129
- Style/BlockComments:
130
- Enabled: false
131
-
132
- Style/CharacterLiteral:
133
- Enabled: false
134
-
135
- Style/ClassCheck:
136
- Enabled: false
137
-
138
- Style/ClassVars:
139
- Enabled: false
140
-
141
- Style/ColonMethodCall:
142
- Enabled: false
143
-
144
- Style/CommentAnnotation:
145
- Enabled: false
146
-
147
29
  Style/CommentedKeyword:
148
- Enabled: false
149
-
150
- Style/ConditionalAssignment:
151
- Enabled: false
152
-
153
- Style/DefWithParentheses:
154
- Enabled: true
155
-
156
- Style/Documentation:
157
- Enabled: false
158
-
159
- Style/ExpandPathArguments:
160
- Enabled: false
161
-
162
- Style/GuardClause:
163
- Enabled: false
164
-
165
- Style/IfUnlessModifier:
166
- Enabled: false
167
-
168
- Style/InverseMethods:
169
- Enabled: true
170
-
171
- Style/Next:
172
- Enabled: false
173
-
174
- Style/RaiseArgs:
175
- Enabled: true
176
-
177
- Style/RedundantReturn:
178
- Enabled: false
179
-
180
- Style/RedundantSelf:
181
- Enabled: true
182
-
183
- Style/RegexpLiteral:
184
- Enabled: false
185
-
186
- Style/PercentLiteralDelimiters:
187
- Enabled: false
188
-
189
- Style/StderrPuts:
190
- Enabled: false
191
-
192
- Style/StringLiterals:
193
- Enabled: true
194
-
195
- Style/TernaryParentheses:
196
- Enabled: false
197
-
198
- Style/UnlessElse:
199
- Enabled: false
30
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
+ ## [0.1.24] - 2021-07-01
2
+ - Code restyling to please rubocop 1.53.1
3
+
4
+ ## [0.1.23] - 2021-09-04
5
+ - Remove dependencies towards `coverall`, `simplecov`
6
+ - Code restyling to please rubocop 1.19.1
7
+
8
+ * [CHANGE] File 'sequitur.gemspec' Remove dependencies towards `coverall`, `simplecov`
9
+ * [CHANGE] File 'sequitur.gemspec' Ruby version must be 2.5+
10
+
1
11
  ## [0.1.22] - 2019-08-18
2
- - Code refactoring to use string frozen magic comments (as a consequence, srl_ruby runs only on Rubies 2.3 or newer).
12
+ - Code refactoring to use string frozen magic comments (as a consequence, sequitur runs only on Rubies 2.3 or newer).
3
13
  - Code restyling to please rubocop 0.7.40.
4
14
 
5
15
  * [CHANGE] Files `Gemfile`, `.travis.yml`, `appveyor.yml` updated.
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2019 Dimitri Geshef
1
+ Copyright (c) 2014-2023 Dimitri Geshef
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/Rakefile CHANGED
@@ -19,12 +19,10 @@ RSpec::Core::RakeTask.new do |spec|
19
19
  spec.pattern = 'spec/**/*_spec.rb'
20
20
  end
21
21
 
22
-
23
22
  # Run RSpec tests
24
23
  desc 'Run tests, with RSpec'
25
24
  task test: [:spec]
26
25
 
27
-
28
26
  # Default rake task
29
27
  task default: :test
30
28
 
@@ -10,9 +10,8 @@ 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
- formatter = Sequitur::Formatter::BaseText.new(STDOUT)
14
+ formatter = Sequitur::Formatter::BaseText.new($stdout)
16
15
 
17
16
  # Now render the rules
18
17
  formatter.render(grammar.visitor)
data/examples/porridge.rb CHANGED
@@ -3,23 +3,23 @@
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 = <<-SNIPPET
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)
19
19
 
20
20
  # To display the grammar rules on the console output
21
21
  # We use a formatter
22
- formatter = Sequitur::Formatter::BaseText.new(STDOUT)
22
+ formatter = Sequitur::Formatter::BaseText.new($stdout)
23
23
 
24
24
  # Now render the rules.
25
25
  formatter.render(grammar.visitor)
@@ -11,7 +11,7 @@ grammar = Sequitur.build_from(input_sequence)
11
11
 
12
12
  # To display the grammar rules on the console output
13
13
  # We use a formatter
14
- formatter = Sequitur::Formatter::BaseText.new(STDOUT)
14
+ formatter = Sequitur::Formatter::BaseText.new($stdout)
15
15
 
16
16
  # Now render the rules. Each rule is displayed with the format:
17
17
  # rule_id : a_sequence_grammar_symbols.
@@ -15,7 +15,7 @@ input_sequence = %i[
15
15
  grammar = Sequitur.build_from(input_sequence)
16
16
 
17
17
  # Use a formatter to display the grammar rules on the console output
18
- formatter = Sequitur::Formatter::BaseText.new(STDOUT)
18
+ formatter = Sequitur::Formatter::BaseText.new($stdout)
19
19
 
20
20
  # Now render the rules
21
21
  formatter.render(grammar.visitor)
@@ -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 = <<-SNIPPET
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,9 +18,8 @@ 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
- formatter = Sequitur::Formatter::BaseText.new(STDOUT)
22
+ formatter = Sequitur::Formatter::BaseText.new($stdout)
24
23
 
25
24
  # Now render the rules
26
25
  formatter.render(grammar.visitor)
@@ -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.22'
10
+ Version = '0.1.24'
9
11
 
10
12
  # Brief description of the gem.
11
13
  Description = 'Ruby implementation of the Sequitur algorithm'
@@ -20,9 +22,10 @@ module Sequitur # Module used as a namespace
20
22
  RootDir = begin
21
23
  require 'pathname' # Load Pathname class from standard library
22
24
  startdir = Pathname(__FILE__).dirname.parent.parent.expand_path
23
- startdir.to_s + '/' # Append trailing slash character to it
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
@@ -28,7 +28,7 @@ module Sequitur # Module for classes implementing the Sequitur algorithm
28
28
  # the sequence symbol1 symbol2 appears.
29
29
  def initialize(symbol1, symbol2, aProduction)
30
30
  @symbols = [symbol1, symbol2]
31
- @key = symbol1.hash.to_s(16) + ':' + symbol2.hash.to_s(16)
31
+ @key = "#{symbol1.hash.to_s(16)}:#{symbol2.hash.to_s(16)}"
32
32
  @production = aProduction
33
33
  end
34
34
 
@@ -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
- return key == other.key
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
- return symbols[0] == symbols[1]
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
- rule_text = productions.map(&:to_string).join("\n")
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.
@@ -55,10 +54,10 @@ module Sequitur # Module for classes implementing the Sequitur algorithm
55
54
  puts to_string if trace
56
55
  prod = productions.delete_at(anIndex)
57
56
  # TODO: remove output
58
- puts('Removed: ' + prod.to_string) if trace
57
+ puts("Removed: #{prod.to_string}") if trace
59
58
  prod.clear_rhs
60
59
 
61
- return prod
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
- return GrammarVisitor.new(self)
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.kind_of?(GrammarVisitor)
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
- name = prod_index.zero? ? 'start' : "P#{prod_index}"
86
- return name
82
+ prod_index.zero? ? 'start' : "P#{prod_index}"
87
83
  end
88
84
  end # class
89
85
  end # module
@@ -2,7 +2,6 @@
2
2
 
3
3
  require_relative 'base_formatter'
4
4
 
5
-
6
5
  module Sequitur
7
6
  module Formatter
8
7
  # A formatter class that can render the notification events
@@ -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)