cql_ruby 0.0.12 → 0.0.13
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/bin/cql_ruby +139 -139
- data/lib/cql_ruby.rb +9 -15
- data/lib/cql_ruby/abstract_printer.rb +12 -12
- data/lib/cql_ruby/console_printer.rb +97 -97
- data/lib/cql_ruby/crumb_collector.rb +18 -18
- data/lib/cql_ruby/defs.rb +3 -0
- data/lib/cql_ruby/executor.rb +194 -194
- data/lib/cql_ruby/filter_evaluator.rb +177 -178
- data/lib/cql_ruby/filter_reader.rb +124 -130
- data/lib/cql_ruby/pattern_matcher.rb +55 -57
- metadata +17 -2
|
@@ -1,130 +1,124 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
#
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
# @attribute [Array<
|
|
69
|
-
attr_reader :
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
@
|
|
114
|
-
elsif %w[
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
nil
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CqlRuby
|
|
4
|
+
#
|
|
5
|
+
# Reads and provides filters.
|
|
6
|
+
#
|
|
7
|
+
# Accepted filters and syntax:
|
|
8
|
+
#
|
|
9
|
+
# Type:
|
|
10
|
+
#
|
|
11
|
+
# type:[name](,[name])*
|
|
12
|
+
# example: type:def,send
|
|
13
|
+
#
|
|
14
|
+
class FilterReader
|
|
15
|
+
class HierarchyPattern
|
|
16
|
+
SELF_MARKER = 'X'
|
|
17
|
+
|
|
18
|
+
def self.from(raw_value)
|
|
19
|
+
parts = raw_value.split('-')
|
|
20
|
+
self_marker_idx = parts.index(SELF_MARKER)
|
|
21
|
+
raise "Missing self marker '#{SELF_MARKER}' in hierarchy pattern." if self_marker_idx.nil?
|
|
22
|
+
|
|
23
|
+
ancestors = parts[0...self_marker_idx]
|
|
24
|
+
descendants = parts[self_marker_idx + 1..]
|
|
25
|
+
|
|
26
|
+
new(ancestors, descendants)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
attr_reader :ancestors
|
|
30
|
+
attr_reader :descendants
|
|
31
|
+
|
|
32
|
+
def initialize(ancestors, descendants)
|
|
33
|
+
@ancestors = ancestors
|
|
34
|
+
@descendants = descendants
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
class NodeSpec < Struct.new(:type, :name)
|
|
39
|
+
class << self
|
|
40
|
+
#
|
|
41
|
+
# @param [String] raw_value
|
|
42
|
+
# Format: TYPE(=NAME|=*)
|
|
43
|
+
# Accepted types: class, module, def, block
|
|
44
|
+
#
|
|
45
|
+
def from(raw_value)
|
|
46
|
+
type, name = raw_value.split('=')
|
|
47
|
+
name ||= CqlRuby::MATCH_ANYTHING
|
|
48
|
+
|
|
49
|
+
raise "Type '#{type}' is not recognized. See 'cql_ruby --help' for allowed types." unless Parser::Meta::NODE_TYPES.member?(type.to_sym)
|
|
50
|
+
|
|
51
|
+
new(type, name)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def restrict_name?
|
|
56
|
+
name != CqlRuby::MATCH_ANYTHING
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
NESTING_ALLOWED_TYPES = %w[class module def block].freeze
|
|
61
|
+
|
|
62
|
+
# @attribute [Array<Symbol>] allowed_types
|
|
63
|
+
attr_reader :allowed_types
|
|
64
|
+
# @attribute [Array<CqlRuby::FilterReader::NodeSpec>] nest_under
|
|
65
|
+
attr_reader :nest_under
|
|
66
|
+
# @attribute [Array<CqlRuby::FilterReader::NodeSpec>] has_leaves
|
|
67
|
+
attr_reader :has_leaves
|
|
68
|
+
# @attribute [Array<CqlRuby::FilterReader::HierarchyPattern>] patterns
|
|
69
|
+
attr_reader :patterns
|
|
70
|
+
|
|
71
|
+
def initialize(raw_filters = [])
|
|
72
|
+
super()
|
|
73
|
+
|
|
74
|
+
@allowed_types = []
|
|
75
|
+
@nest_under = []
|
|
76
|
+
@has_leaves = []
|
|
77
|
+
@patterns = []
|
|
78
|
+
|
|
79
|
+
parse_raw_filters(raw_filters)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def restrict_types?
|
|
83
|
+
!@allowed_types.empty?
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def restrict_nesting?
|
|
87
|
+
!@nest_under.empty?
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def restrict_children?
|
|
91
|
+
!@has_leaves.empty?
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def restrict_pattern?
|
|
95
|
+
!@patterns.empty?
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
private
|
|
99
|
+
|
|
100
|
+
# @param [Array<String>] raw_filters
|
|
101
|
+
def parse_raw_filters(raw_filters)
|
|
102
|
+
raw_filters.each do |raw_filter|
|
|
103
|
+
name, value = raw_filter.split(':')
|
|
104
|
+
raise "Unrecognized filter: #{raw_filter}" if name.nil? || value.nil?
|
|
105
|
+
|
|
106
|
+
if %w[type t].include?(name)
|
|
107
|
+
@allowed_types += value.split(',').map(&:to_sym)
|
|
108
|
+
elsif %w[nest n].include?(name)
|
|
109
|
+
spec = NodeSpec.from(value)
|
|
110
|
+
raise "Unknown type for nesting: '#{spec.type}' from '#{raw_filter}'. Allowed: #{NESTING_ALLOWED_TYPES}" unless NESTING_ALLOWED_TYPES.include?(spec.type)
|
|
111
|
+
raise "Type #{spec.type} cannot have a name." if %w[block].include?(spec.type) && spec.restrict_name?
|
|
112
|
+
|
|
113
|
+
@nest_under << spec
|
|
114
|
+
elsif %w[has h].include?(name)
|
|
115
|
+
@has_leaves << NodeSpec.from(value)
|
|
116
|
+
elsif %w[pattern p].include?(name)
|
|
117
|
+
@patterns << HierarchyPattern.from(value)
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
nil
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
@@ -1,57 +1,55 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
module CqlRuby
|
|
3
|
-
module PatternMatcher
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
fops
|
|
38
|
-
fops |= Regexp::
|
|
39
|
-
fops |= Regexp::
|
|
40
|
-
fops |= Regexp::
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
end
|
|
57
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module CqlRuby
|
|
3
|
+
module PatternMatcher
|
|
4
|
+
def self.match?(pattern, subject)
|
|
5
|
+
pattern = pattern.to_s
|
|
6
|
+
return true if pattern == CqlRuby::MATCH_ANYTHING
|
|
7
|
+
|
|
8
|
+
subject = subject.to_s
|
|
9
|
+
|
|
10
|
+
if regex?(pattern)
|
|
11
|
+
regex_match?(pattern, subject)
|
|
12
|
+
elsif partial_string?(pattern)
|
|
13
|
+
partial_string_match?(pattern, subject)
|
|
14
|
+
else
|
|
15
|
+
full_string_match?(pattern, subject)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.regex?(pattern)
|
|
20
|
+
pattern[0..1] == 'r/'
|
|
21
|
+
end
|
|
22
|
+
private_class_method :regex?
|
|
23
|
+
|
|
24
|
+
def self.partial_string?(pattern)
|
|
25
|
+
pattern[0] == '%'
|
|
26
|
+
end
|
|
27
|
+
private_class_method :partial_string?
|
|
28
|
+
|
|
29
|
+
def self.regex_match?(pattern, subject)
|
|
30
|
+
pattern = pattern[2..]
|
|
31
|
+
delim_idx = pattern.rindex('/')
|
|
32
|
+
mods = pattern[delim_idx + 1..].chars
|
|
33
|
+
pattern = pattern[0..delim_idx - 1]
|
|
34
|
+
|
|
35
|
+
fops = 0
|
|
36
|
+
fops |= Regexp::IGNORECASE if mods.include?('i')
|
|
37
|
+
fops |= Regexp::MULTILINE if mods.include?('m')
|
|
38
|
+
fops |= Regexp::EXTENDED if mods.include?('x')
|
|
39
|
+
fops |= Regexp::FIXEDENCODING if mods.include?('f')
|
|
40
|
+
fops |= Regexp::NOENCODING if mods.include?('n')
|
|
41
|
+
Regexp.new(pattern, fops).match?(subject)
|
|
42
|
+
end
|
|
43
|
+
private_class_method :regex_match?
|
|
44
|
+
|
|
45
|
+
def self.full_string_match?(pattern, subject)
|
|
46
|
+
pattern == subject
|
|
47
|
+
end
|
|
48
|
+
private_class_method :full_string_match?
|
|
49
|
+
|
|
50
|
+
def self.partial_string_match?(pattern, subject)
|
|
51
|
+
!subject.index(pattern[1..]).nil?
|
|
52
|
+
end
|
|
53
|
+
private_class_method :partial_string_match?
|
|
54
|
+
end
|
|
55
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cql_ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.13
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- itarato
|
|
@@ -30,6 +30,20 @@ dependencies:
|
|
|
30
30
|
- - ">="
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
32
|
version: 2.7.1
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: rspec
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
type: :development
|
|
41
|
+
prerelease: false
|
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
33
47
|
description:
|
|
34
48
|
email: it.arato@gmail.com
|
|
35
49
|
executables:
|
|
@@ -42,6 +56,7 @@ files:
|
|
|
42
56
|
- lib/cql_ruby/abstract_printer.rb
|
|
43
57
|
- lib/cql_ruby/console_printer.rb
|
|
44
58
|
- lib/cql_ruby/crumb_collector.rb
|
|
59
|
+
- lib/cql_ruby/defs.rb
|
|
45
60
|
- lib/cql_ruby/executor.rb
|
|
46
61
|
- lib/cql_ruby/filter_evaluator.rb
|
|
47
62
|
- lib/cql_ruby/filter_reader.rb
|
|
@@ -65,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
65
80
|
- !ruby/object:Gem::Version
|
|
66
81
|
version: '0'
|
|
67
82
|
requirements: []
|
|
68
|
-
rubygems_version: 3.0.
|
|
83
|
+
rubygems_version: 3.0.1
|
|
69
84
|
signing_key:
|
|
70
85
|
specification_version: 4
|
|
71
86
|
summary: Code Query Language for Ruby
|