command_search 0.11.2 → 0.11.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/command_search.rb +1 -1
- data/lib/command_search/parser.rb +82 -73
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c1b899c749aee5b7a81173484fb0fa69eaffd2ab96a26cc3bff7fb7293c5058
|
4
|
+
data.tar.gz: 95c7404d1176cbfb7db75b07323c2e51c13d449c7dc111f53db15db04982d5cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbcf93763eceef8ce66e809603557bf8a21273c41167fdbac2ab080138af2341dd1e98fb79aa66294e8d6bca32af163b88b38f888d80c929f73f0ec9b5aec3dd
|
7
|
+
data.tar.gz: c748c0a6c709c665c1028a46072c6536966d07f6d4e665ca55058e28d11f82253fdc94b3d5d78f594e0b3df2c65d55eff4e33ae865d34abc319e4e788a3d76c0
|
data/lib/command_search.rb
CHANGED
@@ -2,127 +2,136 @@ module CommandSearch
|
|
2
2
|
module Parser
|
3
3
|
module_function
|
4
4
|
|
5
|
-
def group_parens!(
|
5
|
+
def group_parens!(ast)
|
6
6
|
i = 0
|
7
7
|
opening_idxs = []
|
8
|
-
while i <
|
9
|
-
next i += 1 unless
|
10
|
-
if
|
8
|
+
while i < ast.length
|
9
|
+
next i += 1 unless ast[i][:type] == :paren
|
10
|
+
if ast[i][:value] == '('
|
11
11
|
opening_idxs.push(i)
|
12
|
-
|
12
|
+
ast.delete_at(i)
|
13
13
|
next
|
14
14
|
end
|
15
|
-
|
15
|
+
ast.delete_at(i)
|
16
16
|
opening = opening_idxs.pop()
|
17
17
|
next unless opening
|
18
|
-
val =
|
18
|
+
val = ast.slice(opening, i - opening)
|
19
19
|
if val.count > 1
|
20
|
-
|
20
|
+
ast[opening..(i - 1)] = { type: :and, value: val }
|
21
21
|
i -= val.length
|
22
22
|
next
|
23
23
|
elsif val.count == 1
|
24
|
-
|
24
|
+
ast[opening] = val.first
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def cluster_cmds!(
|
29
|
+
def cluster_cmds!(ast)
|
30
30
|
i = 1
|
31
|
-
while i <
|
32
|
-
type =
|
31
|
+
while i < ast.length - 1
|
32
|
+
type = ast[i][:type]
|
33
33
|
next i += 1 unless type == :colon || type == :compare
|
34
|
-
|
34
|
+
ast[(i - 1)..(i + 1)] = {
|
35
35
|
type: type,
|
36
|
-
nest_op:
|
37
|
-
value: [
|
36
|
+
nest_op: ast[i][:value],
|
37
|
+
value: [ast[i - 1], ast[i + 1]]
|
38
38
|
}
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
def cluster_or!(
|
42
|
+
def cluster_or!(ast)
|
43
43
|
i = 0
|
44
|
-
while i <
|
45
|
-
type =
|
46
|
-
cluster_or!(
|
44
|
+
while i < ast.length
|
45
|
+
type = ast[i][:type]
|
46
|
+
cluster_or!(ast[i][:value]) if type == :and || type == :not
|
47
47
|
next i += 1 unless type == :pipe
|
48
|
-
if i == 0 || i ==
|
49
|
-
|
48
|
+
if i == 0 || i == ast.length - 1
|
49
|
+
ast.delete_at(i)
|
50
50
|
next
|
51
51
|
end
|
52
|
-
val = [
|
52
|
+
val = [ast[i - 1], ast[i + 1]]
|
53
53
|
cluster_or!(val)
|
54
|
-
|
54
|
+
ast[i][:type] = :or
|
55
|
+
ast[i][:value] = val
|
56
|
+
ast.delete_at(i + 1)
|
57
|
+
ast.delete_at(i - 1)
|
55
58
|
end
|
56
59
|
end
|
57
60
|
|
58
|
-
def cluster_not!(
|
59
|
-
i =
|
61
|
+
def cluster_not!(ast)
|
62
|
+
i = ast.length
|
60
63
|
while i > 0
|
61
64
|
i -= 1
|
62
|
-
type =
|
63
|
-
cluster_not!(
|
65
|
+
type = ast[i][:type]
|
66
|
+
cluster_not!(ast[i][:value]) if type == :and
|
64
67
|
next unless type == :minus
|
65
|
-
if i ==
|
66
|
-
|
68
|
+
if i == ast.length - 1
|
69
|
+
ast.delete_at(i)
|
67
70
|
next
|
68
71
|
end
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
}
|
72
|
+
ast[i][:type] = :not
|
73
|
+
ast[i][:value] = [ast[i + 1]]
|
74
|
+
ast.delete_at(i + 1)
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
76
|
-
def unchain!(
|
77
|
-
i =
|
78
|
-
while i <
|
79
|
-
left =
|
80
|
-
right =
|
81
|
-
if types.include?(left) && types.include?(right)
|
82
|
-
input.insert(i + 1, input[i + 1].clone())
|
83
|
-
end
|
78
|
+
def unchain!(ast)
|
79
|
+
i = 1
|
80
|
+
while i < ast.length - 3
|
81
|
+
left = ast[i][:type]
|
82
|
+
right = ast[i + 2][:type]
|
84
83
|
i += 1
|
84
|
+
next unless left == :colon || left == :compare
|
85
|
+
next unless right == :colon || right == :compare
|
86
|
+
ast.insert(i, ast[i].clone())
|
85
87
|
end
|
86
88
|
end
|
87
89
|
|
88
|
-
def
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
input[x][:type] = :str
|
94
|
-
input
|
95
|
-
end
|
90
|
+
def r_merge!(ast, i)
|
91
|
+
ast[i][:type] = :str
|
92
|
+
return unless ast[i + 1] && ast[i + 1][:type] == :str
|
93
|
+
ast[i][:value] = ast[i][:value] + ast[i + 1][:value]
|
94
|
+
ast.delete_at(i + 1)
|
96
95
|
end
|
97
96
|
|
98
|
-
def
|
99
|
-
i =
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
105
|
-
i = 0
|
106
|
-
while i < input.length
|
107
|
-
next i += 1 if ![:compare, :colon].include?(input[i][:type])
|
108
|
-
next i += 1 if i > 0 &&
|
109
|
-
(i < input.count - 1) &&
|
110
|
-
[:str, :number, :quote].include?(input[i - 1][:type]) &&
|
111
|
-
[:str, :number, :quote].include?(input[i + 1][:type])
|
97
|
+
def l_merge!(ast, i)
|
98
|
+
ast[i][:type] = :str
|
99
|
+
return unless ast[i - 1] && ast[i - 1][:type] == :str
|
100
|
+
ast[i][:value] = ast[i - 1][:value] + ast[i][:value]
|
101
|
+
ast.delete_at(i - 1)
|
102
|
+
end
|
112
103
|
|
113
|
-
|
114
|
-
|
104
|
+
def clean!(ast)
|
105
|
+
return unless ast.any?
|
106
|
+
if ast[0][:type] == :colon || ast[0][:type] == :compare
|
107
|
+
r_merge!(ast, 0)
|
108
|
+
end
|
109
|
+
if ast[-1][:type] == :colon || ast[-1][:type] == :compare
|
110
|
+
l_merge!(ast, ast.length - 1)
|
111
|
+
end
|
112
|
+
i = 1
|
113
|
+
while i < ast.length - 1
|
114
|
+
next i += 1 unless ast[i][:type] == :colon || ast[i][:type] == :compare
|
115
|
+
if ast[i + 1][:type] == :minus
|
116
|
+
r_merge!(ast, i + 1)
|
117
|
+
elsif ![:str, :number, :quote].include?(ast[i - 1][:type])
|
118
|
+
r_merge!(ast, i)
|
119
|
+
elsif ![:str, :number, :quote].include?(ast[i + 1][:type])
|
120
|
+
l_merge!(ast, i)
|
121
|
+
else
|
122
|
+
i += 1
|
123
|
+
end
|
115
124
|
end
|
116
125
|
end
|
117
126
|
|
118
|
-
def parse!(
|
119
|
-
|
120
|
-
unchain!(
|
121
|
-
cluster_cmds!(
|
122
|
-
group_parens!(
|
123
|
-
cluster_not!(
|
124
|
-
cluster_or!(
|
125
|
-
|
127
|
+
def parse!(ast)
|
128
|
+
clean!(ast)
|
129
|
+
unchain!(ast)
|
130
|
+
cluster_cmds!(ast)
|
131
|
+
group_parens!(ast)
|
132
|
+
cluster_not!(ast)
|
133
|
+
cluster_or!(ast)
|
134
|
+
ast
|
126
135
|
end
|
127
136
|
end
|
128
137
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: command_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zumbalogy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chronic
|
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
requirements: []
|
63
|
-
rubygems_version: 3.0.
|
63
|
+
rubygems_version: 3.0.6
|
64
64
|
signing_key:
|
65
65
|
specification_version: 4
|
66
66
|
summary: Let users query collections with ease.
|