gql 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -2
- data/Rakefile +18 -5
- data/bin/rake +16 -0
- data/gql.gemspec +1 -2
- data/lib/gql.rb +5 -13
- data/lib/gql/call.rb +1 -1
- data/lib/gql/errors.rb +5 -2
- data/lib/gql/node.rb +8 -7
- data/lib/gql/parser.rb +48 -96
- data/lib/gql/schema/call.rb +9 -1
- data/lib/gql/test_case.rb +4 -0
- data/lib/gql/tokenizer.rb +48 -9
- data/lib/gql/version.rb +1 -1
- metadata +4 -18
- data/lib/gql/parser.y +0 -231
- data/lib/gql/tokenizer.rex +0 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afade4dbb867e9e0a602148b69032b9993271a70
|
4
|
+
data.tar.gz: b2fbe5c310949e6f14c76bd736297e8a33c06874
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8db790c55fb17a480541fb5f10af5133e535452e17dd701d569a47475075f125848ecd62c08194db2f3007aa74281349c26acd0c70e091fbb49ad8aca9291b8b
|
7
|
+
data.tar.gz: 4ac70838a5ac05d0f46362ddd98ee0834e2c5bab6ca49c98e6ddfe91400191f4730e7281553a025d43c05a5abaaf2fcfb0df365cfb29d45e32f0bb2cb280c30a
|
data/README.md
CHANGED
@@ -148,8 +148,6 @@ This should result in the following JSON (after prettyfication):
|
|
148
148
|
|
149
149
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
150
150
|
|
151
|
-
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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
152
|
-
|
153
151
|
|
154
152
|
## Contributing
|
155
153
|
|
data/Rakefile
CHANGED
@@ -1,22 +1,35 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
|
1
3
|
require 'bundler/gem_tasks'
|
2
4
|
require 'rake/testtask'
|
3
5
|
|
4
|
-
file 'lib/gql/tokenizer.rb' => '
|
6
|
+
file 'lib/gql/tokenizer.rb' => 'support/tokenizer.rex' do |t|
|
5
7
|
sh "bundle exec rex #{t.prerequisites.first} --output-file #{t.name}"
|
8
|
+
|
9
|
+
# use custom scan error class
|
10
|
+
sh "sed --in-place 's/class ScanError/class Unused/' #{t.name}"
|
11
|
+
sh "sed --in-place 's/ScanError/GQL::Errors::ScanError/' #{t.name}"
|
6
12
|
end
|
7
13
|
|
8
|
-
file 'lib/gql/parser.rb' => '
|
14
|
+
file 'lib/gql/parser.rb' => 'support/parser.racc' do |t|
|
9
15
|
if ENV['DEBUG']
|
10
16
|
sh "bundle exec racc --debug --verbose --output-file=#{t.name} #{t.prerequisites.first}"
|
11
17
|
else
|
12
18
|
sh "bundle exec racc --output-file=#{t.name} #{t.prerequisites.first}"
|
13
19
|
end
|
14
|
-
end
|
15
20
|
|
16
|
-
|
21
|
+
# fix indentation of generated parser code to silence test warning
|
22
|
+
sh "sed --in-place 's/ end\s*# module/end #/g' #{t.name}"
|
23
|
+
end
|
17
24
|
|
18
|
-
Rake::TestTask.new :test
|
25
|
+
Rake::TestTask.new :test do |t|
|
19
26
|
t.libs << 'test'
|
27
|
+
t.test_files = Dir.glob("#{dir}/test/cases/**/*_test.rb")
|
28
|
+
# t.warning = true
|
29
|
+
# t.verbose = true
|
20
30
|
end
|
21
31
|
|
32
|
+
task :compile => ['lib/gql/tokenizer.rb', 'lib/gql/parser.rb']
|
33
|
+
task :test => :compile
|
34
|
+
task :release => :test
|
22
35
|
task :default => :test
|
data/bin/rake
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rake' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('rake', 'rake')
|
data/gql.gemspec
CHANGED
@@ -16,13 +16,12 @@ Gem::Specification.new do |spec|
|
|
16
16
|
|
17
17
|
spec.required_ruby_version = '>= 2.2.0'
|
18
18
|
|
19
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|support)/}) }
|
20
20
|
spec.bindir = 'exe'
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
|
23
23
|
spec.add_development_dependency 'bundler', '~> 1.8'
|
24
24
|
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
-
spec.add_development_dependency 'minitest'
|
26
25
|
spec.add_development_dependency 'rexical', '~> 1.0'
|
27
26
|
spec.add_development_dependency 'racc', '~> 1.4'
|
28
27
|
|
data/lib/gql.rb
CHANGED
@@ -14,11 +14,12 @@ module GQL
|
|
14
14
|
autoload :Parser, 'gql/parser'
|
15
15
|
autoload :Simple, 'gql/simple'
|
16
16
|
autoload :String, 'gql/string'
|
17
|
-
autoload :
|
17
|
+
autoload :TestCase, 'gql/test_case'
|
18
18
|
autoload :VERSION, 'gql/version'
|
19
19
|
|
20
20
|
module Errors
|
21
21
|
autoload :InvalidNodeClass, 'gql/errors'
|
22
|
+
autoload :ScanError, 'gql/errors'
|
22
23
|
autoload :SyntaxError, 'gql/errors'
|
23
24
|
autoload :UndefinedCall, 'gql/errors'
|
24
25
|
autoload :UndefinedField, 'gql/errors'
|
@@ -61,23 +62,14 @@ module GQL
|
|
61
62
|
end
|
62
63
|
|
63
64
|
def parse(input)
|
64
|
-
|
65
|
-
|
66
|
-
tokenizer = Tokenizer.new
|
67
|
-
tokenizer.scan_setup input
|
68
|
-
|
69
|
-
parser = Parser.new(tokenizer)
|
70
|
-
parser.parse
|
65
|
+
Parser.new(input).parse
|
71
66
|
end
|
72
67
|
|
73
68
|
def tokenize(input)
|
74
|
-
|
75
|
-
|
76
|
-
tokenizer = Tokenizer.new
|
77
|
-
tokenizer.scan_setup input
|
69
|
+
parser = Parser.new(input)
|
78
70
|
|
79
71
|
[].tap do |result|
|
80
|
-
while token =
|
72
|
+
while token = parser.next_token
|
81
73
|
result << token
|
82
74
|
yield token if block_given?
|
83
75
|
end
|
data/lib/gql/call.rb
CHANGED
@@ -2,7 +2,7 @@ require 'active_support/core_ext/class/attribute'
|
|
2
2
|
|
3
3
|
module GQL
|
4
4
|
class Call
|
5
|
-
class_attribute :result_class, :proc, instance_accessor: false, instance_predicate: false
|
5
|
+
class_attribute :id, :result_class, :proc, instance_accessor: false, instance_predicate: false
|
6
6
|
|
7
7
|
class << self
|
8
8
|
def returns(result_class)
|
data/lib/gql/errors.rb
CHANGED
@@ -52,11 +52,14 @@ module GQL
|
|
52
52
|
end
|
53
53
|
|
54
54
|
class SyntaxError < Error
|
55
|
-
def initialize(value, token)
|
55
|
+
def initialize(lineno, value, token)
|
56
56
|
token = 'character' if token == 'error' || token == %Q{"#{value}"}
|
57
57
|
|
58
|
-
super("Unexpected #{token}: `#{value}
|
58
|
+
super("Unexpected #{token}: `#{value}` (line #{lineno}).")
|
59
59
|
end
|
60
60
|
end
|
61
|
+
|
62
|
+
class ScanError < Error
|
63
|
+
end
|
61
64
|
end
|
62
65
|
end
|
data/lib/gql/node.rb
CHANGED
@@ -25,13 +25,13 @@ module GQL
|
|
25
25
|
class << self
|
26
26
|
def call(id, *args)
|
27
27
|
if id.is_a? Hash
|
28
|
-
id.each do |
|
29
|
-
call
|
28
|
+
id.each do |name, call_class|
|
29
|
+
call name, call_class
|
30
30
|
end
|
31
31
|
else
|
32
32
|
options = args.extract_options!
|
33
33
|
|
34
|
-
proc_or_class = args.shift || -> (*
|
34
|
+
proc_or_class = args.shift || -> (*pargs) { target.public_send(id, *pargs) }
|
35
35
|
result_class = options[:returns] || proc_or_class.try(:result_class)
|
36
36
|
|
37
37
|
if result_class.is_a? ::Array
|
@@ -51,8 +51,8 @@ module GQL
|
|
51
51
|
|
52
52
|
call_class =
|
53
53
|
if proc_or_class.is_a? Proc
|
54
|
-
Class.new(Call).tap do |
|
55
|
-
|
54
|
+
Class.new(Call).tap do |klass|
|
55
|
+
klass.class_eval do
|
56
56
|
self.proc = proc_or_class
|
57
57
|
|
58
58
|
def execute(*args)
|
@@ -60,12 +60,13 @@ module GQL
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
self.const_set "#{id.to_s.camelize}Call",
|
63
|
+
self.const_set "#{id.to_s.camelize}Call", klass
|
64
64
|
end
|
65
65
|
else
|
66
66
|
proc_or_class
|
67
67
|
end
|
68
68
|
|
69
|
+
call_class.id = id.to_s
|
69
70
|
call_class.result_class = result_class
|
70
71
|
|
71
72
|
self.calls = calls.merge(id.to_sym => call_class)
|
@@ -114,7 +115,7 @@ module GQL
|
|
114
115
|
else
|
115
116
|
super
|
116
117
|
end
|
117
|
-
rescue NoMethodError
|
118
|
+
rescue NoMethodError
|
118
119
|
raise Errors::UndefinedFieldType, method
|
119
120
|
end
|
120
121
|
end
|
data/lib/gql/parser.rb
CHANGED
@@ -6,16 +6,17 @@
|
|
6
6
|
|
7
7
|
require 'racc/parser.rb'
|
8
8
|
|
9
|
-
|
10
9
|
require 'active_support/json'
|
11
10
|
require 'active_support/core_ext/object/blank'
|
12
11
|
require 'active_support/core_ext/object/try'
|
13
12
|
require 'active_support/core_ext/object/json'
|
14
13
|
|
14
|
+
require 'gql/tokenizer'
|
15
|
+
|
15
16
|
module GQL
|
16
17
|
class Parser < Racc::Parser
|
17
18
|
|
18
|
-
module_eval(<<'...end parser.
|
19
|
+
module_eval(<<'...end parser.racc/module_eval...', 'parser.racc', 135)
|
19
20
|
|
20
21
|
class Query < Struct.new(:root, :variables)
|
21
22
|
def as_json(*)
|
@@ -48,34 +49,9 @@ module_eval(<<'...end parser.y/module_eval...', 'parser.y', 134)
|
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
UNESCAPE_MAP.update(
|
54
|
-
?" => '"',
|
55
|
-
?\\ => '\\',
|
56
|
-
?/ => '/',
|
57
|
-
?b => "\b",
|
58
|
-
?f => "\f",
|
59
|
-
?n => "\n",
|
60
|
-
?r => "\r",
|
61
|
-
?t => "\t",
|
62
|
-
?u => nil,
|
63
|
-
)
|
64
|
-
|
65
|
-
EMPTY_8BIT_STRING = ''
|
66
|
-
|
67
|
-
if String.method_defined? :encode
|
68
|
-
EMPTY_8BIT_STRING.force_encoding Encoding::ASCII_8BIT
|
69
|
-
end
|
70
|
-
|
71
|
-
def initialize(tokenizer)
|
52
|
+
def initialize(str)
|
72
53
|
super()
|
73
|
-
|
74
|
-
@tokenizer = tokenizer
|
75
|
-
end
|
76
|
-
|
77
|
-
def next_token
|
78
|
-
@tokenizer.next_token
|
54
|
+
scan_setup str
|
79
55
|
end
|
80
56
|
|
81
57
|
def parse
|
@@ -83,38 +59,14 @@ module_eval(<<'...end parser.y/module_eval...', 'parser.y', 134)
|
|
83
59
|
end
|
84
60
|
|
85
61
|
def on_error(token, value, vstack)
|
86
|
-
raise Errors::SyntaxError.new(value, token_to_str(token))
|
62
|
+
raise Errors::SyntaxError.new(lineno, value, token_to_str(token))
|
87
63
|
end
|
88
64
|
|
89
65
|
private
|
90
|
-
def unescape_string(str)
|
91
|
-
string = str.gsub(%r((?:\\[\\bfnrt"/]|(?:\\u(?:[A-Fa-f\d]{4}))+|\\[\x20-\xff]))n) do |c|
|
92
|
-
if u = UNESCAPE_MAP[$&[1]]
|
93
|
-
u
|
94
|
-
else # \uXXXX
|
95
|
-
bytes = EMPTY_8BIT_STRING.dup
|
96
|
-
i = 0
|
97
|
-
|
98
|
-
while c[6 * i] == ?\\ && c[6 * i + 1] == ?u
|
99
|
-
bytes << c[6 * i + 2, 2].to_i(16) << c[6 * i + 4, 2].to_i(16)
|
100
|
-
i += 1
|
101
|
-
end
|
102
|
-
|
103
|
-
JSON.iconv('utf-8', 'utf-16be', bytes)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
if string.respond_to? :force_encoding
|
108
|
-
string.force_encoding ::Encoding::UTF_8
|
109
|
-
end
|
110
|
-
|
111
|
-
string
|
112
|
-
end
|
113
|
-
|
114
66
|
def convert_number(str)
|
115
67
|
str.count('.') > 0 ? str.to_f : str.to_i
|
116
68
|
end
|
117
|
-
...end parser.
|
69
|
+
...end parser.racc/module_eval...
|
118
70
|
##### State transition tables begin ###
|
119
71
|
|
120
72
|
racc_action_table = [
|
@@ -339,77 +291,77 @@ Racc_debug_parser = false
|
|
339
291
|
|
340
292
|
# reduce 0 omitted
|
341
293
|
|
342
|
-
module_eval(<<'.,.,', 'parser.
|
294
|
+
module_eval(<<'.,.,', 'parser.racc', 4)
|
343
295
|
def _reduce_1(val, _values, result)
|
344
296
|
result = Query.new(val[1], val[0].merge(val[2]))
|
345
297
|
result
|
346
298
|
end
|
347
299
|
.,.,
|
348
300
|
|
349
|
-
module_eval(<<'.,.,', 'parser.
|
301
|
+
module_eval(<<'.,.,', 'parser.racc', 8)
|
350
302
|
def _reduce_2(val, _values, result)
|
351
303
|
result = Field.new(nil, nil, val[0], nil )
|
352
304
|
result
|
353
305
|
end
|
354
306
|
.,.,
|
355
307
|
|
356
|
-
module_eval(<<'.,.,', 'parser.
|
308
|
+
module_eval(<<'.,.,', 'parser.racc', 9)
|
357
309
|
def _reduce_3(val, _values, result)
|
358
310
|
result = Field.new(nil, nil, nil, val[1])
|
359
311
|
result
|
360
312
|
end
|
361
313
|
.,.,
|
362
314
|
|
363
|
-
module_eval(<<'.,.,', 'parser.
|
315
|
+
module_eval(<<'.,.,', 'parser.racc', 13)
|
364
316
|
def _reduce_4(val, _values, result)
|
365
317
|
result = Call.new(val[0], val[1], nil, val[2].presence)
|
366
318
|
result
|
367
319
|
end
|
368
320
|
.,.,
|
369
321
|
|
370
|
-
module_eval(<<'.,.,', 'parser.
|
322
|
+
module_eval(<<'.,.,', 'parser.racc', 14)
|
371
323
|
def _reduce_5(val, _values, result)
|
372
324
|
result = Call.new(val[0], val[1], val[3], nil )
|
373
325
|
result
|
374
326
|
end
|
375
327
|
.,.,
|
376
328
|
|
377
|
-
module_eval(<<'.,.,', 'parser.
|
329
|
+
module_eval(<<'.,.,', 'parser.racc', 15)
|
378
330
|
def _reduce_6(val, _values, result)
|
379
331
|
result = Call.new(val[0], val[1], nil, nil )
|
380
332
|
result
|
381
333
|
end
|
382
334
|
.,.,
|
383
335
|
|
384
|
-
module_eval(<<'.,.,', 'parser.
|
336
|
+
module_eval(<<'.,.,', 'parser.racc', 19)
|
385
337
|
def _reduce_7(val, _values, result)
|
386
338
|
result = []
|
387
339
|
result
|
388
340
|
end
|
389
341
|
.,.,
|
390
342
|
|
391
|
-
module_eval(<<'.,.,', 'parser.
|
343
|
+
module_eval(<<'.,.,', 'parser.racc', 20)
|
392
344
|
def _reduce_8(val, _values, result)
|
393
345
|
result = []
|
394
346
|
result
|
395
347
|
end
|
396
348
|
.,.,
|
397
349
|
|
398
|
-
module_eval(<<'.,.,', 'parser.
|
350
|
+
module_eval(<<'.,.,', 'parser.racc', 21)
|
399
351
|
def _reduce_9(val, _values, result)
|
400
352
|
result = val[1]
|
401
353
|
result
|
402
354
|
end
|
403
355
|
.,.,
|
404
356
|
|
405
|
-
module_eval(<<'.,.,', 'parser.
|
357
|
+
module_eval(<<'.,.,', 'parser.racc', 25)
|
406
358
|
def _reduce_10(val, _values, result)
|
407
359
|
result.push val[2]
|
408
360
|
result
|
409
361
|
end
|
410
362
|
.,.,
|
411
363
|
|
412
|
-
module_eval(<<'.,.,', 'parser.
|
364
|
+
module_eval(<<'.,.,', 'parser.racc', 26)
|
413
365
|
def _reduce_11(val, _values, result)
|
414
366
|
result = val
|
415
367
|
result
|
@@ -420,84 +372,84 @@ module_eval(<<'.,.,', 'parser.y', 26)
|
|
420
372
|
|
421
373
|
# reduce 13 omitted
|
422
374
|
|
423
|
-
module_eval(<<'.,.,', 'parser.
|
375
|
+
module_eval(<<'.,.,', 'parser.racc', 35)
|
424
376
|
def _reduce_14(val, _values, result)
|
425
377
|
result = []
|
426
378
|
result
|
427
379
|
end
|
428
380
|
.,.,
|
429
381
|
|
430
|
-
module_eval(<<'.,.,', 'parser.
|
382
|
+
module_eval(<<'.,.,', 'parser.racc', 36)
|
431
383
|
def _reduce_15(val, _values, result)
|
432
384
|
result = val[1]
|
433
385
|
result
|
434
386
|
end
|
435
387
|
.,.,
|
436
388
|
|
437
|
-
module_eval(<<'.,.,', 'parser.
|
389
|
+
module_eval(<<'.,.,', 'parser.racc', 40)
|
438
390
|
def _reduce_16(val, _values, result)
|
439
391
|
result.push val[2]
|
440
392
|
result
|
441
393
|
end
|
442
394
|
.,.,
|
443
395
|
|
444
|
-
module_eval(<<'.,.,', 'parser.
|
396
|
+
module_eval(<<'.,.,', 'parser.racc', 41)
|
445
397
|
def _reduce_17(val, _values, result)
|
446
398
|
result = val
|
447
399
|
result
|
448
400
|
end
|
449
401
|
.,.,
|
450
402
|
|
451
|
-
module_eval(<<'.,.,', 'parser.
|
403
|
+
module_eval(<<'.,.,', 'parser.racc', 45)
|
452
404
|
def _reduce_18(val, _values, result)
|
453
405
|
result = Field.new(val[0], val[2], nil, val[1].presence)
|
454
406
|
result
|
455
407
|
end
|
456
408
|
.,.,
|
457
409
|
|
458
|
-
module_eval(<<'.,.,', 'parser.
|
410
|
+
module_eval(<<'.,.,', 'parser.racc', 46)
|
459
411
|
def _reduce_19(val, _values, result)
|
460
412
|
result = Field.new(val[0], val[3], val[2], nil )
|
461
413
|
result
|
462
414
|
end
|
463
415
|
.,.,
|
464
416
|
|
465
|
-
module_eval(<<'.,.,', 'parser.
|
417
|
+
module_eval(<<'.,.,', 'parser.racc', 47)
|
466
418
|
def _reduce_20(val, _values, result)
|
467
419
|
result = Field.new(val[0], val[1], nil, nil )
|
468
420
|
result
|
469
421
|
end
|
470
422
|
.,.,
|
471
423
|
|
472
|
-
module_eval(<<'.,.,', 'parser.
|
424
|
+
module_eval(<<'.,.,', 'parser.racc', 48)
|
473
425
|
def _reduce_21(val, _values, result)
|
474
426
|
result = Field.new(val[0], nil, nil, val[1].presence)
|
475
427
|
result
|
476
428
|
end
|
477
429
|
.,.,
|
478
430
|
|
479
|
-
module_eval(<<'.,.,', 'parser.
|
431
|
+
module_eval(<<'.,.,', 'parser.racc', 49)
|
480
432
|
def _reduce_22(val, _values, result)
|
481
433
|
result = Field.new(val[0], nil, val[2], nil )
|
482
434
|
result
|
483
435
|
end
|
484
436
|
.,.,
|
485
437
|
|
486
|
-
module_eval(<<'.,.,', 'parser.
|
438
|
+
module_eval(<<'.,.,', 'parser.racc', 50)
|
487
439
|
def _reduce_23(val, _values, result)
|
488
440
|
result = Field.new(val[0], nil, nil, nil )
|
489
441
|
result
|
490
442
|
end
|
491
443
|
.,.,
|
492
444
|
|
493
|
-
module_eval(<<'.,.,', 'parser.
|
445
|
+
module_eval(<<'.,.,', 'parser.racc', 54)
|
494
446
|
def _reduce_24(val, _values, result)
|
495
447
|
result = val[1]
|
496
448
|
result
|
497
449
|
end
|
498
450
|
.,.,
|
499
451
|
|
500
|
-
module_eval(<<'.,.,', 'parser.
|
452
|
+
module_eval(<<'.,.,', 'parser.racc', 58)
|
501
453
|
def _reduce_25(val, _values, result)
|
502
454
|
result = {}
|
503
455
|
result
|
@@ -508,21 +460,21 @@ module_eval(<<'.,.,', 'parser.y', 58)
|
|
508
460
|
|
509
461
|
# reduce 27 omitted
|
510
462
|
|
511
|
-
module_eval(<<'.,.,', 'parser.
|
463
|
+
module_eval(<<'.,.,', 'parser.racc', 64)
|
512
464
|
def _reduce_28(val, _values, result)
|
513
465
|
result.update val[1]
|
514
466
|
result
|
515
467
|
end
|
516
468
|
.,.,
|
517
469
|
|
518
|
-
module_eval(<<'.,.,', 'parser.
|
470
|
+
module_eval(<<'.,.,', 'parser.racc', 68)
|
519
471
|
def _reduce_29(val, _values, result)
|
520
472
|
result = { val[0] => val[2] }
|
521
473
|
result
|
522
474
|
end
|
523
475
|
.,.,
|
524
476
|
|
525
|
-
module_eval(<<'.,.,', 'parser.
|
477
|
+
module_eval(<<'.,.,', 'parser.racc', 72)
|
526
478
|
def _reduce_30(val, _values, result)
|
527
479
|
result = val[1]
|
528
480
|
result
|
@@ -537,21 +489,21 @@ module_eval(<<'.,.,', 'parser.y', 72)
|
|
537
489
|
|
538
490
|
# reduce 34 omitted
|
539
491
|
|
540
|
-
module_eval(<<'.,.,', 'parser.
|
492
|
+
module_eval(<<'.,.,', 'parser.racc', 86)
|
541
493
|
def _reduce_35(val, _values, result)
|
542
494
|
result = {}
|
543
495
|
result
|
544
496
|
end
|
545
497
|
.,.,
|
546
498
|
|
547
|
-
module_eval(<<'.,.,', 'parser.
|
499
|
+
module_eval(<<'.,.,', 'parser.racc', 87)
|
548
500
|
def _reduce_36(val, _values, result)
|
549
501
|
result = val[1]
|
550
502
|
result
|
551
503
|
end
|
552
504
|
.,.,
|
553
505
|
|
554
|
-
module_eval(<<'.,.,', 'parser.
|
506
|
+
module_eval(<<'.,.,', 'parser.racc', 91)
|
555
507
|
def _reduce_37(val, _values, result)
|
556
508
|
result.update val[2]
|
557
509
|
result
|
@@ -560,35 +512,35 @@ module_eval(<<'.,.,', 'parser.y', 91)
|
|
560
512
|
|
561
513
|
# reduce 38 omitted
|
562
514
|
|
563
|
-
module_eval(<<'.,.,', 'parser.
|
515
|
+
module_eval(<<'.,.,', 'parser.racc', 96)
|
564
516
|
def _reduce_39(val, _values, result)
|
565
517
|
result = { val[0] => val[2] }
|
566
518
|
result
|
567
519
|
end
|
568
520
|
.,.,
|
569
521
|
|
570
|
-
module_eval(<<'.,.,', 'parser.
|
522
|
+
module_eval(<<'.,.,', 'parser.racc', 100)
|
571
523
|
def _reduce_40(val, _values, result)
|
572
524
|
result = []
|
573
525
|
result
|
574
526
|
end
|
575
527
|
.,.,
|
576
528
|
|
577
|
-
module_eval(<<'.,.,', 'parser.
|
529
|
+
module_eval(<<'.,.,', 'parser.racc', 101)
|
578
530
|
def _reduce_41(val, _values, result)
|
579
531
|
result = val[1]
|
580
532
|
result
|
581
533
|
end
|
582
534
|
.,.,
|
583
535
|
|
584
|
-
module_eval(<<'.,.,', 'parser.
|
536
|
+
module_eval(<<'.,.,', 'parser.racc', 105)
|
585
537
|
def _reduce_42(val, _values, result)
|
586
538
|
result.push val[2]
|
587
539
|
result
|
588
540
|
end
|
589
541
|
.,.,
|
590
542
|
|
591
|
-
module_eval(<<'.,.,', 'parser.
|
543
|
+
module_eval(<<'.,.,', 'parser.racc', 106)
|
592
544
|
def _reduce_43(val, _values, result)
|
593
545
|
result = val
|
594
546
|
result
|
@@ -597,42 +549,42 @@ module_eval(<<'.,.,', 'parser.y', 106)
|
|
597
549
|
|
598
550
|
# reduce 44 omitted
|
599
551
|
|
600
|
-
module_eval(<<'.,.,', 'parser.
|
552
|
+
module_eval(<<'.,.,', 'parser.racc', 111)
|
601
553
|
def _reduce_45(val, _values, result)
|
602
554
|
result = convert_number(val[0])
|
603
555
|
result
|
604
556
|
end
|
605
557
|
.,.,
|
606
558
|
|
607
|
-
module_eval(<<'.,.,', 'parser.
|
559
|
+
module_eval(<<'.,.,', 'parser.racc', 112)
|
608
560
|
def _reduce_46(val, _values, result)
|
609
561
|
result = true
|
610
562
|
result
|
611
563
|
end
|
612
564
|
.,.,
|
613
565
|
|
614
|
-
module_eval(<<'.,.,', 'parser.
|
566
|
+
module_eval(<<'.,.,', 'parser.racc', 113)
|
615
567
|
def _reduce_47(val, _values, result)
|
616
568
|
result = false
|
617
569
|
result
|
618
570
|
end
|
619
571
|
.,.,
|
620
572
|
|
621
|
-
module_eval(<<'.,.,', 'parser.
|
573
|
+
module_eval(<<'.,.,', 'parser.racc', 114)
|
622
574
|
def _reduce_48(val, _values, result)
|
623
575
|
result = nil
|
624
576
|
result
|
625
577
|
end
|
626
578
|
.,.,
|
627
579
|
|
628
|
-
module_eval(<<'.,.,', 'parser.
|
580
|
+
module_eval(<<'.,.,', 'parser.racc', 118)
|
629
581
|
def _reduce_49(val, _values, result)
|
630
582
|
result = unescape_string(val[0])
|
631
583
|
result
|
632
584
|
end
|
633
585
|
.,.,
|
634
586
|
|
635
|
-
module_eval(<<'.,.,', 'parser.
|
587
|
+
module_eval(<<'.,.,', 'parser.racc', 121)
|
636
588
|
def _reduce_50(val, _values, result)
|
637
589
|
result = val[0].to_sym
|
638
590
|
result
|
@@ -644,4 +596,4 @@ def _reduce_none(val, _values, result)
|
|
644
596
|
end
|
645
597
|
|
646
598
|
end # class Parser
|
647
|
-
|
599
|
+
end # GQL
|
data/lib/gql/schema/call.rb
CHANGED
@@ -5,8 +5,16 @@ module GQL
|
|
5
5
|
|
6
6
|
string :id
|
7
7
|
string :type, -> { target.name }
|
8
|
-
array :parameters, -> { target.method.parameters }, item_class: Parameter
|
9
8
|
object :result_class, -> { target.result_class || Placeholder }, node_class: Node
|
9
|
+
|
10
|
+
|
11
|
+
array :parameters, -> {
|
12
|
+
if target.proc
|
13
|
+
target.proc.parameters
|
14
|
+
else
|
15
|
+
target.instance_method(:execute).parameters
|
16
|
+
end
|
17
|
+
}, item_class: Parameter
|
10
18
|
end
|
11
19
|
end
|
12
20
|
end
|
data/lib/gql/tokenizer.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
#--
|
2
2
|
# DO NOT MODIFY!!!!
|
3
3
|
# This file is automatically generated by rex 1.0.5
|
4
|
-
# from lexical definition file "
|
4
|
+
# from lexical definition file "support/tokenizer.rex".
|
5
5
|
#++
|
6
6
|
|
7
7
|
require 'racc/parser'
|
8
|
-
class GQL::
|
8
|
+
class GQL::Parser < Racc::Parser
|
9
9
|
require 'strscan'
|
10
10
|
|
11
|
-
class
|
11
|
+
class Unused < StandardError ; end
|
12
12
|
|
13
13
|
attr_reader :lineno
|
14
14
|
attr_reader :filename
|
@@ -63,8 +63,8 @@ class GQL::Tokenizer < Racc::Parser
|
|
63
63
|
when (text = @ss.scan(/\/\//))
|
64
64
|
action { @state = :REM; nil }
|
65
65
|
|
66
|
-
when (text = @ss.scan(/"(?:[^"\\]|\\
|
67
|
-
action { [:STRING, text
|
66
|
+
when (text = @ss.scan(/"(?:[^"\\]|\\["\\\/bfnrt]|\\u[0-9a-fA-F]{4})*"/))
|
67
|
+
action { [:STRING, unescape_string(text)] }
|
68
68
|
|
69
69
|
when (text = @ss.scan(/-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/))
|
70
70
|
action { [:NUMBER, text] }
|
@@ -92,7 +92,7 @@ class GQL::Tokenizer < Racc::Parser
|
|
92
92
|
|
93
93
|
else
|
94
94
|
text = @ss.string[@ss.pos .. -1]
|
95
|
-
raise ScanError, "can not match: '" + text + "'"
|
95
|
+
raise GQL::Errors::ScanError, "can not match: '" + text + "'"
|
96
96
|
end # if
|
97
97
|
|
98
98
|
when :REMS
|
@@ -103,9 +103,12 @@ class GQL::Tokenizer < Racc::Parser
|
|
103
103
|
when (text = @ss.scan(/.*(?=\*\/)/))
|
104
104
|
;
|
105
105
|
|
106
|
+
when (text = @ss.scan(/(.|\n)*(?=\*\/)/))
|
107
|
+
;
|
108
|
+
|
106
109
|
else
|
107
110
|
text = @ss.string[@ss.pos .. -1]
|
108
|
-
raise ScanError, "can not match: '" + text + "'"
|
111
|
+
raise GQL::Errors::ScanError, "can not match: '" + text + "'"
|
109
112
|
end # if
|
110
113
|
|
111
114
|
when :REM
|
@@ -118,13 +121,49 @@ class GQL::Tokenizer < Racc::Parser
|
|
118
121
|
|
119
122
|
else
|
120
123
|
text = @ss.string[@ss.pos .. -1]
|
121
|
-
raise ScanError, "can not match: '" + text + "'"
|
124
|
+
raise GQL::Errors::ScanError, "can not match: '" + text + "'"
|
122
125
|
end # if
|
123
126
|
|
124
127
|
else
|
125
|
-
raise ScanError, "undefined state: '" + state.to_s + "'"
|
128
|
+
raise GQL::Errors::ScanError, "undefined state: '" + state.to_s + "'"
|
126
129
|
end # case state
|
127
130
|
token
|
128
131
|
end # def _next_token
|
129
132
|
|
133
|
+
private
|
134
|
+
UNESCAPE_MAP = Hash.new { |h, k| h[k] = k.chr }
|
135
|
+
UNESCAPE_MAP.update(
|
136
|
+
?" => '"',
|
137
|
+
?\\ => '\\',
|
138
|
+
?/ => '/',
|
139
|
+
?b => "\b",
|
140
|
+
?f => "\f",
|
141
|
+
?n => "\n",
|
142
|
+
?r => "\r",
|
143
|
+
?t => "\t",
|
144
|
+
?u => nil,
|
145
|
+
)
|
146
|
+
EMPTY_8BIT_STRING = ''
|
147
|
+
if String.method_defined? :encode
|
148
|
+
EMPTY_8BIT_STRING.force_encoding Encoding::ASCII_8BIT
|
149
|
+
end
|
150
|
+
def unescape_string(str)
|
151
|
+
string = str.gsub(/^"|"$/, '').gsub(%r((?:\\[\\bfnrt"/]|(?:\\u(?:[A-Fa-f\d]{4}))+|\\[\x20-\xff]))n) do |c|
|
152
|
+
if u = UNESCAPE_MAP[$&[1]]
|
153
|
+
u
|
154
|
+
else # \uXXXX
|
155
|
+
bytes = EMPTY_8BIT_STRING.dup
|
156
|
+
i = 0
|
157
|
+
while c[6 * i] == ?\\ && c[6 * i + 1] == ?u
|
158
|
+
bytes << c[6 * i + 2, 2].to_i(16) << c[6 * i + 4, 2].to_i(16)
|
159
|
+
i += 1
|
160
|
+
end
|
161
|
+
JSON.iconv('utf-8', 'utf-16be', bytes)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
if string.respond_to? :force_encoding
|
165
|
+
string.force_encoding ::Encoding::UTF_8
|
166
|
+
end
|
167
|
+
string
|
168
|
+
end
|
130
169
|
end # class
|
data/lib/gql/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Andert
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: minitest
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rexical
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,6 +93,7 @@ files:
|
|
107
93
|
- README.md
|
108
94
|
- Rakefile
|
109
95
|
- bin/console
|
96
|
+
- bin/rake
|
110
97
|
- bin/setup
|
111
98
|
- gql.gemspec
|
112
99
|
- lib/gql.rb
|
@@ -122,7 +109,6 @@ files:
|
|
122
109
|
- lib/gql/number.rb
|
123
110
|
- lib/gql/object.rb
|
124
111
|
- lib/gql/parser.rb
|
125
|
-
- lib/gql/parser.y
|
126
112
|
- lib/gql/schema/call.rb
|
127
113
|
- lib/gql/schema/field.rb
|
128
114
|
- lib/gql/schema/list.rb
|
@@ -131,8 +117,8 @@ files:
|
|
131
117
|
- lib/gql/schema/placeholder.rb
|
132
118
|
- lib/gql/simple.rb
|
133
119
|
- lib/gql/string.rb
|
120
|
+
- lib/gql/test_case.rb
|
134
121
|
- lib/gql/tokenizer.rb
|
135
|
-
- lib/gql/tokenizer.rex
|
136
122
|
- lib/gql/version.rb
|
137
123
|
homepage: https://github.com/martinandert/gql
|
138
124
|
licenses:
|
data/lib/gql/parser.y
DELETED
@@ -1,231 +0,0 @@
|
|
1
|
-
class GQL::Parser
|
2
|
-
token STRING NUMBER TRUE FALSE NULL AS IDENT
|
3
|
-
rule
|
4
|
-
query
|
5
|
-
: variables root variables { result = Query.new(val[1], val[0].merge(val[2])) }
|
6
|
-
;
|
7
|
-
|
8
|
-
root
|
9
|
-
: call { result = Field.new(nil, nil, val[0], nil ) }
|
10
|
-
| '{' field_list '}' { result = Field.new(nil, nil, nil, val[1]) }
|
11
|
-
;
|
12
|
-
|
13
|
-
call
|
14
|
-
: identifier arguments fields { result = Call.new(val[0], val[1], nil, val[2].presence) }
|
15
|
-
| identifier arguments '.' call { result = Call.new(val[0], val[1], val[3], nil ) }
|
16
|
-
| identifier arguments { result = Call.new(val[0], val[1], nil, nil ) }
|
17
|
-
;
|
18
|
-
|
19
|
-
arguments
|
20
|
-
: /* empty */ { result = [] }
|
21
|
-
| '(' ')' { result = [] }
|
22
|
-
| '(' argument_list ')' { result = val[1] }
|
23
|
-
;
|
24
|
-
|
25
|
-
argument_list
|
26
|
-
: argument_list ',' argument { result.push val[2] }
|
27
|
-
| argument { result = val }
|
28
|
-
;
|
29
|
-
|
30
|
-
argument
|
31
|
-
: variable_identifier
|
32
|
-
| json_value
|
33
|
-
;
|
34
|
-
|
35
|
-
fields
|
36
|
-
: '{' '}' { result = [] }
|
37
|
-
| '{' field_list '}' { result = val[1] }
|
38
|
-
;
|
39
|
-
|
40
|
-
field_list
|
41
|
-
: field_list ',' field { result.push val[2] }
|
42
|
-
| field { result = val }
|
43
|
-
;
|
44
|
-
|
45
|
-
field
|
46
|
-
: identifier fields alias_identifier { result = Field.new(val[0], val[2], nil, val[1].presence) }
|
47
|
-
| identifier '.' call alias_identifier { result = Field.new(val[0], val[3], val[2], nil ) }
|
48
|
-
| identifier alias_identifier { result = Field.new(val[0], val[1], nil, nil ) }
|
49
|
-
| identifier fields { result = Field.new(val[0], nil, nil, val[1].presence) }
|
50
|
-
| identifier '.' call { result = Field.new(val[0], nil, val[2], nil ) }
|
51
|
-
| identifier { result = Field.new(val[0], nil, nil, nil ) }
|
52
|
-
;
|
53
|
-
|
54
|
-
alias_identifier
|
55
|
-
: AS identifier { result = val[1] }
|
56
|
-
;
|
57
|
-
|
58
|
-
variables
|
59
|
-
: /* empty */ { result = {} }
|
60
|
-
| variable_list
|
61
|
-
;
|
62
|
-
|
63
|
-
variable_list
|
64
|
-
: variable
|
65
|
-
| variable_list variable { result.update val[1] }
|
66
|
-
;
|
67
|
-
|
68
|
-
variable
|
69
|
-
: variable_identifier '=' variable_value { result = { val[0] => val[2] } }
|
70
|
-
;
|
71
|
-
|
72
|
-
variable_identifier
|
73
|
-
: '<' identifier '>' { result = val[1] }
|
74
|
-
;
|
75
|
-
|
76
|
-
variable_value
|
77
|
-
: json_value
|
78
|
-
;
|
79
|
-
|
80
|
-
json_value
|
81
|
-
: object
|
82
|
-
| array
|
83
|
-
| scalar
|
84
|
-
;
|
85
|
-
|
86
|
-
object
|
87
|
-
: '{' '}' { result = {} }
|
88
|
-
| '{' pairs '}' { result = val[1] }
|
89
|
-
;
|
90
|
-
|
91
|
-
pairs
|
92
|
-
: pairs ',' pair { result.update val[2] }
|
93
|
-
| pair
|
94
|
-
;
|
95
|
-
|
96
|
-
pair
|
97
|
-
: string ':' json_value { result = { val[0] => val[2] } }
|
98
|
-
;
|
99
|
-
|
100
|
-
array
|
101
|
-
: '[' ']' { result = [] }
|
102
|
-
| '[' values ']' { result = val[1] }
|
103
|
-
;
|
104
|
-
|
105
|
-
values
|
106
|
-
: values ',' json_value { result.push val[2] }
|
107
|
-
| json_value { result = val }
|
108
|
-
;
|
109
|
-
|
110
|
-
scalar
|
111
|
-
: string
|
112
|
-
| NUMBER { result = convert_number(val[0]) }
|
113
|
-
| TRUE { result = true }
|
114
|
-
| FALSE { result = false }
|
115
|
-
| NULL { result = nil }
|
116
|
-
;
|
117
|
-
|
118
|
-
string
|
119
|
-
: STRING { result = unescape_string(val[0]) }
|
120
|
-
|
121
|
-
identifier
|
122
|
-
: IDENT { result = val[0].to_sym }
|
123
|
-
;
|
124
|
-
end
|
125
|
-
|
126
|
-
---- header
|
127
|
-
|
128
|
-
require 'active_support/json'
|
129
|
-
require 'active_support/core_ext/object/blank'
|
130
|
-
require 'active_support/core_ext/object/try'
|
131
|
-
require 'active_support/core_ext/object/json'
|
132
|
-
|
133
|
-
---- inner
|
134
|
-
|
135
|
-
class Query < Struct.new(:root, :variables)
|
136
|
-
def as_json(*)
|
137
|
-
{
|
138
|
-
root: root.as_json,
|
139
|
-
variables: variables
|
140
|
-
}
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
class Field < Struct.new(:id, :alias_id, :call, :fields)
|
145
|
-
def as_json(*)
|
146
|
-
{
|
147
|
-
id: id,
|
148
|
-
alias_id: alias_id,
|
149
|
-
call: call.as_json,
|
150
|
-
fields: fields.as_json
|
151
|
-
}
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
class Call < Struct.new(:id, :arguments, :call, :fields)
|
156
|
-
def as_json(*)
|
157
|
-
{
|
158
|
-
id: id,
|
159
|
-
arguments: arguments,
|
160
|
-
call: call.as_json,
|
161
|
-
fields: fields.as_json
|
162
|
-
}
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
UNESCAPE_MAP = Hash.new { |h, k| h[k] = k.chr }
|
167
|
-
|
168
|
-
UNESCAPE_MAP.update(
|
169
|
-
?" => '"',
|
170
|
-
?\\ => '\\',
|
171
|
-
?/ => '/',
|
172
|
-
?b => "\b",
|
173
|
-
?f => "\f",
|
174
|
-
?n => "\n",
|
175
|
-
?r => "\r",
|
176
|
-
?t => "\t",
|
177
|
-
?u => nil,
|
178
|
-
)
|
179
|
-
|
180
|
-
EMPTY_8BIT_STRING = ''
|
181
|
-
|
182
|
-
if String.method_defined? :encode
|
183
|
-
EMPTY_8BIT_STRING.force_encoding Encoding::ASCII_8BIT
|
184
|
-
end
|
185
|
-
|
186
|
-
def initialize(tokenizer)
|
187
|
-
super()
|
188
|
-
|
189
|
-
@tokenizer = tokenizer
|
190
|
-
end
|
191
|
-
|
192
|
-
def next_token
|
193
|
-
@tokenizer.next_token
|
194
|
-
end
|
195
|
-
|
196
|
-
def parse
|
197
|
-
do_parse
|
198
|
-
end
|
199
|
-
|
200
|
-
def on_error(token, value, vstack)
|
201
|
-
raise Errors::SyntaxError.new(value, token_to_str(token))
|
202
|
-
end
|
203
|
-
|
204
|
-
private
|
205
|
-
def unescape_string(str)
|
206
|
-
string = str.gsub(%r((?:\\[\\bfnrt"/]|(?:\\u(?:[A-Fa-f\d]{4}))+|\\[\x20-\xff]))n) do |c|
|
207
|
-
if u = UNESCAPE_MAP[$&[1]]
|
208
|
-
u
|
209
|
-
else # \uXXXX
|
210
|
-
bytes = EMPTY_8BIT_STRING.dup
|
211
|
-
i = 0
|
212
|
-
|
213
|
-
while c[6 * i] == ?\\ && c[6 * i + 1] == ?u
|
214
|
-
bytes << c[6 * i + 2, 2].to_i(16) << c[6 * i + 4, 2].to_i(16)
|
215
|
-
i += 1
|
216
|
-
end
|
217
|
-
|
218
|
-
JSON.iconv('utf-8', 'utf-16be', bytes)
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
if string.respond_to? :force_encoding
|
223
|
-
string.force_encoding ::Encoding::UTF_8
|
224
|
-
end
|
225
|
-
|
226
|
-
string
|
227
|
-
end
|
228
|
-
|
229
|
-
def convert_number(str)
|
230
|
-
str.count('.') > 0 ? str.to_f : str.to_i
|
231
|
-
end
|
data/lib/gql/tokenizer.rex
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
class GQL::Tokenizer
|
2
|
-
macro
|
3
|
-
BLANK \s+
|
4
|
-
REM_IN \/\*
|
5
|
-
REM_OUT \*\/
|
6
|
-
REM \/\/
|
7
|
-
STRING "(?:[^"\\]|\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4}))*"
|
8
|
-
NUMBER -?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?
|
9
|
-
TRUE true
|
10
|
-
FALSE false
|
11
|
-
NULL null
|
12
|
-
IDENT [a-zA-Z_][a-zA-Z0-9_]*
|
13
|
-
AS [aA][sS]
|
14
|
-
|
15
|
-
rule
|
16
|
-
|
17
|
-
# [:state] pattern [action]
|
18
|
-
|
19
|
-
# remarks
|
20
|
-
{REM_IN} { @state = :REMS; nil }
|
21
|
-
:REMS {REM_OUT} { @state = nil; nil }
|
22
|
-
:REMS .*(?={REM_OUT}) # ignore
|
23
|
-
{REM} { @state = :REM; nil }
|
24
|
-
:REM \n { @state = nil; nil }
|
25
|
-
:REM .*(?=$) # ignore
|
26
|
-
|
27
|
-
# scalars
|
28
|
-
{STRING} { [:STRING, text.gsub(/^"|"$/, '')] }
|
29
|
-
{NUMBER} { [:NUMBER, text] }
|
30
|
-
{TRUE} { [:TRUE, text] }
|
31
|
-
{FALSE} { [:FALSE, text] }
|
32
|
-
{NULL} { [:NULL, text] }
|
33
|
-
|
34
|
-
# keywords
|
35
|
-
{AS} { [:AS, text] }
|
36
|
-
|
37
|
-
# identifier
|
38
|
-
{IDENT} { [:IDENT, text] }
|
39
|
-
|
40
|
-
# whitespace
|
41
|
-
{BLANK} # ignore
|
42
|
-
|
43
|
-
# rest
|
44
|
-
. { [text, text] }
|
45
|
-
|
46
|
-
end
|