srl_ruby 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +7 -5
- data/bin/srl2ruby +16 -8
- data/bin/srl2ruby_cli_parser.rb +10 -0
- data/features/uuid_validation.feature +24 -0
- data/lib/srl_ruby/version.rb +1 -1
- data/srl_ruby.gemspec +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1997032b58ee5f449eaed39a3fca67d24e86f253
|
4
|
+
data.tar.gz: 89ec3ebb1fab1f5f766096efe8e13faf51f4857d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2a3e60c41dc5ad53ebe26283b091fed46f2d75c38137f2fbbde5859f58a3f777c85cad4163efa4c0538288db469aa8e6623a7cbd0e5911e563a01661774e932
|
7
|
+
data.tar.gz: f5002562a72aac9b6e1a4f9ec2bba1f8e251435f578b3f9aad7b25a1acb1097553ae49e10ecdb2a87d2ab0eb4e3f026f5efca63331f991ee19b673591c8528e0
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## [0.4.1] - 2018-05-25
|
2
|
+
|
3
|
+
### Added
|
4
|
+
- Command-line option -p, --pattern SRL_PATT, that allows users to enter directly short one-liner SRL patterns.
|
5
|
+
Thanks to `KarimGeiger` for suggesting me this enhancement.
|
6
|
+
- Directory `examples` with SRL examples from `README` and more...
|
7
|
+
|
8
|
+
### Changed
|
9
|
+
- File `README.md` updated with new text of command-line help.
|
10
|
+
|
1
11
|
## [0.4.0] - 2018-05-13
|
2
12
|
Version bump: SrlRuby has a command-line compiler `srl2ruby`
|
3
13
|
|
data/README.md
CHANGED
@@ -50,9 +50,11 @@ Description:
|
|
50
50
|
|
51
51
|
Examples:
|
52
52
|
srl2ruby example.srl
|
53
|
+
srl2ruby -p 'begin with literally "Hello world!"'
|
53
54
|
srl2ruby example.srl -o example_re.rb -t srl_and_ruby.erb
|
54
55
|
|
55
56
|
Options:
|
57
|
+
-p, --pattern SRL_PATT One-liner SRL pattern.
|
56
58
|
-o, --output-file PATH Output to a file with specified name.
|
57
59
|
-t, --template-file TEMPLATE Use given ERB template for the Ruby code generation. srl2ruby looks for
|
58
60
|
the template file in current dir first then in its gem's /templates dir.
|
@@ -140,7 +142,7 @@ Parsing file 'email_validation.srl'
|
|
140
142
|
```
|
141
143
|
|
142
144
|
The resulting regexp isn't for the fainted hearts: who's ready to maintain it? In addition, the above pattern covers only the most frequent cases.
|
143
|
-
If you were asked to cover more exotic
|
145
|
+
If you were asked to cover more exotic cases, and knowing that it means an expression at least twice as complex, which version are you willing to update the SRL or the Regexp one?
|
144
146
|
|
145
147
|
#### Good to know: customizable output
|
146
148
|
In fact, if one wants to update or maintain a pattern, it would be practical to have the SRL expression and its equivalent Regexp next to each other in our Ruby source code.
|
@@ -212,12 +214,12 @@ If one compiles the above SRL expression with `srl2ruby` as explained earlier in
|
|
212
214
|
When I want to test regular expressions, one of my favorite tool is the
|
213
215
|
[Rubular website](http://rubular.com/). Tom Lovitt created a great Regexp editor and tester specifically for the Ruby community.
|
214
216
|
|
215
|
-
By the way, perhaps
|
217
|
+
By the way, perhaps some lynx-eyed readers spotted a small "mistake" on the third line of the SRL snippet: it doesn't end with a comma.
|
216
218
|
My apologies... For style consistency this line should be written as:
|
217
219
|
```
|
218
220
|
digit twice,
|
219
221
|
```
|
220
|
-
In reality, SRL happily ignores comma. Well..., most of the time. There is one exception: for the `any of` construct commas are used to separate alternatives (see example in [Iteration 3](#iteration-3)
|
222
|
+
In reality, SRL happily ignores comma. Well..., most of the time. There is one exception: for the `any of` construct commas are used to separate alternatives (see example in [Iteration 3](#iteration-3)).
|
221
223
|
|
222
224
|
### Iteration 2
|
223
225
|
Tests won't take a long time to show that the previous pattern is much too 'lenient' and will accept grossly incorrect entries such as 45:67 PM.
|
@@ -295,7 +297,7 @@ must end,
|
|
295
297
|
case insensitive
|
296
298
|
```
|
297
299
|
|
298
|
-
Here is the Regexp counterpart
|
300
|
+
Here is the Regexp counterpart generated by `srl2ruby`:
|
299
301
|
```ruby
|
300
302
|
/(?i-mx:^(?:(?:0?\d)|(?:1[01])):(?:0?|[1-5])\d\s?[AP]M$)/
|
301
303
|
```
|
@@ -329,7 +331,7 @@ case insensitive
|
|
329
331
|
/(?i-mx:^(?<hour>(?:(?:0?\d)|(?:1[01]))):(?<min>(?:0?|[1-5])\d)\s?[AP]M$)/
|
330
332
|
```
|
331
333
|
|
332
|
-
That
|
334
|
+
That Regexp is becoming insane...
|
333
335
|
|
334
336
|
|
335
337
|
#### Does this last Regexp really work?
|
data/bin/srl2ruby
CHANGED
@@ -21,19 +21,16 @@ class Srl2RubyProg
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def run!(file_names)
|
24
|
+
if cli_options.include?(:pattern)
|
25
|
+
srl_source = cli_options[:pattern]
|
26
|
+
process_srl(srl_source)
|
27
|
+
end
|
24
28
|
file_names.each do |srl_file|
|
25
29
|
fname = validate_filename(srl_file)
|
26
30
|
next unless file_exist?(fname)
|
27
31
|
puts "Parsing file '#{fname}'"
|
28
32
|
srl_source = File.read(fname)
|
29
|
-
|
30
|
-
destination = $stdout
|
31
|
-
if cli_options.include?(:output)
|
32
|
-
filepath = cli_options[:output]
|
33
|
-
destination = File.open(filepath, 'w')
|
34
|
-
end
|
35
|
-
puts "Writing to file '#{filepath}'" unless destination == $stdout
|
36
|
-
destination.puts emit_code(template, srl_source, result)
|
33
|
+
process_srl(srl_source)
|
37
34
|
end
|
38
35
|
end
|
39
36
|
|
@@ -79,6 +76,17 @@ class Srl2RubyProg
|
|
79
76
|
|
80
77
|
exists
|
81
78
|
end
|
79
|
+
|
80
|
+
def process_srl(srl_source)
|
81
|
+
result = SrlRuby.parse(srl_source)
|
82
|
+
destination = $stdout
|
83
|
+
if cli_options.include?(:output)
|
84
|
+
filepath = cli_options[:output]
|
85
|
+
destination = File.open(filepath, 'w')
|
86
|
+
end
|
87
|
+
puts "Writing to file '#{filepath}'" unless destination == $stdout
|
88
|
+
destination.puts emit_code(template, srl_source, result)
|
89
|
+
end
|
82
90
|
|
83
91
|
def emit_code(template, srl_source, regexp)
|
84
92
|
template.result(binding)
|
data/bin/srl2ruby_cli_parser.rb
CHANGED
@@ -13,6 +13,7 @@ class Srl2RubyCLIParser < OptionParser
|
|
13
13
|
|
14
14
|
heading
|
15
15
|
separator 'Options:'
|
16
|
+
add_p_option
|
16
17
|
add_o_option
|
17
18
|
add_t_option
|
18
19
|
separator ''
|
@@ -41,6 +42,7 @@ Description:
|
|
41
42
|
|
42
43
|
Examples:
|
43
44
|
#{program_name} example.srl
|
45
|
+
#{program_name} -p 'begin with literally "Hello world!"'
|
44
46
|
#{program_name} example.srl -o example_re.rb -t srl_and_ruby.erb
|
45
47
|
DESCR
|
46
48
|
|
@@ -61,6 +63,14 @@ DESCR
|
|
61
63
|
@parsed_options[:output] = pathname
|
62
64
|
end
|
63
65
|
end
|
66
|
+
|
67
|
+
def add_p_option
|
68
|
+
explanation = 'One-liner SRL pattern.'
|
69
|
+
|
70
|
+
on '-p', '--pattern SRL_PATT', explanation do |pattern_arg|
|
71
|
+
@parsed_options[:pattern] = pattern_arg.gsub(/^'|'$/, '')
|
72
|
+
end
|
73
|
+
end
|
64
74
|
|
65
75
|
def add_t_option
|
66
76
|
explanation = <<-EXPLANATION
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Feature: Defining a UUID validation pattern
|
2
|
+
As a shy Rubyist,
|
3
|
+
I want to use SRL to specify password pattern
|
4
|
+
So that I can use its regex representation in my code
|
5
|
+
|
6
|
+
|
7
|
+
Scenario: defining a UUID validation expression
|
8
|
+
# The pattern is based on the 8-4-4-4-12 syntax
|
9
|
+
When I define the following SRL expression:
|
10
|
+
"""
|
11
|
+
begin with (any of(digit, letter from a to f)) exactly 8 times,
|
12
|
+
literally "-",
|
13
|
+
(
|
14
|
+
(any of(digit, letter from a to f)) exactly 4 times,
|
15
|
+
literally "-"
|
16
|
+
) exactly 3 times,
|
17
|
+
(any of(digit, letter from a to f)) exactly 12 times
|
18
|
+
"""
|
19
|
+
Then I expect matching for:
|
20
|
+
| 123e4567-e89b-12d3-a456-426655440000 |
|
21
|
+
| 00112233-4455-6677-8899-aabbccddeeff |
|
22
|
+
|
23
|
+
And I expect no match for:
|
24
|
+
| 123e4567e89b12d3a456426655440000 |
|
data/lib/srl_ruby/version.rb
CHANGED
data/srl_ruby.gemspec
CHANGED
@@ -46,8 +46,8 @@ Gem::Specification.new do |spec|
|
|
46
46
|
spec.email = ['famished.tiger@yahoo.com']
|
47
47
|
|
48
48
|
spec.description = <<-DESCR
|
49
|
-
A compiler that transforms highly readable Simple Regex Language
|
50
|
-
into regular expressions.
|
49
|
+
A compiler and library that transforms highly readable Simple Regex Language
|
50
|
+
patterns into regular expressions.
|
51
51
|
DESCR
|
52
52
|
spec.summary = <<-SUMMARY
|
53
53
|
A parser for the [Simple Regex Language](https://simple-regex.com/).
|
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.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-05-
|
11
|
+
date: 2018-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rley
|
@@ -80,9 +80,8 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3.0'
|
83
|
-
description:
|
84
|
-
|
85
|
-
into regular expressions.
|
83
|
+
description: " A compiler and library that transforms highly readable Simple Regex
|
84
|
+
Language \n patterns into regular expressions.\n"
|
86
85
|
email:
|
87
86
|
- famished.tiger@yahoo.com
|
88
87
|
executables:
|
@@ -120,6 +119,7 @@ files:
|
|
120
119
|
- features/lib/support/env..rb
|
121
120
|
- features/password_validation.feature
|
122
121
|
- features/url_capturing.feature
|
122
|
+
- features/uuid_validation.feature
|
123
123
|
- lib/regex/abstract_method.rb
|
124
124
|
- lib/regex/alternation.rb
|
125
125
|
- lib/regex/anchor.rb
|