srl_ruby 0.3.0 → 0.3.1

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
  SHA1:
3
- metadata.gz: 17b59ca17f397a24c01b84bd9d1a4a67743e2f73
4
- data.tar.gz: 8b6b397b9d5e95bf1f5a6f6b5cdd866d7a8e966d
3
+ metadata.gz: 808f335172ddb8259c8f7c7d5ed0207936c6f7ad
4
+ data.tar.gz: cd7bfcabd76599a570997cf9032d2522d346f038
5
5
  SHA512:
6
- metadata.gz: 5b7e2d0a99199a431eb2c381f566171161e7c7aaa6098211d9740e3f4bbc86568aafa60d6f41a5e334a35c81cddffc2260e11c1a6a8392e39f8095f7cba05571
7
- data.tar.gz: 6d7cd5fe49e6277558f2cfaa2601ee515cb14556fc5d8c4b831d853f4f77f52301758166618b0cf3e7f5ae6cf9cab957052ad7cb0f5f53a323726c4bb307824d
6
+ metadata.gz: 3db09d707e1496ed2711a903d5f655aca233fd695804a4ba6787fa8e067bb190efb9c770e9ee0e685ed6282f9956c8e23c30cedf4f3dca7a428c99e53e165c23
7
+ data.tar.gz: 02f3eb69d6cbc700e2d4f22ebe9d3e2c96892e150258aa9984af3102fde44a98cc2ebb4ab5025acdd6f961f1614cc75bf5e964d28e42263a6ca3b84b9df99b10
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## [0.3.1] - 2018-04-04
2
+ ### Added
3
+ - Added `Cucumber` feature files both for additional testing and demo purposes.
4
+ Almost all examples from SRL websites are "featured".
5
+
6
+ ### Changed
7
+ - All regex node classes support the `done!` method. It signals the end of aprsing, this is the right moment to finalize/tune
8
+ the parse tree or parse forest to build.
9
+
10
+ ### Fixed
11
+ - Method `PolyadicExpression#done!` fixes an issue with lookbehind regex generation. The lookbehind expression precede the
12
+ expression to be mathced/capture. In SRL, lookbehind syntax the expression to capture or match...
13
+ - Class `SrlRuby::ASTBuilder` improved support "from ... to ..." syntax: supports the case when boundaries are swapped.
14
+ If last captured subexpression is a repetition, then it is made lazy (instead of greedy).
15
+
1
16
  ## [0.3.0] - 2018-04-04
2
17
  Version bump: SrlRuby passes the complete official SRL test suite!
3
18
  ### Changed
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
2
+ require 'rspec/core/rake_task' # Rspec as testing tool
3
+ require 'cucumber/rake/task' # Cucumber as testing tool
3
4
 
4
5
  desc 'Run RSpec'
5
6
  RSpec::Core::RakeTask.new do |spec|
@@ -7,10 +8,12 @@ RSpec::Core::RakeTask.new do |spec|
7
8
  end
8
9
 
9
10
 
10
- # Combine RSpec tests
11
- desc 'Run tests, with RSpec'
12
- task test: [:spec]
11
+ Cucumber::Rake::Task.new do |_|
12
+ end
13
13
 
14
+ # Combine RSpec and Cucumber tests
15
+ desc 'Run tests, with RSpec and Cucumber'
16
+ task test: [:spec, :cucumber]
14
17
 
15
18
  # Default rake task
16
19
  task default: :test
@@ -10,6 +10,10 @@ module Regex # This module is used as a namespace
10
10
  def atomic?
11
11
  return true
12
12
  end
13
+
14
+ def done!()
15
+ # Do nothing
16
+ end
13
17
  end # class
14
18
  end # module
15
19
 
@@ -14,6 +14,10 @@ module Regex # This module is used as a namespace
14
14
  super()
15
15
  @child = theChild
16
16
  end
17
+
18
+ def done!()
19
+ # Do nothing
20
+ end
17
21
 
18
22
  protected
19
23
 
@@ -22,6 +22,19 @@ module Regex # This module is used as a namespace
22
22
 
23
23
  return self
24
24
  end
