kleene 0.7.0 → 0.8.0
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 +4 -4
- data/.rubocop.yml +14 -0
- data/Gemfile.lock +1 -1
- 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: 03ad3b5293809eb768a2bb47eb3f1a9ccee680d7d71873d75c7511eb9fc711be
|
4
|
+
data.tar.gz: cb0e8f6600e878153bf2454cea8e3dd4dc67d1872660bd1a77b0648a5f91efa5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7043fb3024741baf02ed48de44d14c616d4bb83315ad23481d0908c962fbd41a56a9ccc8d0444577526baa94933621b43203c29b2cba14192d98d8f5a7246ef
|
7
|
+
data.tar.gz: a78f7aee47db290800efa79cb6096d604f30dc249907db8759bb319b29f01d378801395557a9a8760fc3b6d06e2e447335398de053e1594233da62128a3aafb9
|
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
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.8.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
|