ddql 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 82f78b8b46dd03069598a3945141114c781eef9da44a0f409d8a8ab3c6bae4b0
4
+ data.tar.gz: ec23e584baad9e0359c9471cf3002371863f888cf5cf718ef7cdeb6eb8291686
5
+ SHA512:
6
+ metadata.gz: 14f90543034d8fdd8813aad9db740efb95f11b9feb9ba17b0f23fd64b603cc7b804cde2fee516c95d11d593b0d57f219edee1d736246d5670e41afbd15c5ae1d
7
+ data.tar.gz: 62e76c1c990a1168a4510b56636a6ca9105d1720794e4535a07bd53c5742cd5f5710fcd21ace66ff3e39623d800a07bcf8ee6ac71a87a38650ecf9ce4ac57441
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1 @@
1
+ ddql
@@ -0,0 +1 @@
1
+ ruby-2.6.3
@@ -0,0 +1,10 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5
7
+ - 2.6
8
+ - 2.7
9
+ - jruby
10
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ddql.gemspec
4
+ gemspec
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ddql (0.1.0)
5
+ parslet (~> 2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ byebug (11.1.3)
11
+ coderay (1.1.3)
12
+ diff-lcs (1.3)
13
+ method_source (1.0.0)
14
+ parslet (2.0.0)
15
+ pry (0.13.1)
16
+ coderay (~> 1.1)
17
+ method_source (~> 1.0)
18
+ pry-byebug (3.9.0)
19
+ byebug (~> 11.0)
20
+ pry (~> 0.13.0)
21
+ rake (13.0.1)
22
+ rspec (3.8.0)
23
+ rspec-core (~> 3.8.0)
24
+ rspec-expectations (~> 3.8.0)
25
+ rspec-mocks (~> 3.8.0)
26
+ rspec-core (3.8.0)
27
+ rspec-support (~> 3.8.0)
28
+ rspec-expectations (3.8.3)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.8.0)
31
+ rspec-mocks (3.8.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.8.0)
34
+ rspec-support (3.8.0)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ bundler (~> 2.0)
41
+ ddql!
42
+ pry-byebug (~> 3.9)
43
+ rake (~> 13.0)
44
+ rspec (~> 3.0)
45
+
46
+ BUNDLED WITH
47
+ 2.1.4
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Technology Innovation Lab
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Jason Rogers
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.
@@ -0,0 +1,42 @@
1
+ # DDQL
2
+
3
+ A (Ruby) DataDesk query language parser written in Parslet.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ddql'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ddql
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then,
28
+ run `rake spec` to run the tests. You can also run `bin/console` for an
29
+ interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`.
32
+ To release a new version, update the version number in `version.rb`, and then
33
+ run `bundle exec rake release`, which will create a git tag for the version,
34
+ push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/iss-lab/ddql).
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'ddql'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require 'pry'
11
+ PARSER = DDQL::Parser.new
12
+ puts 'Create a new instance of the parser or use the PARSER constant'
13
+ Pry.start
14
+
15
+ # require "irb"
16
+ # IRB.start(__FILE__)
@@ -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
@@ -0,0 +1,36 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "ddql/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ddql"
7
+ spec.version = DDQL::VERSION
8
+ spec.authors = ["Jason Rogers"]
9
+ spec.email = ["jacaetevha@gmail.com"]
10
+
11
+ spec.summary = %q{DataDesk Query Language parser for Ruby}
12
+ spec.homepage = "https://github.com/iss-lab/DDQL"
13
+ spec.license = "MIT"
14
+
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/iss-lab/DDQL"
19
+ spec.metadata["changelog_uri"] = "https://github.com/iss-lab/DDQL/blob/master/CHANGELOG.md"
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('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "parslet", "~> 2.0"
31
+
32
+ spec.add_development_dependency "bundler", "~> 2.0"
33
+ spec.add_development_dependency "rake", "~> 13.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ spec.add_development_dependency "pry-byebug", "~> 3.9"
36
+ end
@@ -0,0 +1,7 @@
1
+ require 'parslet'
2
+ require 'ddql/parser'
3
+ require 'ddql/version'
4
+
5
+ module DDQL
6
+ class ParseError < StandardError; end
7
+ end
@@ -0,0 +1,282 @@
1
+ module DDQL
2
+ class Parser < Parslet::Parser
3
+ # comparison constants
4
+ rule(:eq) { (str('==') | str('=')) }
5
+ rule(:ge) { str('>=') }
6
+ rule(:gt) { str('>') }
7
+ rule(:is) { str('IS') }
8
+ rule(:isnt) { str('IS NOT') }
9
+ rule(:le) { str('<=') }
10
+ rule(:lt) { str('<') }
11
+ rule(:ne) { str('!=') }
12
+ rule(:no) { str('NO') }
13
+ rule(:null) { str('NULL') }
14
+ rule(:yes) { str('YES') }
15
+
16
+ # constants
17
+ rule(:comma) { str(',') }
18
+ rule(:digit) { match('[0-9]') }
19
+ rule(:group_by) { str('GROUP BY') }
20
+ rule(:spaces) { match('\s').repeat(1) }
21
+ rule(:spaces?) { spaces.maybe }
22
+ rule(:tick) { str("'") }
23
+ rule(:string) { (tick >> (tick.absent? >> any).repeat.as(:string) >> tick) }
24
+
25
+ # brackets
26
+ rule(:lbracket) { str('[') }
27
+ rule(:lparen) { spaces? >> str('(') >> spaces? }
28
+ rule(:lsquiggly) { spaces? >> str('{') >> spaces? }
29
+ rule(:rbracket) { str(']') }
30
+ rule(:rparen) { spaces? >> str(')') >> spaces? }
31
+ rule(:rsquiggly) { spaces? >> str('}') >> spaces? }
32
+
33
+ # math ops
34
+ rule(:math_add) { str('+').as(:op_add) }
35
+ rule(:math_subtract) { str('-').as(:op_subtract) }
36
+ rule(:math_multiply) { str('*').as(:op_multiply) }
37
+ rule(:math_divide) { str('/').as(:op_divide) }
38
+ rule(:math_mod) { str('%').as(:op_mod) }
39
+ rule(:math_power) { str('^').as(:op_power) }
40
+ rule(:math_operation) do
41
+ math_add | math_subtract | math_multiply | math_divide | math_mod | math_power
42
+ end
43
+
44
+ # boolean operators
45
+ rule(:bool_not) { spaces? >> str('NOT').as(:op_not) >> spaces? }
46
+ rule(:or_operator) { spaces? >> str('OR').as(:op_or) >> spaces? }
47
+ rule(:and_operator) { spaces? >> str('AND').as(:op_and) >> spaces? }
48
+
49
+ # string operators
50
+ rule(:ctn_operator) { spaces? >> (str('CTN') | str('LCTN')).as(:op_ctn) >> spaces? }
51
+ rule(:stw_operator) { spaces? >> str('STW').as(:op_stw) >> spaces? }
52
+
53
+ # date operators
54
+ rule(:date_on_operator) { spaces? >> str('ON').as(:op_date_on) >> spaces? }
55
+ rule(:date_after_operator) { spaces? >> str('PST').as(:op_date_after) >> spaces? }
56
+ rule(:date_after_operator_or_on) { spaces? >> str('EPST').as(:op_date_after_or_on) >> spaces? }
57
+ rule(:date_before_operator) { spaces? >> str('PRE').as(:op_date_before) >> spaces? }
58
+ rule(:date_before_operator_or_on) { spaces? >> str('EPRE').as(:op_date_before_or_on) >> spaces? }
59
+
60
+ # currency support
61
+ rule(:currency_code) { match('[A-Z]').repeat(3) }
62
+ rule(:currency) do
63
+ tick.maybe >>
64
+ (
65
+ tick.absent? >>
66
+ currency_code.as(:currency_code) >>
67
+ str(':') >>
68
+ (float_numeric | int_numeric).as(:currency_value)
69
+ ) >>
70
+ tick.maybe
71
+ end
72
+
73
+ # numbers
74
+ rule(:float_numeric) do
75
+ (str('-').maybe >> (
76
+ str('0') | (match('[1-9]') >> digit.repeat)
77
+ ) >> (
78
+ str('.') >> digit.repeat(1)
79
+ ) >> (
80
+ match('[eE]') >> (str('+') | str('-')).maybe >> digit.repeat(1)
81
+ ).maybe
82
+ ).as(:float)
83
+ end
84
+ rule(:float) do
85
+ (tick.maybe >> (tick.absent? >> float_numeric >> tick)) | float_numeric
86
+ end
87
+ rule(:int_numeric) { (str('-').maybe >> digit.repeat(1)).as(:int) }
88
+ rule(:int) do
89
+ (tick.maybe >> (tick.absent? >> int_numeric >> tick)) | int_numeric
90
+ end
91
+
92
+ # special markers
93
+ rule(:current_date) { str('$CURRENT_DATE').as(:current_date) }
94
+ rule(:current_quarter) { str('$CURRENT_QUARTER').as(:current_quarter) }
95
+ rule(:current_year) { str('$CURRENT_YEAR').as(:current_year) }
96
+ rule(:relative_end_date) { str('$END_DATE').as(:relative_end_date) }
97
+ rule(:relative_end_quarter) { str('$END_QUARTER').as(:relative_end_quarter) }
98
+ rule(:relative_end_year) { str('$END_YEAR').as(:relative_end_year) }
99
+ rule(:relative_start_date) { str('$START_DATE').as(:relative_start_date) }
100
+ rule(:relative_start_quarter) { str('$START_QUARTER').as(:relative_start_quarter) }
101
+ rule(:relative_start_year) { str('$START_YEAR').as(:relative_start_year) }
102
+ rule(:special_marker) do
103
+ (
104
+ current_year | current_date | current_quarter |
105
+ relative_end_date | relative_end_quarter | relative_end_year |
106
+ relative_start_date | relative_start_quarter | relative_start_year
107
+ ).as(:special_marker)
108
+ end
109
+
110
+ # nulls
111
+ rule(:null_no_information) { str('NO_INFORMATION') }
112
+ rule(:null_not_applicable) { str('NOT_APPLICABLE') }
113
+ rule(:null_not_collected) { str('NOT_COLLECTED') }
114
+ rule(:null_not_disclosed) { str('NOT_DISCLOSED') }
115
+ rule(:null_not_meaningful) { str('NOT_MEANINGFUL') }
116
+ rule(:null_value_type) do
117
+ (
118
+ null_no_information |
119
+ null_not_applicable |
120
+ null_not_collected |
121
+ null_not_disclosed |
122
+ null_not_meaningful
123
+ ).as(:null_value_type)
124
+ end
125
+
126
+ # array operators
127
+ rule(:arrays_all_operator) { str('ALL').as(:op_all) }
128
+ rule(:arrays_any_operator) { str('ANY').as(:op_any) }
129
+ rule(:arrays_in_operator) { str('IN').as(:op_in) }
130
+ rule(:arrays_none_operator) { str('NONE').as(:op_none) }
131
+ rule(:arrays_operator) do
132
+ arrays_all_operator | arrays_any_operator | arrays_in_operator | arrays_none_operator
133
+ end
134
+
135
+ # comparison operators
136
+ rule(:boolean_operator) { or_operator | and_operator }
137
+ rule(:date_rel_operator) { date_on_operator | date_after_operator | date_after_operator_or_on | date_before_operator | date_before_operator_or_on }
138
+ rule(:eq_operator) { eq.as(:op_eq) }
139
+ rule(:ge_operator) { ge.as(:op_ge) }
140
+ rule(:gt_operator) { gt.as(:op_gt) }
141
+ rule(:is_not_null_operator) { (isnt >> spaces >> null).as(:op_is_not_null) }
142
+ rule(:is_null_operator) { (is >> spaces >> null).as(:op_is_null) }
143
+ rule(:is_operator) { is.as(:op_is) }
144
+ rule(:le_operator) { le.as(:op_le) }
145
+ rule(:lt_operator) { lt.as(:op_lt) }
146
+ rule(:ne_operator) { ne.as(:op_ne) }
147
+ rule(:no_operator) { no.as(:op_no) }
148
+ rule(:relational_operator) { eq_operator | le_operator | ge_operator | lt_operator | gt_operator | ne_operator }
149
+ rule(:string_rel_operator) { ctn_operator | stw_operator }
150
+ rule(:yes_operator) { yes.as(:op_yes) }
151
+
152
+ # aggregations
153
+ rule(:avg_operator) { str('AVG').as(:op_avg) }
154
+ rule(:cnt_operator) { str('CNT').as(:op_cnt) }
155
+ rule(:ext_operator) { str('EXISTS').as(:op_exist) }
156
+ rule(:max_operator) { str('MAX').as(:op_max) }
157
+ rule(:med_operator) { str('MED').as(:op_med) }
158
+ rule(:min_operator) { str('MIN').as(:op_min) }
159
+ rule(:sum_operator) { str('SUM').as(:op_sum) }
160
+ rule(:grouping_operator) { (max_operator | min_operator).as(:agg) }
161
+ rule(:agg_operator) do
162
+ (avg_operator | cnt_operator | ext_operator | med_operator | sum_operator).as(:agg)
163
+ end
164
+ rule(:aggregation_operator) do
165
+ # Examples:
166
+ # CNT {type: IssuerCase, fields: [], expression: ([CaseFlag] == 'Amber' AND [CaseFlag] == 'RED' AND [CaseFlag] == 'Green')} >= '0'
167
+ # CNT {type: IssuerPerson, expression: [ipAssociationType] == 'Director'}
168
+ (agg_operator >>
169
+ lsquiggly >>
170
+ (rsquiggly.absent? >> any).repeat(1).as(:sub_query_info) >>
171
+ rsquiggly >>
172
+ relational_operator.as(:op) >>
173
+ value.as(:right)
174
+ ) | (agg_operator >>
175
+ lsquiggly >>
176
+ (rsquiggly.absent? >> any).repeat(1).as(:sub_query_info) >>
177
+ rsquiggly
178
+ ) | (grouping_operator >>
179
+ lsquiggly >>
180
+ (rsquiggly.absent? >> any).repeat(1).as(:sub_query_info) >>
181
+ rsquiggly >>
182
+ spaces? >>
183
+ group_by >>
184
+ spaces? >>
185
+ factor.as(:group_by)
186
+ )
187
+ end
188
+
189
+ # sub-queries
190
+ rule(:sub_query_type) do
191
+ spaces? >> str('type:') >> spaces? >> (str('IssuerCase') | str('IssuerPerson') | str('Issuer')).as(:type) >> spaces?
192
+ end
193
+ rule(:sub_query_fields) do
194
+ spaces? >> str('fields:') >> spaces? >> (factor | (lbracket >> spaces?.as(:factor) >> rbracket)).as(:fields) >> spaces?
195
+ end
196
+ rule(:sub_query_qualifier) do
197
+ spaces? >> str('qualifier:') >> spaces? >> string.as(:assoc_qualifier)
198
+ end
199
+ rule(:sub_query_expression) do
200
+ spaces? >> str('expression:') >> spaces? >> top.as(:expression)
201
+ end
202
+ rule(:sub_query_info_parsing) do
203
+ (sub_query_type >> (comma >> sub_query_qualifier).maybe >> comma >> sub_query_expression >> comma >> sub_query_fields) |
204
+ (sub_query_type >> (comma >> sub_query_qualifier).maybe >> comma >> sub_query_expression >> comma.absent?) |
205
+ (sub_query_type >> (comma >> sub_query_qualifier).maybe >> comma >> (sub_query_fields >> comma).maybe >> sub_query_expression) |
206
+ (sub_query_fields >> comma >> sub_query_type >> (comma >> sub_query_qualifier).maybe >> comma >> sub_query_expression) |
207
+ (sub_query_fields >> comma >> sub_query_expression >> comma >> sub_query_type >> (comma >> sub_query_qualifier).maybe) |
208
+ (sub_query_expression >> comma >> sub_query_type >> (comma >> sub_query_qualifier).maybe >> (comma >> sub_query_fields).maybe) |
209
+ (sub_query_expression >> comma >> (sub_query_fields >> comma).maybe >> sub_query_type >> (comma >> sub_query_qualifier).maybe) |
210
+ (sub_query_type >> comma >> sub_query_fields) | # for MIN/MAX {...} GROUP BY [...]
211
+ (sub_query_fields >> comma >> sub_query_type) # for MIN/MAX {...} GROUP BY [...]
212
+ end
213
+
214
+ # higher-level definitions
215
+ rule(:operator) do
216
+ (relational_operator | arrays_operator).as(:op)
217
+ end
218
+
219
+ rule(:factor) do
220
+ lbracket >> (
221
+ match('[_0-9a-zA-Z&]').repeat(1).as(:factor)
222
+ ) >> rbracket
223
+ end
224
+
225
+ rule(:val) do
226
+ (currency | float | int | special_marker | string)
227
+ end
228
+
229
+ rule(:value) do
230
+ spaces? >> (val | factor) >> spaces?
231
+ end
232
+
233
+ rule(:math_operand) do
234
+ spaces? >> (special_marker | float | int | factor | aggregation_operator) >> spaces?
235
+ end
236
+
237
+ rule(:equation) do
238
+ (math_operand.as(:left) >> spaces? >> math_operation >> spaces? >> math_operand.as(:right)) |
239
+ (math_operand.as(:left) >> spaces? >> math_operation >> spaces? >> equation.as(:right)) #|
240
+ end
241
+
242
+ rule(:factor_comparison) do
243
+ (factor.as(:left) >> spaces >> is_not_null_operator.as(:op)) |
244
+ (factor.as(:left) >> spaces >> is_null_operator.as(:op)) |
245
+ (factor.as(:left) >> spaces >> is_operator.as(:op) >> spaces >> null_value_type.as(:right)) |
246
+ (value.as(:left) >> operator >> value.as(:right)) |
247
+ (factor.as(:left) >> (string_rel_operator | date_rel_operator).as(:op) >> string.as(:right)) |
248
+ (factor.as(:left) >> spaces? >> (no_operator | yes_operator).as(:yes_no_op))
249
+ end
250
+
251
+ rule(:entity) do
252
+ equation |
253
+ sub_query_info_parsing |
254
+ (
255
+ bool_not.maybe >> (
256
+ (lparen >> entity >> rparen) |
257
+ aggregation_operator |
258
+ (factor_comparison) |
259
+ factor.as(:value_of) |
260
+ special_marker |
261
+ top
262
+ )
263
+ )
264
+ end
265
+
266
+ rule(:statement) do
267
+ spaces? >> (
268
+ (lparen >> spaces? >> (top | entity | factor) >> spaces? >> rparen) |
269
+ entity
270
+ ) >> spaces?
271
+ end
272
+
273
+ rule(:top) do
274
+ (statement.as(:lstatement) >> (boolean_operator.as(:boolean_operator) >> top.as(:rstatement))) |
275
+ (statement.as(:lstatement) >> (math_operation.as(:math_operation) >> top.as(:rstatement))) |
276
+ (statement.as(:lstatement) >> (operator.as(:operator) >> top.as(:rstatement))) |
277
+ statement
278
+ end
279
+
280
+ root(:top)
281
+ end
282
+ end
@@ -0,0 +1,3 @@
1
+ module DDQL
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ddql
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Rogers
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: parslet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.9'
83
+ description:
84
+ email:
85
+ - jacaetevha@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".ruby-gemset"
93
+ - ".ruby-version"
94
+ - ".travis.yml"
95
+ - Gemfile
96
+ - Gemfile.lock
97
+ - LICENSE
98
+ - LICENSE.txt
99
+ - README.md
100
+ - Rakefile
101
+ - bin/console
102
+ - bin/setup
103
+ - ddql.gemspec
104
+ - lib/ddql.rb
105
+ - lib/ddql/parser.rb
106
+ - lib/ddql/version.rb
107
+ homepage: https://github.com/iss-lab/DDQL
108
+ licenses:
109
+ - MIT
110
+ metadata:
111
+ allowed_push_host: https://rubygems.org
112
+ homepage_uri: https://github.com/iss-lab/DDQL
113
+ source_code_uri: https://github.com/iss-lab/DDQL
114
+ changelog_uri: https://github.com/iss-lab/DDQL/blob/master/CHANGELOG.md
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubygems_version: 3.0.6
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: DataDesk Query Language parser for Ruby
134
+ test_files: []