regexgen 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.dir-locals.el +4 -0
- data/.github/workflows/main.yml +2 -0
- data/.solargraph.yml +17 -0
- data/Gemfile.lock +29 -1
- data/README.md +13 -0
- data/bin/regexgen +33 -0
- data/lib/regexgen/regex.rb +37 -1
- data/lib/regexgen/version.rb +1 -1
- data/regexgen.gemspec +1 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 712b188ebb53ab6fd9ddc10b42eae54b87312ee1a27fb2af0740141f8e054414
|
4
|
+
data.tar.gz: 63b927e179f6e7eb058b50d037ed2c963c1abbb39e68b91b6e09e5104b36df91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 077127e3bca3854f569e6452cb5db39e54b83faf134795b92cfc34f785890c3bd2de995bd06dab8c3cc3eacde2aea60c94fcb720233701d05831056e47396065
|
7
|
+
data.tar.gz: bc5df49ef540c19765602270278a0338dbd3725039174fbc220ec9814c5af1e0ecb6c650c2f68915b711e600163acdc69fab022c506109e76440ee95adaf0ad5
|
data/.dir-locals.el
ADDED
data/.github/workflows/main.yml
CHANGED
data/.solargraph.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
include:
|
3
|
+
- "**/*.rb"
|
4
|
+
exclude:
|
5
|
+
- spec/**/*
|
6
|
+
- test/**/*
|
7
|
+
- vendor/**/*
|
8
|
+
- ".bundle/**/*"
|
9
|
+
require: []
|
10
|
+
domains: []
|
11
|
+
reporters:
|
12
|
+
- rubocop
|
13
|
+
- require_not_found
|
14
|
+
- typecheck:typed
|
15
|
+
require_paths: []
|
16
|
+
plugins: []
|
17
|
+
max_files: 5000
|
data/Gemfile.lock
CHANGED
@@ -1,20 +1,30 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
regexgen (0.
|
4
|
+
regexgen (0.2.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
ast (2.4.1)
|
10
|
+
backport (1.1.2)
|
11
|
+
benchmark (0.1.0)
|
10
12
|
byebug (11.1.3)
|
13
|
+
e2mmap (0.1.0)
|
14
|
+
jaro_winkler (1.5.4)
|
15
|
+
maruku (0.7.3)
|
16
|
+
mini_portile2 (2.4.0)
|
11
17
|
minitest (5.14.1)
|
18
|
+
nokogiri (1.10.10)
|
19
|
+
mini_portile2 (~> 2.4.0)
|
12
20
|
parallel (1.19.2)
|
13
21
|
parser (2.7.1.4)
|
14
22
|
ast (~> 2.4.1)
|
15
23
|
rainbow (3.0.0)
|
16
24
|
rake (12.3.3)
|
17
25
|
regexp_parser (1.7.1)
|
26
|
+
reverse_markdown (2.0.0)
|
27
|
+
nokogiri
|
18
28
|
rexml (3.2.4)
|
19
29
|
rubocop (0.89.0)
|
20
30
|
parallel (~> 1.10)
|
@@ -28,7 +38,24 @@ GEM
|
|
28
38
|
rubocop-ast (0.3.0)
|
29
39
|
parser (>= 2.7.1.4)
|
30
40
|
ruby-progressbar (1.10.1)
|
41
|
+
solargraph (0.39.13)
|
42
|
+
backport (~> 1.1)
|
43
|
+
benchmark
|
44
|
+
bundler (>= 1.17.2)
|
45
|
+
e2mmap
|
46
|
+
jaro_winkler (~> 1.5)
|
47
|
+
maruku (~> 0.7, >= 0.7.3)
|
48
|
+
nokogiri (~> 1.9, >= 1.9.1)
|
49
|
+
parser (~> 2.3)
|
50
|
+
reverse_markdown (>= 1.0.5, < 3)
|
51
|
+
rubocop (~> 0.52)
|
52
|
+
thor (~> 1.0)
|
53
|
+
tilt (~> 2.0)
|
54
|
+
yard (~> 0.9, >= 0.9.24)
|
55
|
+
thor (1.0.1)
|
56
|
+
tilt (2.0.10)
|
31
57
|
unicode-display_width (1.7.0)
|
58
|
+
yard (0.9.25)
|
32
59
|
|
33
60
|
PLATFORMS
|
34
61
|
ruby
|
@@ -39,6 +66,7 @@ DEPENDENCIES
|
|
39
66
|
rake (~> 12.0)
|
40
67
|
regexgen!
|
41
68
|
rubocop (~> 0.89)
|
69
|
+
solargraph (~> 0.39)
|
42
70
|
|
43
71
|
BUNDLED WITH
|
44
72
|
2.1.4
|
data/README.md
CHANGED
@@ -29,6 +29,19 @@ require 'regexgen'
|
|
29
29
|
Regexgen.generate(['foobar', 'foobaz', 'foozap', 'fooza']) #=> /foo(?:zap?|ba[rz])/
|
30
30
|
```
|
31
31
|
|
32
|
+
## CLI
|
33
|
+
|
34
|
+
`regexgen` also has a simple CLI to generate regexes using inputs from the
|
35
|
+
command line.
|
36
|
+
|
37
|
+
```sh
|
38
|
+
$ regexgen
|
39
|
+
usage: regexgen [-mix] strings...
|
40
|
+
-m Multiline flag
|
41
|
+
-i Case-insensitive flag
|
42
|
+
-x Extended flag
|
43
|
+
```
|
44
|
+
|
32
45
|
## Unicode handling
|
33
46
|
|
34
47
|
Unlike the JavaScript version, this package does not do any special Unicode
|
data/bin/regexgen
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'regexgen'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
REGEX_FLAGS = {
|
8
|
+
'm' => 'Multiline flag',
|
9
|
+
'i' => 'Case-insensitive flag',
|
10
|
+
'x' => 'Extended flag'
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
flags = []
|
14
|
+
op = OptionParser.new do |opts|
|
15
|
+
opts.banner = "usage: regexgen [-#{REGEX_FLAGS.keys.join}] strings..."
|
16
|
+
REGEX_FLAGS.each do |flag, description|
|
17
|
+
opts.on("-#{flag}", description) { |_| flags << flag }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
begin
|
22
|
+
op.parse!
|
23
|
+
rescue OptionParser::InvalidOption => e
|
24
|
+
puts e, op.help
|
25
|
+
exit(1)
|
26
|
+
end
|
27
|
+
|
28
|
+
if ARGV.empty?
|
29
|
+
puts op.help
|
30
|
+
exit(1)
|
31
|
+
end
|
32
|
+
|
33
|
+
puts Regexgen.generate(ARGV, flags)
|
data/lib/regexgen/regex.rb
CHANGED
@@ -4,6 +4,42 @@ require 'regexgen/ast'
|
|
4
4
|
|
5
5
|
module Regexgen
|
6
6
|
class<<self
|
7
|
+
# Brzozowski algebraic method
|
8
|
+
# https://cs.stackexchange.com/a/2392
|
9
|
+
#
|
10
|
+
# Largely ported from
|
11
|
+
# https://github.com/devongovett/regexgen/blob/7ef10aef3a414b10554822cdf6e90389582b1890/src/regex.js
|
12
|
+
#
|
13
|
+
# Initialize B
|
14
|
+
#
|
15
|
+
# for i = 1 to m:
|
16
|
+
# if final(i):
|
17
|
+
# B[i] := ε
|
18
|
+
# else:
|
19
|
+
# B[i] := ∅
|
20
|
+
#
|
21
|
+
# Initialize A
|
22
|
+
#
|
23
|
+
# for i = 1 to m:
|
24
|
+
# for j = 1 to m:
|
25
|
+
# for a in Σ:
|
26
|
+
# if trans(i, a, j):
|
27
|
+
# A[i,j] := a
|
28
|
+
# else:
|
29
|
+
# A[i,j] := ∅
|
30
|
+
#
|
31
|
+
# Solve
|
32
|
+
#
|
33
|
+
# for n = m decreasing to 1:
|
34
|
+
# B[n] := star(A[n,n]) . B[n]
|
35
|
+
# for j = 1 to n:
|
36
|
+
# A[n,j] := star(A[n,n]) . A[n,j];
|
37
|
+
# for i = 1 to n:
|
38
|
+
# B[i] += A[i,n] . B[n]
|
39
|
+
# for j = 1 to n:
|
40
|
+
# A[i,j] += A[i,n] . A[n,j]
|
41
|
+
#
|
42
|
+
# Result is e := B[1]
|
7
43
|
def to_regex(root)
|
8
44
|
states = root.visit.to_a
|
9
45
|
|
@@ -22,7 +58,7 @@ module Regexgen
|
|
22
58
|
|
23
59
|
(states.length - 1).downto(0) do |n|
|
24
60
|
if a[n][n]
|
25
|
-
b[n] = concat(star(a[n][n], b[n])
|
61
|
+
b[n] = concat(star(a[n][n]), b[n])
|
26
62
|
(0...n).each do |j|
|
27
63
|
a[n][j] = concat(start(a[n][n]), a[n][j])
|
28
64
|
end
|
data/lib/regexgen/version.rb
CHANGED
data/regexgen.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: regexgen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Madlon-Kay
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-08-
|
11
|
+
date: 2020-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.89'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: solargraph
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.39'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.39'
|
41
55
|
description:
|
42
56
|
email:
|
43
57
|
- aaron@madlon-kay.com
|
@@ -45,11 +59,13 @@ executables: []
|
|
45
59
|
extensions: []
|
46
60
|
extra_rdoc_files: []
|
47
61
|
files:
|
62
|
+
- ".dir-locals.el"
|
48
63
|
- ".github/workflows/main.yml"
|
49
64
|
- ".gitignore"
|
50
65
|
- ".rubocop.yml"
|
51
66
|
- ".rubocop_todo.yml"
|
52
67
|
- ".ruby-version"
|
68
|
+
- ".solargraph.yml"
|
53
69
|
- ".travis.yml"
|
54
70
|
- Gemfile
|
55
71
|
- Gemfile.lock
|
@@ -57,6 +73,7 @@ files:
|
|
57
73
|
- README.md
|
58
74
|
- Rakefile
|
59
75
|
- bin/console
|
76
|
+
- bin/regexgen
|
60
77
|
- bin/setup
|
61
78
|
- lib/regexgen.rb
|
62
79
|
- lib/regexgen/ast.rb
|