25
+
26
+ def done!()
27
+ children.each(&:done!)
28
+ children.each_with_index do |child, index|
29
+ break if index == children.size - 1
30
+ next_child = children[index+1]
31
+ if next_child.kind_of?(Lookaround) && next_child.dir == :behind
32
+ # Swap children: lookbehind regex must precede pattern
33
+ @children[index+1] = child
34
+ @children[index] = next_child
35
+ end
36
+ end
37
+ end
25
38
 
26
39
  # Build a depth-first in-order children visitor.
27
40
  # The visitor is implemented as an Enumerator.
@@ -14,6 +14,10 @@ module Regex # This module is used as a namespace
14
14
  super(childExpressionToRepeat)
15
15
  @multiplicity = aMultiplicity
16
16
  end
17
+
18
+ def done!()
19
+ child.done!
20
+ end
17
21
 
18
22
  protected
19
23
 
@@ -59,7 +59,6 @@ module SrlRuby
59
59
  end
60
60
 
61
61
  def char_range(lowerBound, upperBound)
62
- # TODO fix module nesting
63
62
  lower = Regex::Character.new(lowerBound)
64
63
  upper = Regex::Character.new(upperBound)
65
64
  return Regex::CharRange.new(lower, upper)
@@ -189,18 +188,18 @@ module SrlRuby
189
188
  end
190
189
 
191
190
  # rule('letter_range' => %w[LETTER FROM LETTER_LIT TO LETTER_LIT]).as 'lowercase_from_to'
192
- def reduce_lowercase_from_to(_production, _range, _tokens, theChildren)
193
- lower = theChildren[2].token.lexeme
194
- upper = theChildren[4].token.lexeme
195
- ch_range = char_range(lower, upper)
191
+ def reduce_lowercase_from_to(_production, _range, _tokens, theChildren)
192
+ raw_range = [theChildren[2].token.lexeme, theChildren[4].token.lexeme]
193
+ range_sorted = raw_range.sort
194
+ ch_range = char_range(range_sorted[0], range_sorted[1])
196
195
  char_class(false, ch_range)
197
196
  end
198
197
 
199
198
  # rule('letter_range' => %w[UPPERCASE LETTER FROM LETTER_LIT TO LETTER_LIT]).as 'uppercase_from_to'
200
199
  def reduce_uppercase_from_to(_production, _range, _tokens, theChildren)
201
- lower = theChildren[3].token.lexeme
202
- upper = theChildren[5].token.lexeme
203
- ch_range = char_range(lower.upcase, upper.upcase)
200
+ raw_range = [theChildren[3].token.lexeme, theChildren[5].token.lexeme]
201
+ range_sorted = raw_range.sort
202
+ ch_range = char_range(range_sorted[0], range_sorted[1])
204
203
  char_class(false, ch_range)
205
204
  end
206
205
 
@@ -218,7 +217,10 @@ module SrlRuby
218
217
 
219
218
  # rule('digit_range' => %w[digit_or_number FROM DIGIT_LIT TO DIGIT_LIT]).as 'digits_from_to'
220
219
  def reduce_digits_from_to(aProduction, aRange, theTokens, theChildren)
221
- reduce_lowercase_from_to(aProduction, aRange, theTokens, theChildren)
220
+ raw_range = [theChildren[2].token.lexeme, theChildren[4].token.lexeme]
221
+ range_sorted = raw_range.map(&:to_i).sort
222
+ ch_range = char_range(range_sorted[0].to_s, range_sorted[1].to_s)
223
+ char_class(false, ch_range)
222
224
  end
223
225
 
224
226
  # rule('character_class' => %w[ANY CHARACTER]).as 'any_character'
@@ -1,3 +1,3 @@
1
1
  module SrlRuby
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.3.1'.freeze
3
3
  end
@@ -18,13 +18,10 @@ RSpec.describe SrlRuby do
18
18
  def load_file(aFilename)
19
19
  return Acceptance::RuleFileParser.load_file(rule_path + aFilename)
20
20
  end
21
-
22
- #
23
- # CaptureTest = Struct.new(:test_string, :expectations)
24
21
 
25
22
  def test_rule_file(aRuleFileRepr)
26
23
  regex = SrlRuby::parse(aRuleFileRepr.srl.value)
