query-ruby 0.1.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.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.github/dependabot.yml +15 -0
  3. data/.github/workflows/ci.yml +38 -0
  4. data/.gitignore +30 -0
  5. data/.node-version +1 -0
  6. data/.npm-version +1 -0
  7. data/.prettierignore +2 -0
  8. data/.rspec +1 -0
  9. data/.rubocop.yml +130 -0
  10. data/.ruby-version +1 -0
  11. data/.tool-versions +3 -0
  12. data/Gemfile +22 -0
  13. data/Gemfile.lock +249 -0
  14. data/LICENSE +19 -0
  15. data/README.md +3 -0
  16. data/Rakefile +5 -0
  17. data/VERSION +1 -0
  18. data/bin/query +52 -0
  19. data/lib/query/combiner.rb +33 -0
  20. data/lib/query/decompiler.rb +41 -0
  21. data/lib/query/node/base_10.rb +22 -0
  22. data/lib/query/node/base_16.rb +17 -0
  23. data/lib/query/node/base_2.rb +17 -0
  24. data/lib/query/node/base_8.rb +17 -0
  25. data/lib/query/node/boolean.rb +46 -0
  26. data/lib/query/node/decimal.rb +25 -0
  27. data/lib/query/node/key.rb +17 -0
  28. data/lib/query/node/key_value.rb +23 -0
  29. data/lib/query/node/number.rb +27 -0
  30. data/lib/query/node/operator.rb +35 -0
  31. data/lib/query/node/part.rb +21 -0
  32. data/lib/query/node/query.rb +17 -0
  33. data/lib/query/node/range.rb +23 -0
  34. data/lib/query/node/string.rb +17 -0
  35. data/lib/query/node/text.rb +17 -0
  36. data/lib/query/node/value.rb +27 -0
  37. data/lib/query/node.rb +9 -0
  38. data/lib/query/parser/boolean.rb +24 -0
  39. data/lib/query/parser/key.rb +11 -0
  40. data/lib/query/parser/key_value.rb +13 -0
  41. data/lib/query/parser/number.rb +158 -0
  42. data/lib/query/parser/operator.rb +42 -0
  43. data/lib/query/parser/part.rb +11 -0
  44. data/lib/query/parser/query.rb +15 -0
  45. data/lib/query/parser/range.rb +32 -0
  46. data/lib/query/parser/string.rb +44 -0
  47. data/lib/query/parser/text.rb +40 -0
  48. data/lib/query/parser/value.rb +11 -0
  49. data/lib/query/parser/whitespace.rb +19 -0
  50. data/lib/query/parser.rb +21 -0
  51. data/lib/query/version.rb +6 -0
  52. data/lib/query-ruby.rb +14 -0
  53. data/lib/query.rb +29 -0
  54. data/package-lock.json +14 -0
  55. data/package.json +7 -0
  56. data/query-ruby.gemspec +26 -0
  57. data/spec/query_spec.rb +73 -0
  58. data/spec/spec_helper.rb +1 -0
  59. metadata +182 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0ac8665b3965512fc0ec7deb35364d8dcfeeaa4d7314bd79b98a8e03429063f0
