kql 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: adbf2e39a60b4bb6c6cb198a642145d24ca90cd5a632aa8a35466368e58558af
4
+ data.tar.gz: a3b1082afd00ff33d85f285bf98e603a14c5434f8d658b285201a1a2e3c1cd69
5
+ SHA512:
6
+ metadata.gz: 6c91a8f3301fb1ef6175f77f8f99f9dc1dbb24f6afad7aa71048542e29b2f0b6f1fa5ea75580b251b8969c3f20f7d93da2dc24ef12822da7b3edbb900a13444d
7
+ data.tar.gz: 8c9fce957787ce1c370213b28429c8b4b8811daf2f3320d00d9b90c8ba2a283899a549e1f9d54a319cf1edbe9e7a54da9a95816ba2568537b82d2bfca241e880
@@ -0,0 +1,16 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0.2
14
+ bundler-cache: true
15
+ - name: Run the default task
16
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ lib/kql/kql.tab.rb
10
+ kql.output
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at danini@hey.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in kql.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kql (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ kdl (1.0.2)
10
+ simpleidn (~> 0.2.1)
11
+ minitest (5.14.4)
12
+ racc (1.5.2)
13
+ rake (13.0.6)
14
+ simpleidn (0.2.1)
15
+ unf (~> 0.1.4)
16
+ unf (0.1.4)
17
+ unf_ext
18
+ unf_ext (0.0.8)
19
+
20
+ PLATFORMS
21
+ x86_64-linux
22
+
23
+ DEPENDENCIES
24
+ kdl (~> 1.0.0)
25
+ kql!
26
+ minitest (~> 5.0)
27
+ racc (~> 1.5)
28
+ rake (~> 13.0)
29
+
30
+ BUNDLED WITH
31
+ 2.2.32
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Danielle Smith
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # KQL Ruby
2
+
3
+ [KDL](https://kdl.dev) Query Language for [kdl-rb](https://github.com/danini-the-panini/kdl-rb)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'kql'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install kql
20
+
21
+ ## Usage
22
+
23
+ Parse and execute a query:
24
+
25
+ ```ruby
26
+ query = KQL.parse_query('a > b[foo]')
27
+ query.execute(document) #=> [#<KDL::Node...>, ...]
28
+ ```
29
+
30
+ Or do both at once:
31
+
32
+ ```ruby
33
+ KQL.query_document(document, 'a > b[foo]') #=> [#<KDL::Node...>, ...]
34
+ ```
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
+
40
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/danini-the-panini/kql-rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/danini-the-panini/kql-rb/blob/master/CODE_OF_CONDUCT.md).
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
49
+
50
+ ## Code of Conduct
51
+
52
+ Everyone interacting in the Kql project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/danini-the-panini/kql-rb/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ file 'lib/kql/kql.tab.rb' => ['lib/kql/kql.yy'] do
7
+ raise "racc command failed" unless system 'bin/racc lib/kql/kql.yy'
8
+ end
9
+ task :racc => 'lib/kql/kql.tab.rb'
10
+
11
+ Rake::TestTask.new(:test => :racc) do |t|
12
+ t.libs << "test"
13
+ t.libs << "lib"
14
+ t.test_files = FileList["test/**/*_test.rb"]
15
+ end
16
+
17
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "kql"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/racc ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'racc' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("racc", "racc")
data/bin/rake ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rake", "rake")
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/kql.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/kql/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "kql"
7
+ spec.version = KQL::VERSION
8
+ spec.authors = ["Danielle Smith"]
9
+ spec.email = ["danini@hey.com"]
10
+
11
+ spec.summary = "KDL Query Language."
12
+ spec.description = "A query language for navigating KDL documents"
13
+ spec.homepage = "https://kdl.dev"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.4.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/danini-the-panini/kql-rb"
19
+ spec.metadata["changelog_uri"] = "https://github.com/danini-the-panini/kql-rb/releases"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
25
+ end
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency 'racc', '~> 1.5'
29
+ spec.add_development_dependency 'kdl', '~> 1.0.0'
30
+ end
@@ -0,0 +1,99 @@
1
+ module KQL
2
+ class Accessor
3
+ class Val < Accessor
4
+ attr_reader :index
5
+
6
+ def initialize(index)
7
+ @index = index
8
+ end
9
+
10
+ def execute(node)
11
+ node.arguments[index]
12
+ end
13
+
14
+ def match?(node)
15
+ node.arguments.size > index
16
+ end
17
+
18
+ def ==(other)
19
+ return false unless other.is_a?(Val)
20
+
21
+ other.index == index
22
+ end
23
+ end
24
+
25
+ class Prop < Accessor
26
+ attr_reader :name
27
+
28
+ def initialize(name)
29
+ @name = name
30
+ end
31
+
32
+ def execute(node)
33
+ node.properties[name]
34
+ end
35
+
36
+ def match?(node)
37
+ node.properties.key?(name)
38
+ end
39
+
40
+ def ==(other)
41
+ return false unless other.is_a?(Prop)
42
+
43
+ other.name == name
44
+ end
45
+ end
46
+
47
+ singleton :Values, Accessor do
48
+ def execute(node)
49
+ node.arguments
50
+ end
51
+
52
+ def match?(node)
53
+ true
54
+ end
55
+ end
56
+
57
+ singleton :Props, Accessor do
58
+ def execute(node)
59
+ node.properties
60
+ end
61
+
62
+ def match?(node)
63
+ true
64
+ end
65
+ end
66
+
67
+ singleton :Name, Accessor do
68
+ def execute(node)
69
+ node.name
70
+ end
71
+
72
+ def match?(node)
73
+ true
74
+ end
75
+ end
76
+
77
+ singleton :Tag, Accessor do
78
+ def execute(node)
79
+ node.type
80
+ end
81
+
82
+ def match?(node)
83
+ !node.type.nil?
84
+ end
85
+ end
86
+
87
+ class Tuple < Accessor
88
+ attr_reader :accessors
89
+
90
+ def initialize(accessors)
91
+ @accessors = accessors
92
+ end
93
+
94
+ def execute(node)
95
+ accessors.map { |a| a.execute(node) }
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,41 @@
1
+ module KQL
2
+ class Combinator
3
+ singleton :Child, Combinator do
4
+ def execute(context, selector)
5
+ selector.execute(Query::Context.new(context.children))
6
+ end
7
+ end
8
+
9
+ singleton :ImmediateChild, Combinator do
10
+ def execute(context, selector)
11
+ selector.execute(Query::Context.new(context.children(stop: true)))
12
+ end
13
+ end
14
+
15
+ singleton :Sibling, Combinator do
16
+ def execute(context, selector)
17
+ selected_nodes = context.selected_nodes
18
+ .flat_map { |node|
19
+ node.siblings
20
+ .each_with_index
21
+ .select { |n, i| i > node.index }
22
+ .map { |n, i| Query::SelectedNode.new(n, node.node.children, i, stop: true) }
23
+ }
24
+ selector.execute(Query::Context.new(selected_nodes))
25
+ end
26
+ end
27
+
28
+ singleton :ImmediateSibling, Combinator do
29
+ def execute(context, selector)
30
+ selected_nodes = context.selected_nodes
31
+ .flat_map { |node|
32
+ node.siblings
33
+ .each_with_index
34
+ .select { |n, i| i == node.index + 1 }
35
+ .map { |n, i| Query::SelectedNode.new(n, node.node.children, i, stop: true) }
36
+ }
37
+ selector.execute(Query::Context.new(selected_nodes))
38
+ end
39
+ end
40
+ end
41
+ end
data/lib/kql/filter.rb ADDED
@@ -0,0 +1,59 @@
1
+ module KQL
2
+ class Filter
3
+ attr_reader :node, :tag, :matchers
4
+
5
+ def initialize(node: nil, tag: nil, matchers: [])
6
+ @node = node
7
+ @tag = tag
8
+ @matchers = matchers
9
+ end
10
+
11
+ def ==(other)
12
+ return false unless other.is_a?(Filter)
13
+
14
+ other.node == node &&
15
+ other.tag == tag &&
16
+ other.matchers == matchers
17
+ end
18
+
19
+ def execute(context)
20
+ selected_nodes = []
21
+
22
+ context.selected_nodes.flat_map do |n|
23
+ selected_nodes << n if match?(n.node)
24
+ selected_nodes += filter_nodes(n.node.children, n.node) unless n.stop
25
+ end
26
+
27
+ Query::Context.new(selected_nodes)
28
+ end
29
+
30
+ singleton :Top, Filter do
31
+ def initialize
32
+ super
33
+ end
34
+
35
+ def execute(context)
36
+ raise "cannot use top on non-root nodes" unless context.top?
37
+
38
+ context
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def filter_nodes(nodes, parent = nil)
45
+ filtered = nodes.select { |n| match?(n) }
46
+ .each_with_index
47
+ .map { |n, i| Query::SelectedNode.new(n, parent, i) }
48
+ children = nodes.flat_map { |n| filter_nodes(n.children, n) }
49
+ filtered + children
50
+ end
51
+
52
+ def match?(n)
53
+ return false unless node.nil? || node == n.name
54
+ return false unless tag.nil? || tag.match?(n)
55
+ return matchers.all? { |m| m.match?(n) } unless matchers.empty?
56
+ true
57
+ end
58
+ end
59
+ end
data/lib/kql/kql.yy ADDED
@@ -0,0 +1,98 @@
1
+ class KQL::Parser
2
+ options no_result_var
3
+ token IDENT
4
+ STRING INTEGER FLOAT TRUE FALSE NULL
5
+ LPAREN RPAREN
6
+ LBRACKET RBRACKET
7
+ COMMA
8
+ VAL PROP
9
+ TOP PROPS VALUES TAG NAME
10
+ EQUALS NOT_EQUALS GTE GT LTE LT OR
11
+ STARTS_WITH ENDS_WITH INCLUDES
12
+ TILDE PLUS
13
+ MAP
14
+
15
+ rule
16
+ query : alternatives { ::KQL::Query.new(val[0]) }
17
+ | alternatives MAP mapping { ::KQL::Mapping.new(val[0], val[2]) }
18
+
19
+ alternatives : selector { [val[0]] }
20
+ | selector OR alternatives { [val[0], *val[2]] }
21
+
22
+ selector : node_filter combinator selector { ::KQL::Selector::Combined.new(val[0], val[1], val[2]) }
23
+ | node_filter selector { ::KQL::Selector::Combined.new(val[0], ::KQL::Combinator::Child, val[1]) }
24
+ | node_filter { ::KQL::Selector.new(val[0]) }
25
+
26
+ combinator : GT { ::KQL::Combinator::ImmediateChild }
27
+ | TILDE { ::KQL::Combinator::Sibling }
28
+ | PLUS { ::KQL::Combinator::ImmediateSibling }
29
+
30
+ node_filter : TOP { ::KQL::Filter::Top }
31
+ | IDENT { ::KQL::Filter.new(node: val[0].value) }
32
+ | IDENT matchers { ::KQL::Filter.new(node: val[0].value, matchers: val[1]) }
33
+ | tag IDENT { ::KQL::Filter.new(node: val[1].value, tag: val[0]) }
34
+ | tag IDENT matchers { ::KQL::Filter.new(node: val[1].value, tag: val[0], matchers: val[2]) }
35
+ | tag matchers { ::KQL::Filter.new(tag: val[0], matchers: val[1]) }
36
+ | tag { ::KQL::Filter.new(tag: val[0]) }
37
+ | matchers { ::KQL::Filter.new(matchers: val[0]) }
38
+
39
+ tag : LPAREN IDENT RPAREN { ::KQL::Matcher::Tag.new(val[1].value) }
40
+ | LPAREN RPAREN { ::KQL::Matcher::AnyTag }
41
+
42
+ matchers : matcher { [val[0]] }
43
+ | matcher matchers { [val[0], *val[1]] }
44
+
45
+ matcher : LBRACKET matcher_accessor matcher_operator matcher_comparison RBRACKET { ::KQL::Matcher::Comparison.new(val[1], val[2], val[3]) }
46
+ | LBRACKET matcher_accessor RBRACKET { val[1] }
47
+ | LBRACKET RBRACKET { ::KQL::Matcher::Any }
48
+
49
+ matcher_accessor : IDENT { ::KQL::Accessor::Prop.new(val[0].value) }
50
+ | prop
51
+ | val
52
+ | NAME { ::KQL::Accessor::Name }
53
+ | TAG { ::KQL::Accessor::Tag }
54
+
55
+ matcher_comparison : INTEGER { ::KQL::Matcher::Value.new(val[0].value) }
56
+ | FLOAT { ::KQL::Matcher::Value.new(val[0].value) }
57
+ | STRING { ::KQL::Matcher::Value.new(val[0].value) }
58
+ | NULL { ::KQL::Matcher::Value.new(nil) }
59
+ | TRUE { ::KQL::Matcher::Value.new(true) }
60
+ | FALSE { ::KQL::Matcher::Value.new(false) }
61
+ | LPAREN IDENT RPAREN { ::KQL::Matcher::Tag.new(val[1].value) }
62
+
63
+ matcher_operator : EQUALS { ::KQL::Operator::Equals }
64
+ | NOT_EQUALS { ::KQL::Operator::NotEquals }
65
+ | GTE { ::KQL::Operator::GreaterThanOrEqual }
66
+ | GT { ::KQL::Operator::GreaterThan }
67
+ | LTE { ::KQL::Operator::LessThanOrEqual }
68
+ | LT { ::KQL::Operator::LessThan }
69
+ | STARTS_WITH { ::KQL::Operator::StartsWith }
70
+ | ENDS_WITH { ::KQL::Operator::EndsWith }
71
+ | INCLUDES { ::KQL::Operator::Includes }
72
+
73
+ mapping : accessor
74
+ | LPAREN mapping_tuple RPAREN { ::KQL::Accessor::Tuple.new(val[1]) }
75
+
76
+ mapping_tuple : accessor COMMA mapping_tuple { [val[0], *val[2]] }
77
+ | accessor { [val[0]] }
78
+
79
+ accessor : matcher_accessor
80
+ | PROPS { ::KQL::Accessor::Props }
81
+ | VALUES { ::KQL::Accessor::Values }
82
+
83
+ prop : PROP LPAREN IDENT RPAREN { ::KQL::Accessor::Prop.new(val[2].value) }
84
+
85
+ val : VAL LPAREN RPAREN { ::KQL::Accessor::Val.new(0) }
86
+ | VAL LPAREN INTEGER RPAREN { ::KQL::Accessor::Val.new(val[2].value) }
87
+
88
+ ---- inner
89
+ def parse(str)
90
+ @tokenizer = ::KQL::Tokenizer.new(str)
91
+ do_parse
92
+ end
93
+
94
+ private
95
+
96
+ def next_token
97
+ @tokenizer.next_token
98
+ end