srl_ruby 0.4.3 → 0.4.7
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 +5 -5
- data/.rubocop.yml +278 -22
- data/CHANGELOG.md +43 -1
- data/Gemfile +2 -0
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/Rakefile +3 -0
- data/appveyor.yml +15 -14
- data/bin/srl2ruby +17 -12
- data/bin/srl2ruby_cli_parser.rb +6 -6
- data/features/lib/step_definitions/srl_testing_steps.rb +2 -0
- data/features/lib/support/env..rb +2 -0
- data/lib/regex/abstract_method.rb +2 -0
- data/lib/regex/alternation.rb +3 -3
- data/lib/regex/anchor.rb +3 -0
- data/lib/regex/atomic_expression.rb +2 -0
- data/lib/regex/capturing_group.rb +8 -3
- data/lib/regex/char_class.rb +4 -2
- data/lib/regex/char_range.rb +4 -3
- data/lib/regex/char_shorthand.rb +3 -0
- data/lib/regex/character.rb +7 -2
- data/lib/regex/compound_expression.rb +2 -0
- data/lib/regex/concatenation.rb +3 -1
- data/lib/regex/expression.rb +6 -1
- data/lib/regex/lookaround.rb +3 -1
- data/lib/regex/match_option.rb +2 -0
- data/lib/regex/monadic_expression.rb +2 -0
- data/lib/regex/multiplicity.rb +9 -9
- data/lib/regex/non_capturing_group.rb +3 -1
- data/lib/regex/polyadic_expression.rb +4 -0
- data/lib/regex/quantifiable.rb +3 -1
- data/lib/regex/raw_expression.rb +2 -0
- data/lib/regex/repetition.rb +2 -0
- data/lib/regex/wildcard.rb +2 -5
- data/lib/srl_ruby/ast_builder.rb +12 -1
- data/lib/srl_ruby/grammar.rb +48 -46
- data/lib/srl_ruby/regex_repr.rb +2 -0
- data/lib/srl_ruby/tokenizer.rb +14 -8
- data/lib/srl_ruby/version.rb +3 -1
- data/lib/srl_ruby.rb +2 -0
- data/spec/acceptance/srl_test_suite_spec.rb +2 -0
- data/spec/acceptance/support/rule_file_ast_builder.rb +2 -0
- data/spec/acceptance/support/rule_file_grammar.rb +7 -5
- data/spec/acceptance/support/rule_file_nodes.rb +2 -0
- data/spec/acceptance/support/rule_file_parser.rb +2 -0
- data/spec/acceptance/support/rule_file_tokenizer.rb +14 -8
- data/spec/regex/atomic_expression_spec.rb +2 -0
- data/spec/regex/character_spec.rb +12 -6
- data/spec/regex/match_option_spec.rb +2 -0
- data/spec/regex/monadic_expression_spec.rb +2 -0
- data/spec/regex/multiplicity_spec.rb +4 -0
- data/spec/regex/repetition_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/srl_ruby/srl_ruby_spec.rb +2 -0
- data/spec/srl_ruby/tokenizer_spec.rb +3 -1
- data/spec/srl_ruby_spec.rb +8 -6
- data/srl_ruby.gemspec +7 -5
- metadata +16 -18
- data/lib/srl_ruby/srl_token.rb +0 -23
- data/spec/acceptance/support/rule_file_token.rb +0 -22
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# File: rule_tokenizer.rb
|
2
4
|
# Tokenizer for SimpleRegex Test-Rule files
|
3
5
|
# [File format](https://github.com/SimpleRegex/Test-Rules/blob/master/README.md)
|
4
6
|
require 'strscan'
|
5
7
|
require 'pp'
|
6
|
-
|
8
|
+
require 'rley'
|
7
9
|
|
8
10
|
module Acceptance
|
9
11
|
# The tokenizer should recognize:
|
@@ -14,8 +16,13 @@ module Acceptance
|
|
14
16
|
# Delimiters: parentheses '(' and ')'
|
15
17
|
# Separators: comma (optional)
|
16
18
|
class RuleFileTokenizer
|
19
|
+
# @return [StringScanner]
|
17
20
|
attr_reader(:scanner)
|
21
|
+
|
22
|
+
# @return [Integer] current line number
|
18
23
|
attr_reader(:lineno)
|
24
|
+
|
25
|
+
# @return [Integer] offset of start of current line within input
|
19
26
|
attr_reader(:line_start)
|
20
27
|
|
21
28
|
# Can be :default, :expecting_srl
|
@@ -74,18 +81,17 @@ module Acceptance
|
|
74
81
|
curr_ch = scanner.peek(1)
|
75
82
|
token = nil
|
76
83
|
|
77
|
-
|
78
84
|
if '-:'.include? curr_ch
|
79
85
|
# Delimiters, separators => single character token
|
80
86
|
token = build_token(@@lexeme2name[curr_ch], scanner.getch)
|
81
87
|
elsif (lexeme = scanner.scan(/[0-9]+/))
|
82
88
|
token = build_token('INTEGER', lexeme)
|
83
89
|
elsif (lexeme = scanner.scan(/srl:|match:/))
|
84
|
-
token = build_token(@@keywords[lexeme], lexeme)
|
90
|
+
token = build_token(@@keywords[lexeme].chop, lexeme.chop)
|
85
91
|
@state = :expecting_srl if lexeme == 'srl:'
|
86
92
|
elsif (lexeme = scanner.scan(/[a-zA-Z_][a-zA-Z0-9_]*/))
|
87
93
|
keyw = @@keywords[lexeme]
|
88
|
-
token_type = keyw
|
94
|
+
token_type = keyw || 'IDENTIFIER'
|
89
95
|
token = build_token(token_type, lexeme)
|
90
96
|
elsif (lexeme = scanner.scan(/"([^"]|\\")*"/)) # Double quotes literal?
|
91
97
|
unquoted = lexeme.gsub(/(^")|("$)/, '')
|
@@ -110,11 +116,11 @@ module Acceptance
|
|
110
116
|
def build_token(aSymbolName, aLexeme)
|
111
117
|
begin
|
112
118
|
col = scanner.pos - aLexeme.size - @line_start + 1
|
113
|
-
pos = Position.new(@lineno, col)
|
114
|
-
token =
|
115
|
-
rescue StandardError =>
|
119
|
+
pos = Rley::Lexical::Position.new(@lineno, col)
|
120
|
+
token = Rley::Lexical::Token.new(aLexeme, aSymbolName, pos)
|
121
|
+
rescue StandardError => e
|
116
122
|
puts "Failing with '#{aSymbolName}' and '#{aLexeme}'"
|
117
|
-
raise
|
123
|
+
raise e
|
118
124
|
end
|
119
125
|
|
120
126
|
return token
|
@@ -1,9 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# File: character_spec.rb
|
2
4
|
require_relative '../spec_helper' # Use the RSpec test framework
|
3
5
|
require_relative '../../lib/regex/character'
|
4
6
|
|
5
7
|
module Regex # Open this namespace, to get rid of scope qualifiers
|
6
8
|
describe Character do
|
9
|
+
# rubocop: disable Lint/ConstantDefinitionInBlock
|
10
|
+
|
7
11
|
# This constant holds an arbitrary selection of characters
|
8
12
|
SampleChars = [?a, ?\0, ?\u0107].freeze
|
9
13
|
|
@@ -114,6 +118,13 @@ module Regex # Open this namespace, to get rid of scope qualifiers
|
|
114
118
|
end
|
115
119
|
end
|
116
120
|
|
121
|
+
# Create a module that re-defines the existing to_s method
|
122
|
+
module Tweak_to_s
|
123
|
+
def to_s # Overwrite the existing to_s method
|
124
|
+
?\u03a3
|
125
|
+
end
|
126
|
+
end # module
|
127
|
+
|
117
128
|
it 'should known whether it is equal to another Object' do
|
118
129
|
newOne = Character.new(?\u03a3)
|
119
130
|
|
@@ -145,12 +156,6 @@ module Regex # Open this namespace, to get rid of scope qualifiers
|
|
145
156
|
expect(simulator).to receive(:to_s).and_return(?\u03a3)
|
146
157
|
expect(newOne).to eq(simulator)
|
147
158
|
|
148
|
-
# Create a module that re-defines the existing to_s method
|
149
|
-
module Tweak_to_s
|
150
|
-
def to_s # Overwrite the existing to_s method
|
151
|
-
?\u03a3
|
152
|
-
end
|
153
|
-
end # module
|
154
159
|
weird = Object.new
|
155
160
|
weird.extend(Tweak_to_s)
|
156
161
|
expect(newOne).to eq(weird)
|
@@ -164,6 +169,7 @@ module Regex # Open this namespace, to get rid of scope qualifiers
|
|
164
169
|
expect(ch2.explain).to eq("the character '\u03a3'")
|
165
170
|
end
|
166
171
|
end # context
|
172
|
+
# rubocop: enable Lint/ConstantDefinitionInBlock
|
167
173
|
end # describe
|
168
174
|
end # module
|
169
175
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# File: multiplicity_spec.rb
|
2
4
|
|
3
5
|
require_relative '../spec_helper' # Use the RSpec test framework
|
@@ -21,6 +23,7 @@ module Regex # This module is used as a namespace
|
|
21
23
|
end
|
22
24
|
|
23
25
|
context 'Provided services' do
|
26
|
+
# rubocop: disable Style/CombinableLoops
|
24
27
|
it 'should know its text representation' do
|
25
28
|
policy2text = { greedy: '', lazy: '?', possessive: '+' }
|
26
29
|
|
@@ -71,6 +74,7 @@ module Regex # This module is used as a namespace
|
|
71
74
|
end
|
72
75
|
end
|
73
76
|
end
|
77
|
+
# rubocop: enable Style/CombinableLoops
|
74
78
|
end
|
75
79
|
end
|
76
80
|
end # module
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative '../spec_helper' # Use the RSpec framework
|
2
4
|
require_relative '../../lib/srl_ruby/tokenizer' # Load the class under test
|
3
5
|
|
@@ -14,7 +16,7 @@ module SrlRuby
|
|
14
16
|
subject { Tokenizer.new('') }
|
15
17
|
|
16
18
|
context 'Initialization:' do
|
17
|
-
it 'should be initialized with a text to tokenize
|
19
|
+
it 'should be initialized with a text to tokenize' do
|
18
20
|
expect { Tokenizer.new('anything') }.not_to raise_error
|
19
21
|
end
|
20
22
|
|
data/spec/srl_ruby_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'spec_helper' # Use the RSpec framework
|
2
4
|
require_relative '../lib/srl_ruby'
|
3
5
|
|
@@ -224,7 +226,7 @@ SRL
|
|
224
226
|
let(:prefix) { 'letter from p to t ' }
|
225
227
|
|
226
228
|
it "should parse 'once' syntax" do
|
227
|
-
regexp = SrlRuby.parse(prefix
|
229
|
+
regexp = SrlRuby.parse("#{prefix}once")
|
228
230
|
expect(regexp.source).to eq('[p-t]{1}')
|
229
231
|
end
|
230
232
|
|
@@ -244,26 +246,26 @@ SRL
|
|
244
246
|
end
|
245
247
|
|
246
248
|
it "should parse 'between ... and ... times' syntax" do
|
247
|
-
regexp = SrlRuby.parse(prefix
|
249
|
+
regexp = SrlRuby.parse("#{prefix}between 2 and 4 times")
|
248
250
|
expect(regexp.source).to eq('[p-t]{2,4}')
|
249
251
|
|
250
252
|
# Dropping 'times' keyword is a shorter alternative syntax
|
251
|
-
regexp = SrlRuby.parse(prefix
|
253
|
+
regexp = SrlRuby.parse("#{prefix}between 2 and 4")
|
252
254
|
expect(regexp.source).to eq('[p-t]{2,4}')
|
253
255
|
end
|
254
256
|
|
255
257
|
it "should parse 'once or more' syntax" do
|
256
|
-
regexp = SrlRuby.parse(prefix
|
258
|
+
regexp = SrlRuby.parse("#{prefix}once or more")
|
257
259
|
expect(regexp.source).to eq('[p-t]+')
|
258
260
|
end
|
259
261
|
|
260
262
|
it "should parse 'never or more' syntax" do
|
261
|
-
regexp = SrlRuby.parse(prefix
|
263
|
+
regexp = SrlRuby.parse("#{prefix}never or more")
|
262
264
|
expect(regexp.source).to eq('[p-t]*')
|
263
265
|
end
|
264
266
|
|
265
267
|
it "should parse 'at least ... times' syntax" do
|
266
|
-
regexp = SrlRuby.parse(prefix
|
268
|
+
regexp = SrlRuby.parse("#{prefix}at least 10 times")
|
267
269
|
expect(regexp.source).to eq('[p-t]{10,}')
|
268
270
|
end
|
269
271
|
end # context
|
data/srl_ruby.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
lib = File.expand_path('../lib', __FILE__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
require 'srl_ruby/version'
|
@@ -46,7 +48,7 @@ Gem::Specification.new do |spec|
|
|
46
48
|
spec.email = ['famished.tiger@yahoo.com']
|
47
49
|
|
48
50
|
spec.description = <<-DESCR
|
49
|
-
A compiler and library that transforms highly readable Simple Regex Language
|
51
|
+
A compiler and library that transforms highly readable Simple Regex Language
|
50
52
|
patterns into regular expressions.
|
51
53
|
DESCR
|
52
54
|
spec.summary = <<-SUMMARY
|
@@ -63,14 +65,14 @@ SUMMARY
|
|
63
65
|
spec.require_paths = ['lib']
|
64
66
|
PkgExtending.pkg_files(spec)
|
65
67
|
PkgExtending.pkg_documentation(spec)
|
66
|
-
spec.required_ruby_version = '>= 2.
|
68
|
+
spec.required_ruby_version = '>= 2.5.0'
|
67
69
|
|
68
70
|
# Runtime dependencies
|
69
|
-
spec.add_dependency 'rley', '~> 0.
|
71
|
+
spec.add_dependency 'rley', '~> 0.8.02'
|
70
72
|
|
71
73
|
# Development dependencies
|
72
|
-
spec.add_development_dependency 'bundler', '~> 1.
|
74
|
+
spec.add_development_dependency 'bundler', '~> 2.1.0'
|
73
75
|
spec.add_development_dependency 'cucumber', '>= 2.2.0'
|
74
|
-
spec.add_development_dependency 'rake', '~>
|
76
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
75
77
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
76
78
|
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.4.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitri Geshef
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rley
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.8.02
|
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:
|
26
|
+
version: 0.8.02
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 2.1.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 2.1.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: cucumber
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '12.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '12.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,8 +80,9 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3.0'
|
83
|
-
description:
|
84
|
-
|
83
|
+
description: |2
|
84
|
+
A compiler and library that transforms highly readable Simple Regex Language
|
85
|
+
patterns into regular expressions.
|
85
86
|
email:
|
86
87
|
- famished.tiger@yahoo.com
|
87
88
|
executables:
|
@@ -146,7 +147,6 @@ files:
|
|
146
147
|
- lib/srl_ruby/ast_builder.rb
|
147
148
|
- lib/srl_ruby/grammar.rb
|
148
149
|
- lib/srl_ruby/regex_repr.rb
|
149
|
-
- lib/srl_ruby/srl_token.rb
|
150
150
|
- lib/srl_ruby/tokenizer.rb
|
151
151
|
- lib/srl_ruby/version.rb
|
152
152
|
- spec/acceptance/srl_test_suite_spec.rb
|
@@ -154,7 +154,6 @@ files:
|
|
154
154
|
- spec/acceptance/support/rule_file_grammar.rb
|
155
155
|
- spec/acceptance/support/rule_file_nodes.rb
|
156
156
|
- spec/acceptance/support/rule_file_parser.rb
|
157
|
-
- spec/acceptance/support/rule_file_token.rb
|
158
157
|
- spec/acceptance/support/rule_file_tokenizer.rb
|
159
158
|
- spec/regex/atomic_expression_spec.rb
|
160
159
|
- spec/regex/character_spec.rb
|
@@ -191,7 +190,7 @@ homepage: https://github.com/famished-tiger/SRL-Ruby
|
|
191
190
|
licenses:
|
192
191
|
- MIT
|
193
192
|
metadata: {}
|
194
|
-
post_install_message:
|
193
|
+
post_install_message:
|
195
194
|
rdoc_options:
|
196
195
|
- --charset=UTF-8 --exclude="examples|spec"
|
197
196
|
require_paths:
|
@@ -200,16 +199,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
200
199
|
requirements:
|
201
200
|
- - ">="
|
202
201
|
- !ruby/object:Gem::Version
|
203
|
-
version: 2.
|
202
|
+
version: 2.5.0
|
204
203
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
204
|
requirements:
|
206
205
|
- - ">="
|
207
206
|
- !ruby/object:Gem::Version
|
208
207
|
version: '0'
|
209
208
|
requirements: []
|
210
|
-
|
211
|
-
|
212
|
-
signing_key:
|
209
|
+
rubygems_version: 3.1.4
|
210
|
+
signing_key:
|
213
211
|
specification_version: 4
|
214
212
|
summary: A parser for the [Simple Regex Language](https://simple-regex.com/). It translates
|
215
213
|
patterns expressed in SRL into plain Ruby Regexp objects or in regex literals. Use
|
data/lib/srl_ruby/srl_token.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'rley' # Load the Rley gem
|
2
|
-
|
3
|
-
|
4
|
-
module SrlRuby
|
5
|
-
Position = Struct.new(:line, :column) do
|
6
|
-
def to_s
|
7
|
-
"line #{line}, column #{column}"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
# Specialization of Token class.
|
12
|
-
# It stores the position in (line, row) of the token
|
13
|
-
class SrlToken < Rley::Lexical::Token
|
14
|
-
attr_reader(:position)
|
15
|
-
|
16
|
-
def initialize(theLexeme, aTerminal, aPosition)
|
17
|
-
super(theLexeme, aTerminal)
|
18
|
-
@position = aPosition
|
19
|
-
end
|
20
|
-
end # class
|
21
|
-
end # module
|
22
|
-
|
23
|
-
# End of file
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'rley' # Load the Rley gem
|
2
|
-
|
3
|
-
module Acceptance
|
4
|
-
Position = Struct.new(:line, :column) do
|
5
|
-
def to_s
|
6
|
-
"line #{line}, column #{column}"
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
# Specialization of Token class.
|
11
|
-
# It stores the position in (line, row) of the token
|
12
|
-
class RuleFileToken < Rley::Lexical::Token
|
13
|
-
attr_reader(:position)
|
14
|
-
|
15
|
-
def initialize(theLexeme, aTerminal, aPosition)
|
16
|
-
super(theLexeme, aTerminal)
|
17
|
-
@position = aPosition
|
18
|
-
end
|
19
|
-
end # class
|
20
|
-
end # module
|
21
|
-
|
22
|
-
# End of file
|