4
+ data.tar.gz: de6848d68312bc5c612953e12968b775a8a3b7971051b1cd80ec274765539a5c
5
+ SHA512:
6
+ metadata.gz: c5db80249c3f4b02d054453acea39ae197b35768d84dba7698b0c3a9dcfd6aafc77cc7e483893309b74e55c346c4af7fb507c67cf7902f41478f275429d07d57
7
+ data.tar.gz: e6d66eed9e04b42164f7a0542c1450996b511c8bcb9bf0a05e46ab5336202056f81370710a8552d8073ee79e5aaaaf02ce168d727da581f085b4613e8d812963
@@ -0,0 +1,15 @@
1
+ ---
2
+ updates:
3
+ - directory: "/"
4
+ package-ecosystem: github-actions
5
+ schedule:
6
+ interval: daily
7
+ - directory: "/"
8
+ package-ecosystem: npm
9
+ schedule:
10
+ interval: daily
11
+ - directory: "/"
12
+ package-ecosystem: bundler
13
+ schedule:
14
+ interval: daily
15
+ version: 2
@@ -0,0 +1,38 @@
1
+ ---
2
+ jobs:
3
+ bundler-audit:
4
+ name: Bundler Audit
5
+ runs-on: ubuntu-latest
6
+ steps:
7
+ - uses: actions/checkout@v4
8
+ - uses: ruby/setup-ruby@v1
9
+ with:
10
+ bundler-cache: true
11
+ - run: bin/bundler-audit check --update
12
+ npm-audit:
13
+ name: npm Audit
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - uses: actions/setup-node@v4
18
+ - run: npm audit
19
+ rspec:
20
+ name: Test
21
+ runs-on: ubuntu-latest
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+ - uses: ruby/setup-ruby@v1
25
+ with:
26
+ bundler-cache: true
27
+ - run: bin/test
28
+ rubocop:
29
+ name: Rubocop
30
+ runs-on: ubuntu-latest
31
+ steps:
32
+ - uses: actions/checkout@v4
33
+ - uses: ruby/setup-ruby@v1
34
+ with:
35
+ bundler-cache: true
36
+ - run: bin/rubocop
37
+ name: CI
38
+ 'on': push
data/.gitignore ADDED
@@ -0,0 +1,30 @@
1
+ .DS_Store
2
+ *.gem
3
+ /.bundle
4
+ /.env
5
+ /.env.*.local
6
+ /.env.prod
7
+ /.env.staging
8
+ /.expo
9
+ /app/assets/builds
10
+ /config/*.key
11
+ /config/credentials/*.key
12
+ /log
13
+ /node_modules
14
+ /public/assets
15
+ /spec/examples.txt
16
+ /storage
17
+ /tmp
18
+ /tmp/pids
19
+ /tmp/storage
20
+ /vendor/bundle
21
+ !/.env*.erb
22
+ !/app/assets/builds/.keep
23
+ !/db/.keep
24
+ !/log/.keep
25
+ !/storage/.keep
26
+ !/tmp/.keep
27
+ !/tmp/pids/
28
+ !/tmp/pids/.keep
29
+ !/tmp/storage/
30
+ !/tmp/storage/.keep
data/.node-version ADDED
@@ -0,0 +1 @@
1
+ 23.11.0
data/.npm-version ADDED
@@ -0,0 +1 @@
1
+ 11.2.0
data/.prettierignore ADDED
@@ -0,0 +1,2 @@
1
+ node_modules
2
+ vendor
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,130 @@
1
+ ---
2
+ AllCops:
3
+ Exclude:
4
+ - "**/node_modules/**/*"
5
+ - "**/vendor/**/*"
6
+ - "**/db/schema.rb"
7
+ NewCops: enable
8
+ TargetRubyVersion: 3.0
9
+ Layout/ClosingHeredocIndentation:
10
+ Enabled: false
11
+ Layout/FirstArgumentIndentation:
12
+ Enabled: false
13
+ Layout/HashAlignment:
14
+ Enabled: false
15
+ Layout/HeredocIndentation:
16
+ Enabled: false
17
+ Layout/LineEndStringConcatenationIndentation:
18
+ Enabled: false
19
+ Layout/LineLength:
20
+ Enabled: false
21
+ Layout/MultilineMethodCallIndentation:
22
+ Enabled: false
23
+ Layout/MultilineOperationIndentation:
24
+ Enabled: false
25
+ Layout/SpaceInsideHashLiteralBraces:
26
+ Enabled: false
27
+ Lint/EmptyClass:
28
+ Enabled: false
29
+ Lint/MissingSuper:
30
+ Enabled: false
31
+ Lint/PercentStringArray:
32
+ Enabled: false
33
+ Lint/ShadowingOuterLocalVariable:
34
+ Enabled: false
35
+ Lint/SuppressedException:
36
+ Enabled: false
37
+ Lint/UnusedBlockArgument:
38
+ Enabled: false
39
+ Lint/UselessAssignment:
40
+ Enabled: false
41
+ Metrics/AbcSize:
42
+ Enabled: false
43
+ Metrics/BlockLength:
44
+ Enabled: false
45
+ Metrics/ClassLength:
46
+ Enabled: false
47
+ Metrics/CyclomaticComplexity:
48
+ Enabled: false
49
+ Metrics/MethodLength:
50
+ Enabled: false
51
+ Metrics/ModuleLength:
52
+ Enabled: false
53
+ Metrics/ParameterLists:
54
+ Enabled: false
55
+ Metrics/PerceivedComplexity:
56
+ Enabled: false
57
+ Naming/FileName:
58
+ Enabled: false
59
+ Naming/MethodParameterName:
60
+ Enabled: false
61
+ Naming/VariableNumber:
62
+ Enabled: false
63
+ Performance/Sum:
64
+ Enabled: false
65
+ Performance/UnfreezeString:
66
+ Enabled: false
67
+ RSpec/AnyInstance:
68
+ Enabled: false
69
+ RSpec/ContextWording:
70
+ Enabled: false
71
+ RSpec/DescribeClass:
72
+ Enabled: false
73
+ RSpec/ExampleLength:
74
+ Enabled: false
75
+ RSpec/ExampleWording:
76
+ Enabled: false
77
+ RSpec/MultipleExpectations:
78
+ Enabled: false
79
+ RSpec/NoExpectationExample:
80
+ Enabled: false
81
+ RSpec/PendingWithoutReason:
82
+ Enabled: false
83
+ Rails/Delegate:
84
+ Enabled: false
85
+ Rails/DynamicFindBy:
86
+ Enabled: false
87
+ Rails/HelperInstanceVariable:
88
+ Enabled: false
89
+ Rails/NegateInclude:
90
+ Enabled: false
91
+ Rails/Output:
92
+ Enabled: false
93
+ Rails/Presence:
94
+ Enabled: false
95
+ Rails/Present:
96
+ Enabled: false
97
+ Rails/ThreeStateBooleanColumn:
98
+ Enabled: false
99
+ Rails/TimeZone:
100
+ Enabled: false
101
+ Security/Eval:
102
+ Enabled: false
103
+ Style/CaseEquality:
104
+ Enabled: false
105
+ Style/Documentation:
106
+ Enabled: false
107
+ Style/DoubleNegation:
108
+ Enabled: false
109
+ Style/EmptyMethod:
110
+ Enabled: false
111
+ Style/IfUnlessModifier:
112
+ Enabled: false
113
+ Style/MultilineBlockChain:
114
+ Enabled: false
115
+ Style/NestedTernaryOperator:
116
+ Enabled: false
117
+ Style/QuotedSymbols:
118
+ Enabled: false
119
+ Style/StringLiterals:
120
+ Enabled: false
121
+ Style/StringLiteralsInInterpolation:
122
+ Enabled: false
123
+ plugins:
124
+ - rubocop-factory_bot
125
+ - rubocop-performance
126
+ - rubocop-rails
127
+ - rubocop-rake
128
+ - rubocop-rspec
129
+ - rubocop-capybara
130
+ - rubocop-rspec_rails
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.4.2
data/.tool-versions ADDED
@@ -0,0 +1,3 @@
1
+ ruby 3.4.2
2
+ yarn 1.22.22
3
+ nodejs 23.11.0
data/Gemfile ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ ruby "3.4.2"
8
+
9
+ gem "bundler-audit"
10
+ gem "dorian"
11
+ gem "rake"
12
+ gem "rspec"
13
+ gem "rubocop-capybara"
14
+ gem "rubocop-factory_bot"
15
+ gem "rubocop-performance"
16
+ gem "rubocop-rails"
17
+ gem "rubocop-rake"
18
+ gem "rubocop-rspec"
19
+ gem "rubocop-rspec_rails"
20
+ gem "ruby-prof"
21
+ gem "sinatra"
22
+ gem "webmock"
data/Gemfile.lock ADDED
@@ -0,0 +1,249 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ query-ruby (0.1.0)
5
+ activesupport
6
+ bigdecimal
7
+ dorian-arguments
8
+ json
9
+ language-ruby
10
+ zeitwerk
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ activesupport (8.0.2)
16
+ base64
17
+ benchmark (>= 0.3)
18
+ bigdecimal
19
+ concurrent-ruby (~> 1.0, >= 1.3.1)
20
+ connection_pool (>= 2.2.5)
21
+ drb
22
+ i18n (>= 1.6, < 2)
23
+ logger (>= 1.4.2)
24
+ minitest (>= 5.1)
25
+ securerandom (>= 0.3)
26
+ tzinfo (~> 2.0, >= 2.0.5)
27
+ uri (>= 0.13.1)
28
+ addressable (2.8.7)
29
+ public_suffix (>= 2.0.2, < 7.0)
30
+ ast (2.4.3)
31
+ base64 (0.2.0)
32
+ benchmark (0.4.0)
33
+ bigdecimal (3.1.9)
34
+ bundler-audit (0.9.2)
35
+ bundler (>= 1.2.0, < 3)
36
+ thor (~> 1.0)
37
+ cmdparse (3.0.7)
38
+ concurrent-ruby (1.3.5)
39
+ connection_pool (2.5.1)
40
+ crack (1.0.0)
41
+ bigdecimal
42
+ rexml
43
+ csv (3.3.4)
44
+ diff-lcs (1.6.1)
45
+ dorian (2.6.4)
46
+ csv
47
+ dorian-arguments
48
+ dorian-eval
49
+ dorian-progress
50
+ dorian-to_struct
51
+ git
52
+ hexapdf
53
+ json
54
+ mini_racer
55
+ ostruct
56
+ parallel
57
+ syntax_tree
58
+ syntax_tree-haml
59
+ syntax_tree-xml
60
+ terminal-table
61
+ w_syntax_tree-erb
62
+ yaml
63
+ dorian-arguments (1.2.2)
64
+ bigdecimal
65
+ dorian-eval (1.5.0)
66
+ yaml
67
+ dorian-progress (1.1.2)
68
+ ruby-progressbar
69
+ dorian-to_struct (2.0.2)
70
+ drb (2.2.1)
71
+ geom2d (0.4.1)
72
+ git (3.0.0)
73
+ activesupport (>= 5.0)
74
+ addressable (~> 2.8)
75
+ process_executer (~> 1.3)
76
+ rchardet (~> 1.9)
77
+ haml (6.3.0)
78
+ temple (>= 0.8.2)
79
+ thor
80
+ tilt
81
+ hashdiff (1.1.2)
82
+ hexapdf (1.2.0)
83
+ cmdparse (~> 3.0, >= 3.0.3)
84
+ geom2d (~> 0.4, >= 0.4.1)
85
+ openssl (>= 2.2.1)
86
+ strscan (>= 3.1.2)
87
+ i18n (1.14.7)
88
+ concurrent-ruby (~> 1.0)
89
+ json (2.10.2)
90
+ language-ruby (1.2.0)
91
+ dorian-arguments
92
+ zeitwerk
93
+ language_server-protocol (3.17.0.4)
94
+ libv8-node (23.6.1.0)
95
+ libv8-node (23.6.1.0-arm64-darwin)
96
+ libv8-node (23.6.1.0-x86_64-linux)
97
+ lint_roller (1.1.0)
98
+ logger (1.7.0)
99
+ mini_racer (0.18.1)
100
+ libv8-node (~> 23.6.1.0)
101
+ minitest (5.25.5)
102
+ mustermann (3.0.3)
103
+ ruby2_keywords (~> 0.0.1)
104
+ openssl (3.3.0)
105
+ ostruct (0.6.1)
106
+ parallel (1.27.0)
107
+ parser (3.3.8.0)
108
+ ast (~> 2.4.1)
109
+ racc
110
+ prettier_print (1.2.1)
111
+ prism (1.4.0)
112
+ process_executer (1.3.0)
113
+ public_suffix (6.0.1)
114
+ racc (1.8.1)
115
+ rack (3.1.13)
116
+ rack-protection (4.1.1)
117
+ base64 (>= 0.1.0)
118
+ logger (>= 1.6.0)
119
+ rack (>= 3.0.0, < 4)
120
+ rack-session (2.1.0)
121
+ base64 (>= 0.1.0)
122
+ rack (>= 3.0.0)
123
+ rainbow (3.1.1)
124
+ rake (13.2.1)
125
+ rchardet (1.9.0)
126
+ regexp_parser (2.10.0)
127
+ rexml (3.4.1)
128
+ rspec (3.13.0)
129
+ rspec-core (~> 3.13.0)
130
+ rspec-expectations (~> 3.13.0)
131
+ rspec-mocks (~> 3.13.0)
132
+ rspec-core (3.13.3)
133
+ rspec-support (~> 3.13.0)
134
+ rspec-expectations (3.13.3)
135
+ diff-lcs (>= 1.2.0, < 2.0)
136
+ rspec-support (~> 3.13.0)
137
+ rspec-mocks (3.13.2)
138
+ diff-lcs (>= 1.2.0, < 2.0)
139
+ rspec-support (~> 3.13.0)
140
+ rspec-support (3.13.2)
141
+ rubocop (1.75.2)
142
+ json (~> 2.3)
143
+ language_server-protocol (~> 3.17.0.2)
144
+ lint_roller (~> 1.1.0)
145
+ parallel (~> 1.10)
146
+ parser (>= 3.3.0.2)
147
+ rainbow (>= 2.2.2, < 4.0)
148
+ regexp_parser (>= 2.9.3, < 3.0)
149
+ rubocop-ast (>= 1.44.0, < 2.0)
150
+ ruby-progressbar (~> 1.7)
151
+ unicode-display_width (>= 2.4.0, < 4.0)
152
+ rubocop-ast (1.44.1)
153
+ parser (>= 3.3.7.2)
154
+ prism (~> 1.4)
155
+ rubocop-capybara (2.22.1)
156
+ lint_roller (~> 1.1)
157
+ rubocop (~> 1.72, >= 1.72.1)
158
+ rubocop-factory_bot (2.27.1)
159
+ lint_roller (~> 1.1)
160
+ rubocop (~> 1.72, >= 1.72.1)
161
+ rubocop-performance (1.25.0)
162
+ lint_roller (~> 1.1)
163
+ rubocop (>= 1.75.0, < 2.0)
164
+ rubocop-ast (>= 1.38.0, < 2.0)
165
+ rubocop-rails (2.31.0)
166
+ activesupport (>= 4.2.0)
167
+ lint_roller (~> 1.1)
168
+ rack (>= 1.1)
169
+ rubocop (>= 1.75.0, < 2.0)
170
+ rubocop-ast (>= 1.38.0, < 2.0)
171
+ rubocop-rake (0.7.1)
172
+ lint_roller (~> 1.1)
173
+ rubocop (>= 1.72.1)
174
+ rubocop-rspec (3.6.0)
175
+ lint_roller (~> 1.1)
176
+ rubocop (~> 1.72, >= 1.72.1)
177
+ rubocop-rspec_rails (2.31.0)
178
+ lint_roller (~> 1.1)
179
+ rubocop (~> 1.72, >= 1.72.1)
180
+ rubocop-rspec (~> 3.5)
181
+ ruby-prof (1.7.1)
182
+ ruby-progressbar (1.13.0)
183
+ ruby2_keywords (0.0.5)
184
+ securerandom (0.4.1)
185
+ sinatra (4.1.1)
186
+ logger (>= 1.6.0)
187
+ mustermann (~> 3.0)
188
+ rack (>= 3.0.0, < 4)
189
+ rack-protection (= 4.1.1)
190
+ rack-session (>= 2.0.0, < 3)
191
+ tilt (~> 2.0)
192
+ strscan (3.1.3)
193
+ syntax_tree (6.2.0)
194
+ prettier_print (>= 1.2.0)
195
+ syntax_tree-haml (4.0.3)
196
+ haml (>= 5.2)
197
+ prettier_print (>= 1.2.1)
198
+ syntax_tree (>= 6.0.0)
199
+ syntax_tree-xml (0.1.0)
200
+ prettier_print
201
+ syntax_tree (>= 2.0.1)
202
+ temple (0.10.3)
203
+ terminal-table (4.0.0)
204
+ unicode-display_width (>= 1.1.1, < 4)
205
+ thor (1.3.2)
206
+ tilt (2.6.0)
207
+ tzinfo (2.0.6)
208
+ concurrent-ruby (~> 1.0)
209
+ unicode-display_width (3.1.4)
210
+ unicode-emoji (~> 4.0, >= 4.0.4)
211
+ unicode-emoji (4.0.4)
212
+ uri (1.0.3)
213
+ w_syntax_tree-erb (0.12.0)
214
+ prettier_print (~> 1.2, >= 1.2.0)
215
+ syntax_tree (~> 6.1, >= 6.1.1)
216
+ webmock (3.25.1)
217
+ addressable (>= 2.8.0)
218
+ crack (>= 0.3.2)
219
+ hashdiff (>= 0.4.0, < 2.0.0)
220
+ yaml (0.4.0)
221
+ zeitwerk (2.7.2)
222
+
223
+ PLATFORMS
224
+ arm64-darwin-23
225
+ ruby
226
+ x86_64-linux
227
+
228
+ DEPENDENCIES
229
+ bundler-audit
230
+ dorian
231
+ query-ruby!
232
+ rake
233
+ rspec
234
+ rubocop-capybara
235
+ rubocop-factory_bot
236
+ rubocop-performance
237
+ rubocop-rails
238
+ rubocop-rake
239
+ rubocop-rspec
240
+ rubocop-rspec_rails
241
+ ruby-prof
242
+ sinatra
243
+ webmock
244
+
245
+ RUBY VERSION
246
+ ruby 3.4.2p28
247
+
248
+ BUNDLED WITH
249
+ 2.6.7
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright 2024 Dorian Marié <dorian@dorianmarie.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the “Software”), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to
8
+ do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # code-ruby
2
+
3
+ A programming language
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:default) { |task| task.verbose = false }
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/query ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../lib/query-ruby"
5
+ require "dorian/arguments"
6
+
7
+ parsed =
8
+ Dorian::Arguments.parse(
9
+ input: {
10
+ type: :string,
11
+ alias: :i
12
+ },
13
+ parse: {
14
+ type: :boolean,
15
+ alias: :p
16
+ },
17
+ decompile: {
18
+ type: :boolean,
19
+ alias: :d
20
+ },
21
+ combine: {
22
+ type: :boolean,
23
+ alias: :c
24
+ },
25
+ version: {
26
+ type: :boolean,
27
+ alias: :v
28
+ },
29
+ help: {
30
+ type: :boolean,
31
+ alias: :h
32
+ }
33
+ )
34
+
35
+ abort Query::Version.to_s if parsed.options.version
36
+ abort parsed.help if parsed.options.help
37
+
38
+ inputs = [parsed.options.input.to_s]
39
+ inputs += parsed.arguments
40
+ inputs += parsed.files.map { |file| File.read(file) }
41
+
42
+ input = inputs.join(" ")
43
+
44
+ if parsed.options.parse
45
+ pp Query::Parser.parse(input).to_raw
46
+ elsif parsed.options.decompile
47
+ puts Query.decompile(Query.evaluate(input))
48
+ elsif parsed.options.combine
49
+ puts Query.combine(*inputs)
50
+ else
51
+ pp Query.evaluate(input)
52
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Query
4
+ class Combiner
5
+ def initialize(*sources)
6
+ self.sources = sources
7
+ end
8
+
9
+ def self.combine(...)
10
+ new(...).combine
11
+ end
12
+
13
+ def combine
14
+ sources.map do |source|
15
+ Query.evaluate(source)
16
+ end.reduce do |acc, element|
17
+ combine_parsed(acc, element)
18
+ end.then do |parsed|
19
+ Query.decompile(parsed)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ attr_accessor :sources
26
+
27
+ def combine_parsed(left, right)
28
+ (left + right).reverse.uniq do |node|
29
+ node.is_a?(Hash) ? [node[:key], node[:operator]] : node
30
+ end.reverse
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Query
4
+ class Decompiler
5
+ def initialize(parsed)
6
+ @parsed = parsed
7
+ end
8
+
9
+ def self.decompile(...)
10
+ new(...).decompile
11
+ end
12
+
13
+ def decompile
14
+ parsed.map { |node| format_value(node) }.join(" ")
15
+ end
16
+
17
+ def format_string(string)
18
+ end
19
+
20
+ def format_value(value)
21
+ if value.is_a?(Hash)
22
+ "#{value[:key]}#{value[:operator]}#{format_value(value[:value])}"
23
+ elsif value.is_a?(String)
24
+ Query.evaluate(value).many? ? value.inspect : value
25
+ elsif value.is_a?(BigDecimal)
26
+ value.to_s("F")
27
+ elsif value.is_a?(Range)
28
+ left = value.first
29
+ right = value.last
30
+ operator = value.exclude_end? ? "..." : ".."
31
+ "#{format_value(left)}#{operator}#{format_value(right)}"
32
+ else
33
+ value.to_s
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ attr_reader :parsed
40
+ end
41
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Query
4
+ class Node
5
+ class Base10 < Node
6
+ attr_accessor :whole, :exponent
7
+
8
+ def initialize(parsed)
9
+ self.whole = parsed.delete(:whole)
10
+ self.exponent = Node::Value.new(parsed.delete(:exponent)) if parsed.key?(:exponent)
11
+ end
12
+
13
+ def evaluate(**args)
14
+ if exponent
15
+ whole.to_i * 10 ** exponent.evaluate(**args)
16
+ else
17
+ whole.to_i
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end