tinygql 0.1.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -0
- data/bin/bench.rb +38 -0
- data/bin/make_hash.rb +51 -0
- data/lib/tinygql/lexer.rb +115 -42
- data/lib/tinygql/nodes.rb +130 -81
- data/lib/tinygql/nodes.rb.erb +15 -2
- data/lib/tinygql/parser.rb +119 -65
- data/lib/tinygql/version.rb +1 -1
- data/test/lexer_test.rb +101 -0
- data/test/parser_test.rb +17 -0
- metadata +3 -2
data/lib/tinygql/nodes.rb
CHANGED
@@ -3,50 +3,62 @@ module TinyGQL
|
|
3
3
|
class Node
|
4
4
|
include Enumerable
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
6
|
+
# `start` is the start position of this node in the source document
|
7
|
+
attr_reader :start
|
8
|
+
|
9
|
+
def initialize start
|
10
|
+
@start = start
|
11
|
+
end
|
12
|
+
|
13
|
+
# Return the line of this node given `doc`
|
14
|
+
def line doc
|
15
|
+
doc[0, @start].count("\n") + 1
|
16
|
+
end
|
17
|
+
|
18
|
+
def document?; false; end
|
19
|
+
def operation_definition?; false; end
|
20
|
+
def variable?; false; end
|
21
|
+
def named_type?; false; end
|
22
|
+
def not_null_type?; false; end
|
23
|
+
def list_type?; false; end
|
24
|
+
def variable_definition?; false; end
|
25
|
+
def value?; false; end
|
26
|
+
def argument?; false; end
|
27
|
+
def field?; false; end
|
28
|
+
def object_field?; false; end
|
29
|
+
def int_value?; false; end
|
30
|
+
def float_value?; false; end
|
31
|
+
def string_value?; false; end
|
32
|
+
def boolean_value?; false; end
|
33
|
+
def null_value?; false; end
|
34
|
+
def enum_value?; false; end
|
35
|
+
def list_value?; false; end
|
36
|
+
def object_value?; false; end
|
37
|
+
def directive?; false; end
|
38
|
+
def type_condition?; false; end
|
39
|
+
def inline_fragment?; false; end
|
40
|
+
def fragment_spread?; false; end
|
41
|
+
def fragment_definition?; false; end
|
42
|
+
def root_operation_type_definition?; false; end
|
43
|
+
def schema_definition?; false; end
|
44
|
+
def field_definition?; false; end
|
45
|
+
def input_value_definition?; false; end
|
46
|
+
def object_type_definition?; false; end
|
47
|
+
def interface_type_definition?; false; end
|
48
|
+
def union_type_definition?; false; end
|
49
|
+
def scalar_type_definition?; false; end
|
50
|
+
def enum_value_definition?; false; end
|
51
|
+
def enum_type_definition?; false; end
|
52
|
+
def input_object_type_definition?; false; end
|
53
|
+
def object_type_extension?; false; end
|
54
|
+
def executable_directive_location?; false; end
|
55
|
+
def type_system_directive_location?; false; end
|
56
|
+
def directive_definition?; false; end
|
57
|
+
def scalar_type_extension?; false; end
|
58
|
+
def interface_type_extension?; false; end
|
59
|
+
def union_type_extension?; false; end
|
60
|
+
def enum_type_extension?; false; end
|
61
|
+
def input_object_type_extension?; false; end
|
50
62
|
def each(&blk)
|
51
63
|
yield self
|
52
64
|
children.each { |v| v.each(&blk) }
|
@@ -56,7 +68,8 @@ module TinyGQL
|
|
56
68
|
class Document < Node
|
57
69
|
attr_reader :definitions
|
58
70
|
|
59
|
-
def initialize definitions
|
71
|
+
def initialize pos, definitions
|
72
|
+
super(pos)
|
60
73
|
@definitions = definitions
|
61
74
|
end
|
62
75
|
|
@@ -77,7 +90,8 @@ module TinyGQL
|
|
77
90
|
class OperationDefinition < Node
|
78
91
|
attr_reader :type, :name, :variable_definitions, :directives, :selection_set
|
79
92
|
|
80
|
-
def initialize type, name, variable_definitions, directives, selection_set
|
93
|
+
def initialize pos, type, name, variable_definitions, directives, selection_set
|
94
|
+
super(pos)
|
81
95
|
@type = type
|
82
96
|
@name = name
|
83
97
|
@variable_definitions = variable_definitions
|
@@ -102,7 +116,8 @@ module TinyGQL
|
|
102
116
|
class Variable < Node
|
103
117
|
attr_reader :name
|
104
118
|
|
105
|
-
def initialize name
|
119
|
+
def initialize pos, name
|
120
|
+
super(pos)
|
106
121
|
@name = name
|
107
122
|
end
|
108
123
|
|
@@ -123,7 +138,8 @@ module TinyGQL
|
|
123
138
|
class NamedType < Node
|
124
139
|
attr_reader :name
|
125
140
|
|
126
|
-
def initialize name
|
141
|
+
def initialize pos, name
|
142
|
+
super(pos)
|
127
143
|
@name = name
|
128
144
|
end
|
129
145
|
|
@@ -144,7 +160,8 @@ module TinyGQL
|
|
144
160
|
class NotNullType < Node
|
145
161
|
attr_reader :type
|
146
162
|
|
147
|
-
def initialize type
|
163
|
+
def initialize pos, type
|
164
|
+
super(pos)
|
148
165
|
@type = type
|
149
166
|
end
|
150
167
|
|
@@ -165,7 +182,8 @@ module TinyGQL
|
|
165
182
|
class ListType < Node
|
166
183
|
attr_reader :type
|
167
184
|
|
168
|
-
def initialize type
|
185
|
+
def initialize pos, type
|
186
|
+
super(pos)
|
169
187
|
@type = type
|
170
188
|
end
|
171
189
|
|
@@ -186,7 +204,8 @@ module TinyGQL
|
|
186
204
|
class VariableDefinition < Node
|
187
205
|
attr_reader :variable, :type, :default_value
|
188
206
|
|
189
|
-
def initialize variable, type, default_value
|
207
|
+
def initialize pos, variable, type, default_value
|
208
|
+
super(pos)
|
190
209
|
@variable = variable
|
191
210
|
@type = type
|
192
211
|
@default_value = default_value
|
@@ -209,7 +228,8 @@ module TinyGQL
|
|
209
228
|
class Value < Node
|
210
229
|
attr_reader :value
|
211
230
|
|
212
|
-
def initialize value
|
231
|
+
def initialize pos, value
|
232
|
+
super(pos)
|
213
233
|
@value = value
|
214
234
|
end
|
215
235
|
|
@@ -230,7 +250,8 @@ module TinyGQL
|
|
230
250
|
class Argument < Node
|
231
251
|
attr_reader :name, :value
|
232
252
|
|
233
|
-
def initialize name, value
|
253
|
+
def initialize pos, name, value
|
254
|
+
super(pos)
|
234
255
|
@name = name
|
235
256
|
@value = value
|
236
257
|
end
|
@@ -252,7 +273,8 @@ module TinyGQL
|
|
252
273
|
class Field < Node
|
253
274
|
attr_reader :aliaz, :name, :arguments, :directives, :selection_set
|
254
275
|
|
255
|
-
def initialize aliaz, name, arguments, directives, selection_set
|
276
|
+
def initialize pos, aliaz, name, arguments, directives, selection_set
|
277
|
+
super(pos)
|
256
278
|
@aliaz = aliaz
|
257
279
|
@name = name
|
258
280
|
@arguments = arguments
|
@@ -277,7 +299,8 @@ module TinyGQL
|
|
277
299
|
class ObjectField < Node
|
278
300
|
attr_reader :name, :value
|
279
301
|
|
280
|
-
def initialize name, value
|
302
|
+
def initialize pos, name, value
|
303
|
+
super(pos)
|
281
304
|
@name = name
|
282
305
|
@value = value
|
283
306
|
end
|
@@ -390,7 +413,8 @@ module TinyGQL
|
|
390
413
|
class ObjectValue < Node
|
391
414
|
attr_reader :values
|
392
415
|
|
393
|
-
def initialize values
|
416
|
+
def initialize pos, values
|
417
|
+
super(pos)
|
394
418
|
@values = values
|
395
419
|
end
|
396
420
|
|
@@ -411,7 +435,8 @@ module TinyGQL
|
|
411
435
|
class Directive < Node
|
412
436
|
attr_reader :name, :arguments
|
413
437
|
|
414
|
-
def initialize name, arguments
|
438
|
+
def initialize pos, name, arguments
|
439
|
+
super(pos)
|
415
440
|
@name = name
|
416
441
|
@arguments = arguments
|
417
442
|
end
|
@@ -433,7 +458,8 @@ module TinyGQL
|
|
433
458
|
class TypeCondition < Node
|
434
459
|
attr_reader :named_type
|
435
460
|
|
436
|
-
def initialize named_type
|
461
|
+
def initialize pos, named_type
|
462
|
+
super(pos)
|
437
463
|
@named_type = named_type
|
438
464
|
end
|
439
465
|
|
@@ -454,7 +480,8 @@ module TinyGQL
|
|
454
480
|
class InlineFragment < Node
|
455
481
|
attr_reader :type_condition, :directives, :selection_set
|
456
482
|
|
457
|
-
def initialize type_condition, directives, selection_set
|
483
|
+
def initialize pos, type_condition, directives, selection_set
|
484
|
+
super(pos)
|
458
485
|
@type_condition = type_condition
|
459
486
|
@directives = directives
|
460
487
|
@selection_set = selection_set
|
@@ -477,7 +504,8 @@ module TinyGQL
|
|
477
504
|
class FragmentSpread < Node
|
478
505
|
attr_reader :fragment_name, :directives
|
479
506
|
|
480
|
-
def initialize fragment_name, directives
|
507
|
+
def initialize pos, fragment_name, directives
|
508
|
+
super(pos)
|
481
509
|
@fragment_name = fragment_name
|
482
510
|
@directives = directives
|
483
511
|
end
|
@@ -499,7 +527,8 @@ module TinyGQL
|
|
499
527
|
class FragmentDefinition < Node
|
500
528
|
attr_reader :fragment_name, :type_condition, :directives, :selection_set
|
501
529
|
|
502
|
-
def initialize fragment_name, type_condition, directives, selection_set
|
530
|
+
def initialize pos, fragment_name, type_condition, directives, selection_set
|
531
|
+
super(pos)
|
503
532
|
@fragment_name = fragment_name
|
504
533
|
@type_condition = type_condition
|
505
534
|
@directives = directives
|
@@ -523,7 +552,8 @@ module TinyGQL
|
|
523
552
|
class RootOperationTypeDefinition < Node
|
524
553
|
attr_reader :operation_type, :named_type
|
525
554
|
|
526
|
-
def initialize operation_type, named_type
|
555
|
+
def initialize pos, operation_type, named_type
|
556
|
+
super(pos)
|
527
557
|
@operation_type = operation_type
|
528
558
|
@named_type = named_type
|
529
559
|
end
|
@@ -545,7 +575,8 @@ module TinyGQL
|
|
545
575
|
class SchemaDefinition < Node
|
546
576
|
attr_reader :description, :directives, :root_operation_definitions
|
547
577
|
|
548
|
-
def initialize description, directives, root_operation_definitions
|
578
|
+
def initialize pos, description, directives, root_operation_definitions
|
579
|
+
super(pos)
|
549
580
|
@description = description
|
550
581
|
@directives = directives
|
551
582
|
@root_operation_definitions = root_operation_definitions
|
@@ -568,7 +599,8 @@ module TinyGQL
|
|
568
599
|
class FieldDefinition < Node
|
569
600
|
attr_reader :description, :name, :arguments_definition, :type, :directives
|
570
601
|
|
571
|
-
def initialize description, name, arguments_definition, type, directives
|
602
|
+
def initialize pos, description, name, arguments_definition, type, directives
|
603
|
+
super(pos)
|
572
604
|
@description = description
|
573
605
|
@name = name
|
574
606
|
@arguments_definition = arguments_definition
|
@@ -593,7 +625,8 @@ module TinyGQL
|
|
593
625
|
class InputValueDefinition < Node
|
594
626
|
attr_reader :description, :name, :type, :default_value, :directives
|
595
627
|
|
596
|
-
def initialize description, name, type, default_value, directives
|
628
|
+
def initialize pos, description, name, type, default_value, directives
|
629
|
+
super(pos)
|
597
630
|
@description = description
|
598
631
|
@name = name
|
599
632
|
@type = type
|
@@ -618,7 +651,8 @@ module TinyGQL
|
|
618
651
|
class ObjectTypeDefinition < Node
|
619
652
|
attr_reader :description, :name, :implements_interfaces, :directives, :fields_definition
|
620
653
|
|
621
|
-
def initialize description, name, implements_interfaces, directives, fields_definition
|
654
|
+
def initialize pos, description, name, implements_interfaces, directives, fields_definition
|
655
|
+
super(pos)
|
622
656
|
@description = description
|
623
657
|
@name = name
|
624
658
|
@implements_interfaces = implements_interfaces
|
@@ -643,7 +677,8 @@ module TinyGQL
|
|
643
677
|
class InterfaceTypeDefinition < Node
|
644
678
|
attr_reader :description, :name, :directives, :fields_definition
|
645
679
|
|
646
|
-
def initialize description, name, directives, fields_definition
|
680
|
+
def initialize pos, description, name, directives, fields_definition
|
681
|
+
super(pos)
|
647
682
|
@description = description
|
648
683
|
@name = name
|
649
684
|
@directives = directives
|
@@ -667,7 +702,8 @@ module TinyGQL
|
|
667
702
|
class UnionTypeDefinition < Node
|
668
703
|
attr_reader :description, :name, :directives, :union_member_types
|
669
704
|
|
670
|
-
def initialize description, name, directives, union_member_types
|
705
|
+
def initialize pos, description, name, directives, union_member_types
|
706
|
+
super(pos)
|
671
707
|
@description = description
|
672
708
|
@name = name
|
673
709
|
@directives = directives
|
@@ -691,7 +727,8 @@ module TinyGQL
|
|
691
727
|
class ScalarTypeDefinition < Node
|
692
728
|
attr_reader :description, :name, :directives
|
693
729
|
|
694
|
-
def initialize description, name, directives
|
730
|
+
def initialize pos, description, name, directives
|
731
|
+
super(pos)
|
695
732
|
@description = description
|
696
733
|
@name = name
|
697
734
|
@directives = directives
|
@@ -714,7 +751,8 @@ module TinyGQL
|
|
714
751
|
class EnumValueDefinition < Node
|
715
752
|
attr_reader :description, :enum_value, :directives
|
716
753
|
|
717
|
-
def initialize description, enum_value, directives
|
754
|
+
def initialize pos, description, enum_value, directives
|
755
|
+
super(pos)
|
718
756
|
@description = description
|
719
757
|
@enum_value = enum_value
|
720
758
|
@directives = directives
|
@@ -737,7 +775,8 @@ module TinyGQL
|
|
737
775
|
class EnumTypeDefinition < Node
|
738
776
|
attr_reader :description, :name, :directives, :enum_value_definition
|
739
777
|
|
740
|
-
def initialize description, name, directives, enum_value_definition
|
778
|
+
def initialize pos, description, name, directives, enum_value_definition
|
779
|
+
super(pos)
|
741
780
|
@description = description
|
742
781
|
@name = name
|
743
782
|
@directives = directives
|
@@ -761,7 +800,8 @@ module TinyGQL
|
|
761
800
|
class InputObjectTypeDefinition < Node
|
762
801
|
attr_reader :description, :name, :directives, :input_fields_definition
|
763
802
|
|
764
|
-
def initialize description, name, directives, input_fields_definition
|
803
|
+
def initialize pos, description, name, directives, input_fields_definition
|
804
|
+
super(pos)
|
765
805
|
@description = description
|
766
806
|
@name = name
|
767
807
|
@directives = directives
|
@@ -785,7 +825,8 @@ module TinyGQL
|
|
785
825
|
class ObjectTypeExtension < Node
|
786
826
|
attr_reader :name, :implements_interfaces, :directives, :fields_definition
|
787
827
|
|
788
|
-
def initialize name, implements_interfaces, directives, fields_definition
|
828
|
+
def initialize pos, name, implements_interfaces, directives, fields_definition
|
829
|
+
super(pos)
|
789
830
|
@name = name
|
790
831
|
@implements_interfaces = implements_interfaces
|
791
832
|
@directives = directives
|
@@ -809,7 +850,8 @@ module TinyGQL
|
|
809
850
|
class ExecutableDirectiveLocation < Node
|
810
851
|
attr_reader :name
|
811
852
|
|
812
|
-
def initialize name
|
853
|
+
def initialize pos, name
|
854
|
+
super(pos)
|
813
855
|
@name = name
|
814
856
|
end
|
815
857
|
|
@@ -830,7 +872,8 @@ module TinyGQL
|
|
830
872
|
class TypeSystemDirectiveLocation < Node
|
831
873
|
attr_reader :name
|
832
874
|
|
833
|
-
def initialize name
|
875
|
+
def initialize pos, name
|
876
|
+
super(pos)
|
834
877
|
@name = name
|
835
878
|
end
|
836
879
|
|
@@ -851,7 +894,8 @@ module TinyGQL
|
|
851
894
|
class DirectiveDefinition < Node
|
852
895
|
attr_reader :description, :name, :arguments_definition, :directive_locations
|
853
896
|
|
854
|
-
def initialize description, name, arguments_definition, directive_locations
|
897
|
+
def initialize pos, description, name, arguments_definition, directive_locations
|
898
|
+
super(pos)
|
855
899
|
@description = description
|
856
900
|
@name = name
|
857
901
|
@arguments_definition = arguments_definition
|
@@ -875,7 +919,8 @@ module TinyGQL
|
|
875
919
|
class ScalarTypeExtension < Node
|
876
920
|
attr_reader :name, :directives
|
877
921
|
|
878
|
-
def initialize name, directives
|
922
|
+
def initialize pos, name, directives
|
923
|
+
super(pos)
|
879
924
|
@name = name
|
880
925
|
@directives = directives
|
881
926
|
end
|
@@ -897,7 +942,8 @@ module TinyGQL
|
|
897
942
|
class InterfaceTypeExtension < Node
|
898
943
|
attr_reader :name, :implements_interfaces, :directives, :fields_definition
|
899
944
|
|
900
|
-
def initialize name, implements_interfaces, directives, fields_definition
|
945
|
+
def initialize pos, name, implements_interfaces, directives, fields_definition
|
946
|
+
super(pos)
|
901
947
|
@name = name
|
902
948
|
@implements_interfaces = implements_interfaces
|
903
949
|
@directives = directives
|
@@ -921,7 +967,8 @@ module TinyGQL
|
|
921
967
|
class UnionTypeExtension < Node
|
922
968
|
attr_reader :name, :directives, :union_member_types
|
923
969
|
|
924
|
-
def initialize name, directives, union_member_types
|
970
|
+
def initialize pos, name, directives, union_member_types
|
971
|
+
super(pos)
|
925
972
|
@name = name
|
926
973
|
@directives = directives
|
927
974
|
@union_member_types = union_member_types
|
@@ -944,7 +991,8 @@ module TinyGQL
|
|
944
991
|
class EnumTypeExtension < Node
|
945
992
|
attr_reader :name, :directives, :enum_value_definition
|
946
993
|
|
947
|
-
def initialize name, directives, enum_value_definition
|
994
|
+
def initialize pos, name, directives, enum_value_definition
|
995
|
+
super(pos)
|
948
996
|
@name = name
|
949
997
|
@directives = directives
|
950
998
|
@enum_value_definition = enum_value_definition
|
@@ -967,7 +1015,8 @@ module TinyGQL
|
|
967
1015
|
class InputObjectTypeExtension < Node
|
968
1016
|
attr_reader :name, :directives, :input_fields_definition
|
969
1017
|
|
970
|
-
def initialize name, directives, input_fields_definition
|
1018
|
+
def initialize pos, name, directives, input_fields_definition
|
1019
|
+
super(pos)
|
971
1020
|
@name = name
|
972
1021
|
@directives = directives
|
973
1022
|
@input_fields_definition = input_fields_definition
|
data/lib/tinygql/nodes.rb.erb
CHANGED
@@ -3,8 +3,20 @@ module TinyGQL
|
|
3
3
|
class Node
|
4
4
|
include Enumerable
|
5
5
|
|
6
|
+
# `start` is the start position of this node in the source document
|
7
|
+
attr_reader :start
|
8
|
+
|
9
|
+
def initialize start
|
10
|
+
@start = start
|
11
|
+
end
|
12
|
+
|
13
|
+
# Return the line of this node given `doc`
|
14
|
+
def line doc
|
15
|
+
doc[0, @start].count("\n") + 1
|
16
|
+
end
|
17
|
+
|
6
18
|
<%- nodes.each do |node| -%>
|
7
|
-
|
19
|
+
def <%= node.human_name %>?; false; end
|
8
20
|
<%- end -%>
|
9
21
|
def each(&blk)
|
10
22
|
yield self
|
@@ -17,7 +29,8 @@ module TinyGQL
|
|
17
29
|
<%- if node.fields.any? -%>
|
18
30
|
attr_reader <%= node.fields.map { |v| ":" + v.name }.join(", ") %>
|
19
31
|
|
20
|
-
def initialize <%= node.fields.map(&:name).join(", ") %>
|
32
|
+
def initialize <%= (["pos"] + node.fields.map(&:name)).join(", ") %>
|
33
|
+
super(pos)
|
21
34
|
<%- node.fields.each do |field| -%>
|
22
35
|
@<%= field.name %> = <%= field.name %>
|
23
36
|
<%- end -%>
|