kleene 0.7.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +14 -0
- data/Gemfile.lock +5 -5
- data/lib/kleene/kleene.rb +4 -7
- data/lib/kleene/naive_online_regex.rb +56 -17
- data/lib/kleene/patches.rb +2 -4
- data/lib/kleene/version.rb +1 -1
- data/lib/kleene.rb +13 -13
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12f76babc39f4051cb6a1faf6dbcfbe03d3a52735c8fa2bd3b360b031ae9a0f8
|
4
|
+
data.tar.gz: c4bc2f26400e80aeca549fdba04c84ef863f1d04c047b885fbaa91668690a4cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7501f2ad597e59333a792271333e981ffd1e20a4246b94a5f90d4063a311c32815b5c1413d2e9111a1d92da5a5d2eb6168f1c0e175a3a880b0ecf30530766897
|
7
|
+
data.tar.gz: e7acafe55b63f4d7f4a887af73490a05462be0394c575eedfa42048b454921c44282a17e7e336f2cf4f31831b7fea04fc3a04568b3d5cc2ede467f6e58b655d8
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
AllCops:
|
2
|
+
StyleGuideBaseURL: https://rubystyle.guide
|
3
|
+
|
4
|
+
Layout/SpaceInsideBlockBraces:
|
5
|
+
SpaceBeforeBlockParameters: false
|
6
|
+
|
7
|
+
Layout/LineLength:
|
8
|
+
Max: 160
|
9
|
+
|
10
|
+
Style/AccessorGrouping:
|
11
|
+
EnforcedStyle: separated
|
12
|
+
|
13
|
+
Style/Encoding:
|
14
|
+
Enabled: true
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kleene (0.
|
4
|
+
kleene (0.8.0)
|
5
5
|
activesupport (~> 7.1)
|
6
6
|
regexp_parser (~> 2.8)
|
7
7
|
|
@@ -20,13 +20,13 @@ GEM
|
|
20
20
|
tzinfo (~> 2.0)
|
21
21
|
ast (2.4.2)
|
22
22
|
backport (1.2.0)
|
23
|
-
base64 (0.
|
24
|
-
benchmark (0.
|
23
|
+
base64 (0.2.0)
|
24
|
+
benchmark (0.3.0)
|
25
25
|
bigdecimal (3.1.4)
|
26
26
|
concurrent-ruby (1.2.2)
|
27
27
|
connection_pool (2.4.1)
|
28
28
|
diff-lcs (1.5.0)
|
29
|
-
drb (2.
|
29
|
+
drb (2.2.0)
|
30
30
|
ruby2_keywords
|
31
31
|
e2mmap (0.1.0)
|
32
32
|
i18n (1.14.1)
|
@@ -39,7 +39,7 @@ GEM
|
|
39
39
|
kramdown (~> 2.0)
|
40
40
|
language_server-protocol (3.17.0.3)
|
41
41
|
minitest (5.20.0)
|
42
|
-
mutex_m (0.
|
42
|
+
mutex_m (0.2.0)
|
43
43
|
nokogiri (1.15.4-x86_64-linux)
|
44
44
|
racc (~> 1.4)
|
45
45
|
parallel (1.23.0)
|
data/lib/kleene/kleene.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# this is a port and extension of https://github.com/davidkellis/kleene/
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require_relative
|
3
|
+
require_relative './dsl'
|
4
|
+
require_relative './nfa'
|
5
|
+
require_relative './dfa'
|
6
6
|
|
7
7
|
module Kleene
|
8
8
|
# The default alphabet consists of the following:
|
@@ -28,7 +28,6 @@ module Kleene
|
|
28
28
|
State.new(final, true)
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
31
|
attr_reader :id # : Int32
|
33
32
|
attr_accessor :final # : Bool
|
34
33
|
attr_accessor :error # : Bool
|
@@ -76,13 +75,11 @@ module Kleene
|
|
76
75
|
end
|
77
76
|
|
78
77
|
def ==(other)
|
79
|
-
@string == other.string &&
|
80
|
-
@range == other.range
|
78
|
+
@string == other.string && @range == other.range
|
81
79
|
end
|
82
80
|
|
83
81
|
def eql?(other)
|
84
82
|
self == other
|
85
83
|
end
|
86
84
|
end
|
87
|
-
|
88
85
|
end
|
@@ -1,6 +1,5 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require_relative "./kleene"
|
1
|
+
require 'set'
|
2
|
+
require_relative './kleene'
|
4
3
|
|
5
4
|
module Kleene
|
6
5
|
class NaiveOnlineRegex
|
@@ -12,52 +11,92 @@ module Kleene
|
|
12
11
|
end
|
13
12
|
|
14
13
|
def reset
|
15
|
-
@buffer =
|
16
|
-
@matches_per_regex =
|
14
|
+
@buffer = ''
|
15
|
+
@matches_per_regex = {} # Hash(Regexp, Set(OnlineMatch))
|
17
16
|
end
|
18
17
|
|
19
18
|
# #ingest(input) is the online-style matching interface
|
20
|
-
def ingest(input,
|
19
|
+
def ingest(input, _debug = false) # : Set(OnlineMatch)
|
21
20
|
@buffer << input
|
22
21
|
new_online_matches = Set.new
|
23
22
|
@regexen.each do |regex|
|
24
23
|
existing_matches_for_regex = (@matches_per_regex[regex] ||= Set.new)
|
25
|
-
scan_matches = @buffer.scan_matches(regex)
|
26
|
-
|
24
|
+
scan_matches = @buffer.scan_matches(regex)
|
25
|
+
scan_online_matches = scan_matches.map {|match_data| OnlineMatch.new(regex, match_data) }.to_set
|
26
|
+
new_matches = scan_online_matches - existing_matches_for_regex # new_matches : Set(OnlineMatch)
|
27
27
|
existing_matches_for_regex.merge(new_matches)
|
28
|
-
new_online_matches.merge(new_matches
|
28
|
+
new_online_matches.merge(new_matches)
|
29
29
|
end
|
30
30
|
resize_buffer!
|
31
31
|
new_online_matches
|
32
32
|
end
|
33
33
|
|
34
|
-
def matches # Hash(Regexp, Set(
|
34
|
+
def matches # Hash(Regexp, Set(OnlineMatch))
|
35
35
|
@matches_per_regex
|
36
36
|
end
|
37
37
|
|
38
|
-
def matches_for(regex) # Set(
|
38
|
+
def matches_for(regex) # Set(OnlineMatch) | Nil
|
39
39
|
@matches_per_regex[regex]
|
40
40
|
end
|
41
41
|
|
42
42
|
def resize_buffer!
|
43
|
-
|
44
|
-
|
43
|
+
return unless @buffer.size > @window_size
|
44
|
+
|
45
|
+
number_of_chars_at_front_of_buffer_that_should_roll_off = @buffer.size - @window_size
|
46
|
+
|
47
|
+
@buffer = @buffer[-@window_size..-1]
|
48
|
+
drop_matches_that_have_rolled_off(number_of_chars_at_front_of_buffer_that_should_roll_off)
|
49
|
+
end
|
50
|
+
|
51
|
+
def drop_matches_that_have_rolled_off(number_of_chars_at_front_of_buffer_that_rolled_off)
|
52
|
+
@matches_per_regex.each do |regex, match_set|
|
53
|
+
match_set.reject! {|online_match| online_match.offsets.first < number_of_chars_at_front_of_buffer_that_rolled_off }
|
45
54
|
end
|
46
55
|
end
|
47
56
|
end
|
48
57
|
|
49
58
|
# A {Regexp, MatchData} pair
|
50
59
|
class OnlineMatch
|
51
|
-
|
52
|
-
attr_reader :
|
60
|
+
# Regexp # MatchData # Array(Int) -> [start, end] # excludes the end offset
|
61
|
+
attr_reader :regex
|
62
|
+
attr_reader :match
|
63
|
+
attr_reader :offsets # Regexp # MatchData # Array(Int) -> [start, end] # excludes the end offset
|
64
|
+
|
53
65
|
def initialize(regex, match)
|
54
|
-
@regex, @match = regex, match
|
66
|
+
@regex, @match, @offsets = regex, match
|
67
|
+
@offsets = match.offset(0)
|
55
68
|
end
|
69
|
+
|
70
|
+
def identity
|
71
|
+
[@regex, @offsets, to_a]
|
72
|
+
end
|
73
|
+
|
74
|
+
def ==(other)
|
75
|
+
identity == other.identity
|
76
|
+
end
|
77
|
+
|
78
|
+
def eql?(other)
|
79
|
+
self == other
|
80
|
+
end
|
81
|
+
|
82
|
+
def hash
|
83
|
+
identity.hash
|
84
|
+
end
|
85
|
+
|
56
86
|
def to_a
|
57
87
|
@match.to_a
|
58
88
|
end
|
89
|
+
|
59
90
|
def to_h
|
60
|
-
{@regex => to_a}
|
91
|
+
{ @regex => to_a, :offsets => @offsets }
|
92
|
+
end
|
93
|
+
|
94
|
+
def captures
|
95
|
+
@match.captures
|
96
|
+
end
|
97
|
+
|
98
|
+
def [](*args)
|
99
|
+
@match.method(:[]).call(*args)
|
61
100
|
end
|
62
101
|
end
|
63
102
|
end
|
data/lib/kleene/patches.rb
CHANGED
@@ -12,14 +12,12 @@ module Enumerable
|
|
12
12
|
ary = []
|
13
13
|
each do |e|
|
14
14
|
v = block.call(e)
|
15
|
-
unless v.nil?
|
16
|
-
ary << v
|
17
|
-
end
|
15
|
+
ary << v unless v.nil?
|
18
16
|
end
|
19
17
|
ary
|
20
18
|
end
|
21
19
|
|
22
|
-
|
20
|
+
alias includes? include?
|
23
21
|
end
|
24
22
|
|
25
23
|
class String
|
data/lib/kleene/version.rb
CHANGED
data/lib/kleene.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require_relative
|
7
|
-
require_relative
|
8
|
-
require_relative
|
9
|
-
require_relative
|
10
|
-
require_relative
|
11
|
-
require_relative
|
12
|
-
require_relative
|
13
|
-
require_relative
|
14
|
-
require_relative
|
15
|
-
require_relative
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/core_ext'
|
5
|
+
require 'regexp_parser'
|
6
|
+
require_relative 'kleene/version'
|
7
|
+
require_relative 'kleene/patches'
|
8
|
+
require_relative 'kleene/kleene'
|
9
|
+
require_relative 'kleene/dsl'
|
10
|
+
require_relative 'kleene/nfa'
|
11
|
+
require_relative 'kleene/dfa'
|
12
|
+
require_relative 'kleene/multi_match_dfa'
|
13
|
+
require_relative 'kleene/online_dfa'
|
14
|
+
require_relative 'kleene/naive_online_regex'
|
15
|
+
require_relative 'kleene/parser'
|
16
16
|
|
17
17
|
module Kleene
|
18
18
|
class Error < StandardError; end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kleene
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Ellis
|
@@ -47,6 +47,7 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- ".rspec"
|
50
|
+
- ".rubocop.yml"
|
50
51
|
- Gemfile
|
51
52
|
- Gemfile.lock
|
52
53
|
- LICENSE
|