27
- puts regex.source
24
+ # puts regex.source
28
25
  expect(regex).to be_kind_of(Regexp)
29
26
 
30
27
  aRuleFileRepr.match_tests.each do |test|
@@ -19,6 +19,10 @@ module Acceptance
19
19
  }.freeze
20
20
 
21
21
  attr_reader :options
22
+
23
+ def done!()
24
+ # Do nothing!
25
+ end
22
26
 
23
27
  protected
24
28
 
@@ -281,12 +281,12 @@ END_SRL
281
281
 
282
282
  it 'should parse positive lookbehind' do
283
283
  regexp = SrlRuby.parse('literally "bar" if already had literally "foo"')
284
- expect(regexp.source).to eq('bar(?<=foo)')
284
+ expect(regexp.source).to eq('(?<=foo)bar')
285
285
  end
286
286
 
287
287
  it 'should parse negative lookbehind' do
288
288
  regexp = SrlRuby.parse('literally "bar" if not already had literally "foo"')
289
- expect(regexp.source).to eq('bar(?<!foo)')
289
+ expect(regexp.source).to eq('(?<!foo)bar')
290
290
  end
291
291
  end # context
292
292
 
data/srl_ruby.gemspec CHANGED
@@ -38,11 +38,12 @@ Gem::Specification.new do |spec|
38
38
  spec.authors = ['Dimitri Geshef']
39
39
  spec.email = ['famished.tiger@yahoo.com']
40
40
 
41
- spec.description = %q(A parser for the Simple Regex Language (SRL).)
41
+ spec.description = %Q(Build easily regular expressions thanks to Simple Regex Language)
42
42
  spec.summary = <<-END_DESCR
43
- srl_ruby is a gem implementing a parser for Simple Regex Language (SRL).
43
+ A parser for the [Simple Regex Language](https://simple-regex.com/).
44
44
  It translates patterns expressed in SRL into plain Ruby Regexp objects
45
- or regex literals.
45
+ or in regex literals. Use self-documenting, human readable, SRL expressions
46
+ to craft your new awesome regular expressions.
46
47
  END_DESCR
47
48
  spec.homepage = 'https://github.com/famished-tiger/SRL-Ruby'
48
49
  spec.license = 'MIT'
@@ -55,10 +56,11 @@ END_DESCR
55
56
  spec.required_ruby_version = '>= 2.1.0'
56
57
 
57
58
  # Runtime dependencies
58
- spec.add_dependency 'rley', '~> 0.6.05'
59
+ spec.add_dependency 'rley', '~> 0.6.06'
59
60
 
60
61
  # Development dependencies
61
62
  spec.add_development_dependency 'bundler', '~> 1.16'
63
+ spec.add_development_dependency 'cucumber', '>= 2.2.0'
62
64
  spec.add_development_dependency 'rake', '~> 10.0'
63
65
  spec.add_development_dependency 'rspec', '~> 3.0'
64
66
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: srl_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitri Geshef
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-04 00:00:00.000000000 Z
11
+ date: 2018-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rley
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.6.05
19
+ version: 0.6.06
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.6.05
26
+ version: 0.6.06
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: cucumber
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.2.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.2.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +80,7 @@ dependencies:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
82
  version: '3.0'
69
- description: A parser for the Simple Regex Language (SRL).
83
+ description: Build easily regular expressions thanks to Simple Regex Language
70
84
  email:
71
85
  - famished.tiger@yahoo.com
72
86
  executables:
@@ -169,9 +183,10 @@ rubyforge_project:
169
183
  rubygems_version: 2.6.13
170
184
  signing_key:
171
185
  specification_version: 4
172
- summary: srl_ruby is a gem implementing a parser for Simple Regex Language (SRL).
173
- It translates patterns expressed in SRL into plain Ruby Regexp objects or regex
174
- literals.
186
+ summary: A parser for the [Simple Regex Language](https://simple-regex.com/). It translates
187
+ patterns expressed in SRL into plain Ruby Regexp objects or in regex literals.
188
+ Use self-documenting, human readable, SRL expressions to craft your new awesome
189
+ regular expressions.
175
190
  test_files:
176
191
  - spec/acceptance/srl_test_suite_spec.rb
177
192
  - spec/regex/character_spec.rb