graphql 2.0.13 → 2.3.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (228) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/graphql/install/mutation_root_generator.rb +2 -2
  3. data/lib/generators/graphql/install/templates/base_mutation.erb +2 -0
  4. data/lib/generators/graphql/install/templates/mutation_type.erb +2 -0
  5. data/lib/generators/graphql/install_generator.rb +3 -0
  6. data/lib/generators/graphql/mutation_delete_generator.rb +1 -1
  7. data/lib/generators/graphql/mutation_update_generator.rb +1 -1
  8. data/lib/generators/graphql/relay.rb +18 -1
  9. data/lib/generators/graphql/templates/base_argument.erb +2 -0
  10. data/lib/generators/graphql/templates/base_connection.erb +2 -0
  11. data/lib/generators/graphql/templates/base_edge.erb +2 -0
  12. data/lib/generators/graphql/templates/base_enum.erb +2 -0
  13. data/lib/generators/graphql/templates/base_field.erb +2 -0
  14. data/lib/generators/graphql/templates/base_input_object.erb +2 -0
  15. data/lib/generators/graphql/templates/base_interface.erb +2 -0
  16. data/lib/generators/graphql/templates/base_object.erb +2 -0
  17. data/lib/generators/graphql/templates/base_resolver.erb +6 -0
  18. data/lib/generators/graphql/templates/base_scalar.erb +2 -0
  19. data/lib/generators/graphql/templates/base_union.erb +2 -0
  20. data/lib/generators/graphql/templates/graphql_controller.erb +2 -0
  21. data/lib/generators/graphql/templates/loader.erb +2 -0
  22. data/lib/generators/graphql/templates/mutation.erb +2 -0
  23. data/lib/generators/graphql/templates/node_type.erb +2 -0
  24. data/lib/generators/graphql/templates/query_type.erb +2 -0
  25. data/lib/generators/graphql/templates/schema.erb +8 -0
  26. data/lib/graphql/analysis/analyzer.rb +89 -0
  27. data/lib/graphql/analysis/field_usage.rb +82 -0
  28. data/lib/graphql/analysis/max_query_complexity.rb +20 -0
  29. data/lib/graphql/analysis/max_query_depth.rb +20 -0
  30. data/lib/graphql/analysis/query_complexity.rb +183 -0
  31. data/lib/graphql/analysis/query_depth.rb +58 -0
  32. data/lib/graphql/analysis/visitor.rb +283 -0
  33. data/lib/graphql/analysis.rb +92 -1
  34. data/lib/graphql/backtrace/inspect_result.rb +0 -12
  35. data/lib/graphql/backtrace/table.rb +2 -2
  36. data/lib/graphql/backtrace/trace.rb +93 -0
  37. data/lib/graphql/backtrace/tracer.rb +1 -1
  38. data/lib/graphql/backtrace.rb +2 -1
  39. data/lib/graphql/coercion_error.rb +1 -9
  40. data/lib/graphql/dataloader/async_dataloader.rb +88 -0
  41. data/lib/graphql/dataloader/null_dataloader.rb +1 -1
  42. data/lib/graphql/dataloader/request.rb +5 -0
  43. data/lib/graphql/dataloader/source.rb +89 -45
  44. data/lib/graphql/dataloader.rb +115 -142
  45. data/lib/graphql/duration_encoding_error.rb +16 -0
  46. data/lib/graphql/execution/interpreter/argument_value.rb +5 -1
  47. data/lib/graphql/execution/interpreter/arguments.rb +1 -1
  48. data/lib/graphql/execution/interpreter/arguments_cache.rb +33 -33
  49. data/lib/graphql/execution/interpreter/resolve.rb +19 -0
  50. data/lib/graphql/execution/interpreter/runtime/graphql_result.rb +175 -0
  51. data/lib/graphql/execution/interpreter/runtime.rb +331 -455
  52. data/lib/graphql/execution/interpreter.rb +125 -61
  53. data/lib/graphql/execution/lazy.rb +6 -12
  54. data/lib/graphql/execution/lookahead.rb +124 -46
  55. data/lib/graphql/execution/multiplex.rb +3 -117
  56. data/lib/graphql/execution.rb +0 -1
  57. data/lib/graphql/introspection/directive_type.rb +3 -3
  58. data/lib/graphql/introspection/dynamic_fields.rb +1 -1
  59. data/lib/graphql/introspection/entry_points.rb +11 -5
  60. data/lib/graphql/introspection/field_type.rb +2 -2
  61. data/lib/graphql/introspection/schema_type.rb +10 -13
  62. data/lib/graphql/introspection/type_type.rb +17 -10
  63. data/lib/graphql/introspection.rb +3 -2
  64. data/lib/graphql/language/block_string.rb +34 -18
  65. data/lib/graphql/language/definition_slice.rb +1 -1
  66. data/lib/graphql/language/document_from_schema_definition.rb +75 -59
  67. data/lib/graphql/language/lexer.rb +358 -1506
  68. data/lib/graphql/language/nodes.rb +166 -93
  69. data/lib/graphql/language/parser.rb +795 -1953
  70. data/lib/graphql/language/printer.rb +340 -160
  71. data/lib/graphql/language/sanitized_printer.rb +21 -23
  72. data/lib/graphql/language/static_visitor.rb +167 -0
  73. data/lib/graphql/language/visitor.rb +188 -141
  74. data/lib/graphql/language.rb +61 -1
  75. data/lib/graphql/load_application_object_failed_error.rb +5 -1
  76. data/lib/graphql/pagination/active_record_relation_connection.rb +0 -8
  77. data/lib/graphql/pagination/array_connection.rb +6 -6
  78. data/lib/graphql/pagination/connection.rb +33 -6
  79. data/lib/graphql/pagination/mongoid_relation_connection.rb +1 -2
  80. data/lib/graphql/query/context/scoped_context.rb +101 -0
  81. data/lib/graphql/query/context.rb +117 -112
  82. data/lib/graphql/query/null_context.rb +12 -25
  83. data/lib/graphql/query/validation_pipeline.rb +6 -5
  84. data/lib/graphql/query/variables.rb +3 -3
  85. data/lib/graphql/query.rb +86 -30
  86. data/lib/graphql/railtie.rb +9 -6
  87. data/lib/graphql/rake_task.rb +29 -11
  88. data/lib/graphql/rubocop/graphql/base_cop.rb +1 -1
  89. data/lib/graphql/schema/addition.rb +59 -23
  90. data/lib/graphql/schema/always_visible.rb +11 -0
  91. data/lib/graphql/schema/argument.rb +55 -26
  92. data/lib/graphql/schema/base_64_encoder.rb +3 -5
  93. data/lib/graphql/schema/build_from_definition.rb +56 -32
  94. data/lib/graphql/schema/directive/one_of.rb +24 -0
  95. data/lib/graphql/schema/directive/specified_by.rb +14 -0
  96. data/lib/graphql/schema/directive/transform.rb +1 -1
  97. data/lib/graphql/schema/directive.rb +15 -3
  98. data/lib/graphql/schema/enum.rb +35 -24
  99. data/lib/graphql/schema/enum_value.rb +2 -3
  100. data/lib/graphql/schema/field/connection_extension.rb +2 -16
  101. data/lib/graphql/schema/field/scope_extension.rb +8 -1
  102. data/lib/graphql/schema/field.rb +147 -107
  103. data/lib/graphql/schema/field_extension.rb +1 -4
  104. data/lib/graphql/schema/find_inherited_value.rb +2 -7
  105. data/lib/graphql/schema/has_single_input_argument.rb +158 -0
  106. data/lib/graphql/schema/input_object.rb +47 -11
  107. data/lib/graphql/schema/interface.rb +15 -21
  108. data/lib/graphql/schema/introspection_system.rb +7 -17
  109. data/lib/graphql/schema/late_bound_type.rb +10 -0
  110. data/lib/graphql/schema/list.rb +2 -2
  111. data/lib/graphql/schema/loader.rb +2 -3
  112. data/lib/graphql/schema/member/base_dsl_methods.rb +18 -14
  113. data/lib/graphql/schema/member/build_type.rb +11 -3
  114. data/lib/graphql/schema/member/has_arguments.rb +170 -130
  115. data/lib/graphql/schema/member/has_ast_node.rb +12 -0
  116. data/lib/graphql/schema/member/has_deprecation_reason.rb +3 -4
  117. data/lib/graphql/schema/member/has_directives.rb +81 -61
  118. data/lib/graphql/schema/member/has_fields.rb +100 -38
  119. data/lib/graphql/schema/member/has_interfaces.rb +65 -10
  120. data/lib/graphql/schema/member/has_unresolved_type_error.rb +5 -1
  121. data/lib/graphql/schema/member/has_validators.rb +32 -6
  122. data/lib/graphql/schema/member/relay_shortcuts.rb +19 -0
  123. data/lib/graphql/schema/member/scoped.rb +19 -0
  124. data/lib/graphql/schema/member/type_system_helpers.rb +16 -0
  125. data/lib/graphql/schema/member/validates_input.rb +3 -3
  126. data/lib/graphql/schema/mutation.rb +7 -0
  127. data/lib/graphql/schema/object.rb +16 -5
  128. data/lib/graphql/schema/printer.rb +11 -8
  129. data/lib/graphql/schema/relay_classic_mutation.rb +7 -129
  130. data/lib/graphql/schema/resolver/has_payload_type.rb +9 -9
  131. data/lib/graphql/schema/resolver.rb +47 -32
  132. data/lib/graphql/schema/scalar.rb +3 -3
  133. data/lib/graphql/schema/subscription.rb +11 -4
  134. data/lib/graphql/schema/subset.rb +397 -0
  135. data/lib/graphql/schema/timeout.rb +25 -29
  136. data/lib/graphql/schema/type_expression.rb +2 -2
  137. data/lib/graphql/schema/type_membership.rb +3 -0
  138. data/lib/graphql/schema/union.rb +11 -2
  139. data/lib/graphql/schema/unique_within_type.rb +1 -1
  140. data/lib/graphql/schema/validator/all_validator.rb +60 -0
  141. data/lib/graphql/schema/validator.rb +4 -2
  142. data/lib/graphql/schema/warden.rb +238 -93
  143. data/lib/graphql/schema.rb +498 -103
  144. data/lib/graphql/static_validation/all_rules.rb +2 -1
  145. data/lib/graphql/static_validation/base_visitor.rb +7 -6
  146. data/lib/graphql/static_validation/definition_dependencies.rb +7 -1
  147. data/lib/graphql/static_validation/literal_validator.rb +24 -7
  148. data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +1 -1
  149. data/lib/graphql/static_validation/rules/arguments_are_defined.rb +1 -1
  150. data/lib/graphql/static_validation/rules/directives_are_defined.rb +1 -2
  151. data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +1 -1
  152. data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +12 -4
  153. data/lib/graphql/static_validation/rules/fields_will_merge.rb +10 -10
  154. data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +3 -3
  155. data/lib/graphql/static_validation/rules/fragment_types_exist.rb +1 -1
  156. data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +1 -1
  157. data/lib/graphql/static_validation/rules/mutation_root_exists.rb +1 -1
  158. data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid.rb +66 -0
  159. data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid_error.rb +29 -0
  160. data/lib/graphql/static_validation/rules/query_root_exists.rb +1 -1
  161. data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +4 -4
  162. data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +5 -5
  163. data/lib/graphql/static_validation/rules/subscription_root_exists.rb +1 -1
  164. data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +18 -27
  165. data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +1 -1
  166. data/lib/graphql/static_validation/rules/variables_are_input_types.rb +1 -1
  167. data/lib/graphql/static_validation/validation_context.rb +5 -5
  168. data/lib/graphql/static_validation/validator.rb +4 -1
  169. data/lib/graphql/static_validation.rb +0 -1
  170. data/lib/graphql/subscriptions/action_cable_subscriptions.rb +11 -4
  171. data/lib/graphql/subscriptions/broadcast_analyzer.rb +11 -5
  172. data/lib/graphql/subscriptions/event.rb +11 -10
  173. data/lib/graphql/subscriptions/serialize.rb +2 -0
  174. data/lib/graphql/subscriptions.rb +20 -13
  175. data/lib/graphql/testing/helpers.rb +151 -0
  176. data/lib/graphql/testing.rb +2 -0
  177. data/lib/graphql/tracing/active_support_notifications_trace.rb +16 -0
  178. data/lib/graphql/tracing/appoptics_trace.rb +251 -0
  179. data/lib/graphql/tracing/appoptics_tracing.rb +2 -2
  180. data/lib/graphql/tracing/appsignal_trace.rb +77 -0
  181. data/lib/graphql/tracing/data_dog_trace.rb +183 -0
  182. data/lib/graphql/tracing/data_dog_tracing.rb +9 -21
  183. data/lib/graphql/{execution/instrumentation.rb → tracing/legacy_hooks_trace.rb} +10 -28
  184. data/lib/graphql/tracing/legacy_trace.rb +69 -0
  185. data/lib/graphql/tracing/new_relic_trace.rb +75 -0
  186. data/lib/graphql/tracing/notifications_trace.rb +45 -0
  187. data/lib/graphql/tracing/platform_trace.rb +118 -0
  188. data/lib/graphql/tracing/platform_tracing.rb +17 -3
  189. data/lib/graphql/tracing/{prometheus_tracing → prometheus_trace}/graphql_collector.rb +4 -2
  190. data/lib/graphql/tracing/prometheus_trace.rb +89 -0
  191. data/lib/graphql/tracing/prometheus_tracing.rb +3 -3
  192. data/lib/graphql/tracing/scout_trace.rb +72 -0
  193. data/lib/graphql/tracing/sentry_trace.rb +112 -0
  194. data/lib/graphql/tracing/statsd_trace.rb +56 -0
  195. data/lib/graphql/tracing/trace.rb +76 -0
  196. data/lib/graphql/tracing.rb +20 -40
  197. data/lib/graphql/type_kinds.rb +7 -4
  198. data/lib/graphql/types/iso_8601_duration.rb +77 -0
  199. data/lib/graphql/types/relay/base_connection.rb +1 -1
  200. data/lib/graphql/types/relay/connection_behaviors.rb +68 -6
  201. data/lib/graphql/types/relay/edge_behaviors.rb +33 -5
  202. data/lib/graphql/types/relay/node_behaviors.rb +8 -2
  203. data/lib/graphql/types/relay/page_info_behaviors.rb +11 -2
  204. data/lib/graphql/types/relay.rb +0 -1
  205. data/lib/graphql/types/string.rb +1 -1
  206. data/lib/graphql/types.rb +1 -0
  207. data/lib/graphql/version.rb +1 -1
  208. data/lib/graphql.rb +27 -20
  209. data/readme.md +13 -3
  210. metadata +96 -47
  211. data/lib/graphql/analysis/ast/analyzer.rb +0 -84
  212. data/lib/graphql/analysis/ast/field_usage.rb +0 -57
  213. data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -22
  214. data/lib/graphql/analysis/ast/max_query_depth.rb +0 -22
  215. data/lib/graphql/analysis/ast/query_complexity.rb +0 -230
  216. data/lib/graphql/analysis/ast/query_depth.rb +0 -55
  217. data/lib/graphql/analysis/ast/visitor.rb +0 -269
  218. data/lib/graphql/analysis/ast.rb +0 -81
  219. data/lib/graphql/deprecation.rb +0 -9
  220. data/lib/graphql/filter.rb +0 -53
  221. data/lib/graphql/language/lexer.rl +0 -280
  222. data/lib/graphql/language/parser.y +0 -554
  223. data/lib/graphql/language/token.rb +0 -34
  224. data/lib/graphql/schema/base_64_bp.rb +0 -26
  225. data/lib/graphql/schema/invalid_type_error.rb +0 -7
  226. data/lib/graphql/static_validation/type_stack.rb +0 -216
  227. data/lib/graphql/subscriptions/instrumentation.rb +0 -28
  228. data/lib/graphql/types/relay/default_relay.rb +0 -21
@@ -1,1509 +1,361 @@
1
1
  # frozen_string_literal: true
2
-
3
2
  module GraphQL
4
- module Language
5
- module Lexer
6
- def self.tokenize(query_string)
7
- run_lexer(query_string)
8
- end
9
-
10
- # Replace any escaped unicode or whitespace with the _actual_ characters
11
- # To avoid allocating more strings, this modifies the string passed into it
12
- def self.replace_escaped_characters_in_place(raw_string)
13
- raw_string.gsub!(ESCAPES, ESCAPES_REPLACE)
14
- raw_string.gsub!(UTF_8) do |_matched_str|
15
- codepoint_1 = ($1 || $2).to_i(16)
16
- codepoint_2 = $3
17
-
18
- if codepoint_2
19
- codepoint_2 = codepoint_2.to_i(16)
20
- if (codepoint_1 >= 0xD800 && codepoint_1 <= 0xDBFF) && # leading surrogate
21
- (codepoint_2 >= 0xDC00 && codepoint_2 <= 0xDFFF) # trailing surrogate
22
- # A surrogate pair
23
- combined = ((codepoint_1 - 0xD800) * 0x400) + (codepoint_2 - 0xDC00) + 0x10000
24
- [combined].pack('U'.freeze)
25
- else
26
- # Two separate code points
27
- [codepoint_1].pack('U'.freeze) + [codepoint_2].pack('U'.freeze)
28
- end
29
- else
30
- [codepoint_1].pack('U'.freeze)
31
- end
32
- end
33
- nil
34
- end
35
-
36
- private
37
-
38
- class << self
39
- attr_accessor :_graphql_lexer_trans_keys
40
- private :_graphql_lexer_trans_keys, :_graphql_lexer_trans_keys=
41
- end
42
- self._graphql_lexer_trans_keys = [
43
- 1, 0, 4, 22, 4, 43, 14, 47, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 49, 4, 22, 4, 4, 4, 4, 4, 22, 4, 4, 4, 4, 14, 15, 14, 15, 10, 15, 12, 12, 4, 22, 4, 43, 14, 47, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 49, 0, 49, 0, 0, 4, 22, 4, 4, 4, 4, 4, 4, 4, 22, 4, 4, 4, 4, 1, 1, 14, 15, 10, 29, 14, 15, 10, 29, 10, 29, 12, 12, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 14, 46, 4, 4, 0 ,
44
- ]
45
-
46
- class << self
47
- attr_accessor :_graphql_lexer_char_class
48
- private :_graphql_lexer_char_class, :_graphql_lexer_char_class=
49
- end
50
- self._graphql_lexer_char_class = [
51
- 0, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 3, 4, 5, 6, 2, 7, 2, 8, 9, 2, 10, 0, 11, 12, 13, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 2, 2, 17, 2, 2, 18, 19, 19, 19, 19, 20, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 21, 22, 23, 2, 24, 2, 25, 26, 27, 28, 29, 30, 31, 32, 33, 19, 19, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 19, 45, 46, 19, 47, 48, 49, 0 ,
52
- ]
53
-
54
- class << self
55
- attr_accessor :_graphql_lexer_index_offsets
56
- private :_graphql_lexer_index_offsets, :_graphql_lexer_index_offsets=
57
- end
58
- self._graphql_lexer_index_offsets = [
59
- 0, 0, 19, 59, 93, 126, 159, 192, 225, 258, 291, 324, 360, 379, 380, 381, 400, 401, 402, 404, 406, 412, 413, 432, 472, 506, 539, 572, 605, 638, 671, 704, 737, 773, 823, 824, 843, 844, 845, 846, 865, 866, 867, 868, 870, 890, 892, 912, 932, 933, 966, 999, 1032, 1065, 1098, 1131, 1164, 1197, 1230, 1263, 1296, 1329, 1362, 1395, 1428, 1461, 1494, 1527, 1560, 1593, 1626, 1659, 1692, 1725, 1758, 1791, 1824, 1857, 1890, 1923, 1956, 1989, 2022, 2055, 2088, 2121, 2154, 2187, 2220, 2253, 2286, 2319, 2352, 2385, 2418, 2451, 2484, 2517, 2550, 2583, 2616, 2649, 2682, 2715, 2748, 2781, 2814, 2847, 2880, 2913, 2946, 2979, 3012, 3045, 3078, 3111, 3144, 3177, 3210, 3243, 3276, 3309, 3342, 3375, 3408, 3441, 3474, 3507, 3540, 3573, 3606, 3639, 3672, 3705, 3738, 3771, 3804, 3837, 3870, 3903, 3936, 3969, 4002, 4035, 4068, 0 ,
60
- ]
61
-
62
- class << self
63
- attr_accessor :_graphql_lexer_indicies
64
- private :_graphql_lexer_indicies, :_graphql_lexer_indicies=
65
- end
66
- self._graphql_lexer_indicies = [
67
- 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 4, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0, 0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 0, 0, 0, 10, 10, 0, 0, 0, 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 0, 0, 0, 11, 11, 0, 0, 0, 0, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 0, 0, 0, 12, 12, 0, 0, 0, 0, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 0, 0, 0, 12, 12, 0, 0, 0, 0, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 0, 0, 1, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 16, 17, 18, 19, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 16, 20, 21, 22, 22, 24, 24, 25, 25, 13, 13, 22, 22, 26, 28, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 29, 27, 30, 30, 30, 30, 30, 30, 30, 30, 27, 30, 30, 30, 30, 30, 30, 30, 30, 27, 30, 30, 30, 27, 30, 30, 30, 27, 30, 30, 30, 30, 30, 27, 30, 30, 30, 27, 30, 27, 31, 32, 32, 30, 30, 30, 32, 32, 30, 30, 30, 30, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 34, 34, 30, 30, 30, 34, 34, 30, 30, 30, 30, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 35, 35, 30, 30, 30, 35, 35, 30, 30, 30, 30, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 27, 27, 30, 30, 30, 27, 27, 30, 30, 30, 30, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 36, 36, 30, 30, 30, 36, 36, 30, 30, 30, 30, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 37, 37, 30, 30, 30, 37, 37, 30, 30, 30, 30, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 38, 38, 30, 30, 30, 38, 38, 30, 30, 30, 30, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 39, 39, 30, 30, 30, 39, 39, 30, 30, 30, 30, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 30, 30, 30, 39, 39, 30, 30, 30, 30, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 30, 30, 27, 41, 42, 40, 43, 44, 45, 46, 47, 48, 49, 40, 50, 51, 40, 52, 53, 54, 55, 56, 57, 57, 58, 40, 59, 57, 57, 57, 57, 60, 61, 62, 57, 57, 63, 57, 64, 65, 66, 57, 67, 68, 69, 70, 71, 57, 57, 57, 72, 73, 74, 41, 77, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 14, 80, 81, 82, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 16, 83, 18, 84, 52, 53, 25, 25, 86, 85, 22, 22, 85, 85, 85, 85, 87, 85, 85, 85, 85, 85, 85, 85, 85, 87, 22, 22, 25, 25, 88, 88, 24, 24, 88, 88, 88, 88, 87, 88, 88, 88, 88, 88, 88, 88, 88, 87, 25, 25, 86, 85, 53, 53, 85, 85, 85, 85, 87, 85, 85, 85, 85, 85, 85, 85, 85, 87, 89, 57, 57, 13, 13, 13, 57, 57, 13, 13, 13, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 91, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 92, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 93, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 94, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 95, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 96, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 97, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 98, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 99, 57, 57, 57, 57, 57, 57, 57, 57, 100, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 101, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 102, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 103, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 104, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 105, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 106, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 107, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 108, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 109, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 110, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 111, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 112, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 113, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 114, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 115, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 116, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 117, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 118, 119, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 120, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 121, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 122, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 123, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 124, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 125, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 126, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 127, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 128, 57, 57, 57, 129, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 130, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 131, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 132, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 133, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 134, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 135, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 136, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 137, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 138, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 139, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 140, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 141, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 142, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 143, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 144, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 145, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 146, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 147, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 148, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 149, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 150, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 151, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 152, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 153, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 154, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 155, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 156, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 157, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 158, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 159, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 160, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 161, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 162, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 163, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 164, 57, 57, 57, 57, 57, 57, 165, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 166, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 167, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 168, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 169, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 170, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 171, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 172, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 173, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 174, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 175, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 176, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 177, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 178, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 179, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 180, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 181, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 182, 57, 57, 57, 57, 57, 183, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 184, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 185, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 186, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 187, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 188, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 189, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 190, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 90, 90, 90, 57, 57, 90, 90, 90, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 191, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 27, 0 ,
68
- ]
69
-
70
- class << self
71
- attr_accessor :_graphql_lexer_index_defaults
72
- private :_graphql_lexer_index_defaults, :_graphql_lexer_index_defaults=
73
- end
74
- self._graphql_lexer_index_defaults = [
75
- 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 14, 14, 14, 14, 14, 13, 23, 13, 0, 27, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 40, 75, 1, 78, 79, 79, 14, 14, 14, 45, 76, 85, 88, 88, 85, 76, 13, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 30, 0 ,
76
- ]
77
-
78
- class << self
79
- attr_accessor :_graphql_lexer_trans_cond_spaces
80
- private :_graphql_lexer_trans_cond_spaces, :_graphql_lexer_trans_cond_spaces=
81
- end
82
- self._graphql_lexer_trans_cond_spaces = [
83
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0 ,
84
- ]
85
-
86
- class << self
87
- attr_accessor :_graphql_lexer_cond_targs
88
- private :_graphql_lexer_cond_targs, :_graphql_lexer_cond_targs=
89
- end
90
- self._graphql_lexer_cond_targs = [
91
- 33, 1, 33, 2, 3, 4, 7, 5, 6, 8, 9, 10, 11, 33, 12, 13, 15, 14, 37, 16, 17, 39, 45, 33, 46, 18, 33, 22, 144, 23, 0, 24, 25, 28, 26, 27, 29, 30, 31, 32, 33, 34, 33, 33, 35, 42, 33, 33, 33, 33, 43, 48, 44, 47, 33, 33, 33, 49, 33, 33, 50, 58, 65, 75, 93, 100, 103, 104, 108, 117, 135, 140, 33, 33, 33, 33, 33, 36, 33, 33, 38, 33, 40, 41, 33, 33, 19, 20, 33, 21, 33, 51, 52, 53, 54, 55, 56, 57, 49, 59, 61, 60, 49, 62, 63, 64, 49, 66, 69, 67, 68, 49, 70, 71, 72, 73, 74, 49, 76, 84, 77, 78, 79, 80, 81, 82, 83, 49, 85, 87, 86, 49, 88, 89, 90, 91, 92, 49, 94, 95, 96, 97, 98, 99, 49, 101, 102, 49, 49, 105, 106, 107, 49, 109, 110, 111, 112, 113, 114, 115, 116, 49, 118, 125, 119, 122, 120, 121, 49, 123, 124, 49, 126, 127, 128, 129, 130, 131, 132, 133, 134, 49, 136, 138, 137, 49, 139, 49, 141, 142, 143, 49, 0 ,
92
- ]
93
-
94
- class << self
95
- attr_accessor :_graphql_lexer_cond_actions
96
- private :_graphql_lexer_cond_actions, :_graphql_lexer_cond_actions=
97
- end
98
- self._graphql_lexer_cond_actions = [
99
- 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 5, 6, 0, 7, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 12, 13, 14, 0, 15, 16, 17, 18, 0, 14, 19, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 27, 28, 29, 30, 31, 32, 33, 0, 34, 4, 4, 35, 36, 0, 0, 37, 0, 38, 0, 0, 0, 0, 0, 0, 0, 39, 0, 0, 0, 40, 0, 0, 0, 41, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 44, 0, 0, 0, 45, 0, 0, 0, 0, 0, 46, 0, 0, 0, 0, 0, 0, 47, 0, 0, 48, 49, 0, 0, 0, 50, 0, 0, 0, 0, 0, 0, 0, 0, 51, 0, 0, 0, 0, 0, 0, 52, 0, 0, 53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0, 55, 0, 56, 0, 0, 0, 57, 0 ,
100
- ]
101
-
102
- class << self
103
- attr_accessor :_graphql_lexer_to_state_actions
104
- private :_graphql_lexer_to_state_actions, :_graphql_lexer_to_state_actions=
105
- end
106
- self._graphql_lexer_to_state_actions = [
107
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0 ,
108
- ]
109
-
110
- class << self
111
- attr_accessor :_graphql_lexer_from_state_actions
112
- private :_graphql_lexer_from_state_actions, :_graphql_lexer_from_state_actions=
113
- end
114
- self._graphql_lexer_from_state_actions = [
115
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0 ,
116
- ]
117
-
118
- class << self
119
- attr_accessor :_graphql_lexer_eof_trans
120
- private :_graphql_lexer_eof_trans, :_graphql_lexer_eof_trans=
121
- end
122
- self._graphql_lexer_eof_trans = [
123
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 14, 14, 14, 14, 14, 14, 14, 24, 14, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 76, 77, 79, 80, 80, 80, 80, 80, 85, 77, 86, 89, 89, 86, 77, 14, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 0, 0 ,
124
- ]
125
-
126
- class << self
127
- attr_accessor :_graphql_lexer_nfa_targs
128
- private :_graphql_lexer_nfa_targs, :_graphql_lexer_nfa_targs=
129
- end
130
- self._graphql_lexer_nfa_targs = [
131
- 0, 0 ,
132
- ]
133
-
134
- class << self
135
- attr_accessor :_graphql_lexer_nfa_offsets
136
- private :_graphql_lexer_nfa_offsets, :_graphql_lexer_nfa_offsets=
137
- end
138
- self._graphql_lexer_nfa_offsets = [
139
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,
140
- ]
141
-
142
- class << self
143
- attr_accessor :_graphql_lexer_nfa_push_actions
144
- private :_graphql_lexer_nfa_push_actions, :_graphql_lexer_nfa_push_actions=
145
- end
146
- self._graphql_lexer_nfa_push_actions = [
147
- 0, 0 ,
148
- ]
149
-
150
- class << self
151
- attr_accessor :_graphql_lexer_nfa_pop_trans
152
- private :_graphql_lexer_nfa_pop_trans, :_graphql_lexer_nfa_pop_trans=
153
- end
154
- self._graphql_lexer_nfa_pop_trans = [
155
- 0, 0 ,
156
- ]
157
-
158
- class << self
159
- attr_accessor :graphql_lexer_start
160
- end
161
- self.graphql_lexer_start = 33;
162
-
163
- class << self
164
- attr_accessor :graphql_lexer_first_final
165
- end
166
- self.graphql_lexer_first_final = 33;
167
-
168
- class << self
169
- attr_accessor :graphql_lexer_error
170
- end
171
- self.graphql_lexer_error = 0;
172
-
173
- class << self
174
- attr_accessor :graphql_lexer_en_str
175
- end
176
- self.graphql_lexer_en_str = 144;
177
-
178
- class << self
179
- attr_accessor :graphql_lexer_en_main
180
- end
181
- self.graphql_lexer_en_main = 33;
182
-
183
- def self.run_lexer(query_string)
184
- data = query_string.unpack(PACK_DIRECTIVE)
185
- eof = data.length
186
-
187
- # Since `Lexer` is a module, store all lexer state
188
- # in this local variable:
189
- meta = {
190
- line: 1,
191
- col: 1,
192
- data: data,
193
- tokens: [],
194
- previous_token: nil,
195
- }
196
-
197
- p ||= 0
198
- pe ||= data.length
199
-
200
- begin
201
- cs = graphql_lexer_start;
202
- ts = 0;
203
- te = 0;
204
- act = 0;
205
-
206
- end
207
- begin
208
- _trans = 0;
209
- _have = 0;
210
- _cont = 1;
211
- _keys = 0;
212
- _inds = 0;
213
- while ( _cont == 1 )
214
- begin
215
- if ( cs == 0 )
216
- _cont = 0;
217
-
218
- end
219
- _have = 0;
220
- if ( p == pe )
221
- begin
222
- if ( p == eof )
223
- begin
224
- if ( _graphql_lexer_eof_trans[cs] > 0 )
225
- begin
226
- _trans = _graphql_lexer_eof_trans[cs] - 1;
227
- _have = 1;
228
-
229
- end
230
-
231
- end
232
- if ( _have == 0 )
233
- begin
234
-
235
- end
236
-
237
- end
238
-
239
- end
240
-
241
- end
242
- if ( _have == 0 )
243
- _cont = 0;
244
-
245
- end
246
-
247
- end
248
-
249
- end
250
- if ( _cont == 1 )
251
- begin
252
- if ( _have == 0 )
253
- begin
254
- case _graphql_lexer_from_state_actions[cs]
255
- when -2 then
256
- begin
257
- end
258
- when 10 then
259
- begin
260
- begin
261
- begin
262
- ts = p;
263
-
264
- end
265
-
266
- end
267
-
268
-
269
- end
270
- end
271
- _keys = (cs<<1) ;
272
- _inds = _graphql_lexer_index_offsets[cs] ;
273
- if ( ( data[p ].ord) <= 125 && ( data[p ].ord) >= 9 )
274
- begin
275
- _ic = _graphql_lexer_char_class[( data[p ].ord) - 9];
276
- if ( _ic <= _graphql_lexer_trans_keys[_keys+1 ]&& _ic >= _graphql_lexer_trans_keys[_keys ] )
277
- _trans = _graphql_lexer_indicies[_inds + ( _ic - _graphql_lexer_trans_keys[_keys ]) ];
278
-
279
- else
280
- _trans = _graphql_lexer_index_defaults[cs];
281
-
282
- end
283
-
284
- end
285
-
286
- else
287
- begin
288
- _trans = _graphql_lexer_index_defaults[cs];
289
-
290
- end
291
-
292
- end
293
-
294
- end
295
-
296
- end
297
- if ( _cont == 1 )
298
- begin
299
- cs = _graphql_lexer_cond_targs[_trans];
300
- case _graphql_lexer_cond_actions[_trans]
301
- when -2 then
302
- begin
303
- end
304
- when 14 then
305
- begin
306
- begin
307
- begin
308
- te = p+1;
309
-
310
- end
311
-
312
- end
313
-
314
- end
315
- when 8 then
316
- begin
317
- begin
318
- begin
319
- te = p+1;
320
- begin
321
- emit_string(ts, te, meta, block: false)
322
- end
323
-
324
- end
325
-
326
- end
327
-
328
- end
329
- when 28 then
330
- begin
331
- begin
332
- begin
333
- te = p+1;
334
- begin
335
- emit(:RCURLY, ts, te, meta, "}")
336
- end
337
-
338
- end
339
-
340
- end
341
-
342
- end
343
- when 26 then
344
- begin
345
- begin
346
- begin
347
- te = p+1;
348
- begin
349
- emit(:LCURLY, ts, te, meta, "{")
350
- end
351
-
352
- end
353
-
354
- end
355
-
356
- end
357
- when 18 then
358
- begin
359
- begin
360
- begin
361
- te = p+1;
362
- begin
363
- emit(:RPAREN, ts, te, meta, ")")
364
- end
365
-
366
- end
367
-
368
- end
369
-
370
- end
371
- when 17 then
372
- begin
373
- begin
374
- begin
375
- te = p+1;
376
- begin
377
- emit(:LPAREN, ts, te, meta, "(")
378
- end
379
-
380
- end
381
-
382
- end
383
-
384
- end
385
- when 25 then
386
- begin
387
- begin
388
- begin
389
- te = p+1;
390
- begin
391
- emit(:RBRACKET, ts, te, meta, "]")
392
- end
393
-
394
- end
395
-
396
- end
397
-
398
- end
399
- when 24 then
400
- begin
401
- begin
402
- begin
403
- te = p+1;
404
- begin
405
- emit(:LBRACKET, ts, te, meta, "[")
406
- end
407
-
408
- end
409
-
410
- end
411
-
412
- end
413
- when 20 then
414
- begin
415
- begin
416
- begin
417
- te = p+1;
418
- begin
419
- emit(:COLON, ts, te, meta, ":")
420
- end
421
-
422
- end
423
-
424
- end
425
-
426
- end
427
- when 2 then
428
- begin
429
- begin
430
- begin
431
- te = p+1;
432
- begin
433
- emit_string(ts, te, meta, block: false)
434
- end
435
-
436
- end
437
-
438
- end
439
-
440
- end
441
- when 34 then
442
- begin
443
- begin
444
- begin
445
- te = p+1;
446
- begin
447
- emit_string(ts, te, meta, block: true)
448
- end
449
-
450
- end
451
-
452
- end
453
-
454
- end
455
- when 15 then
456
- begin
457
- begin
458
- begin
459
- te = p+1;
460
- begin
461
- emit(:VAR_SIGN, ts, te, meta, "$")
462
- end
463
-
464
- end
465
-
466
- end
467
-
468
- end
469
- when 22 then
470
- begin
471
- begin
472
- begin
473
- te = p+1;
474
- begin
475
- emit(:DIR_SIGN, ts, te, meta, "@")
476
- end
477
-
478
- end
479
-
480
- end
481
-
482
- end
483
- when 7 then
484
- begin
485
- begin
486
- begin
487
- te = p+1;
488
- begin
489
- emit(:ELLIPSIS, ts, te, meta, "...")
490
- end
491
-
492
- end
493
-
494
- end
495
-
496
- end
497
- when 21 then
498
- begin
499
- begin
500
- begin
501
- te = p+1;
502
- begin
503
- emit(:EQUALS, ts, te, meta, "=")
504
- end
505
-
506
- end
507
-
508
- end
509
-
510
- end
511
- when 13 then
512
- begin
513
- begin
514
- begin
515
- te = p+1;
516
- begin
517
- emit(:BANG, ts, te, meta, "!")
518
- end
519
-
520
- end
521
-
522
- end
523
-
524
- end
525
- when 27 then
526
- begin
527
- begin
528
- begin
529
- te = p+1;
530
- begin
531
- emit(:PIPE, ts, te, meta, "|")
532
- end
533
-
534
- end
535
-
536
- end
537
-
538
- end
539
- when 16 then
540
- begin
541
- begin
542
- begin
543
- te = p+1;
544
- begin
545
- emit(:AMP, ts, te, meta, "&")
546
- end
547
-
548
- end
549
-
550
- end
551
-
552
- end
553
- when 12 then
554
- begin
555
- begin
556
- begin
557
- te = p+1;
558
- begin
559
- meta[:line] += 1
560
- meta[:col] = 1
561
-
562
- end
563
-
564
- end
565
-
566
- end
567
-
568
- end
569
- when 11 then
570
- begin
571
- begin
572
- begin
573
- te = p+1;
574
- begin
575
- emit(:UNKNOWN_CHAR, ts, te, meta)
576
- end
577
-
578
- end
579
-
580
- end
581
-
582
- end
583
- when 36 then
584
- begin
585
- begin
586
- begin
587
- te = p;
588
- p = p - 1;
589
- begin
590
- emit(:INT, ts, te, meta)
591
- end
592
-
593
- end
594
-
595
- end
596
-
597
- end
598
- when 37 then
599
- begin
600
- begin
601
- begin
602
- te = p;
603
- p = p - 1;
604
- begin
605
- emit(:FLOAT, ts, te, meta)
606
- end
607
-
608
- end
609
-
610
- end
611
-
612
- end
613
- when 32 then
614
- begin
615
- begin
616
- begin
617
- te = p;
618
- p = p - 1;
619
- begin
620
- emit_string(ts, te, meta, block: false)
621
- end
622
-
623
- end
624
-
625
- end
626
-
627
- end
628
- when 33 then
629
- begin
630
- begin
631
- begin
632
- te = p;
633
- p = p - 1;
634
- begin
635
- emit_string(ts, te, meta, block: true)
636
- end
637
-
638
- end
639
-
640
- end
641
-
642
- end
643
- when 38 then
644
- begin
645
- begin
646
- begin
647
- te = p;
648
- p = p - 1;
649
- begin
650
- emit(:IDENTIFIER, ts, te, meta)
651
- end
652
-
653
- end
654
-
655
- end
656
-
657
- end
658
- when 35 then
659
- begin
660
- begin
661
- begin
662
- te = p;
663
- p = p - 1;
664
- begin
665
- record_comment(ts, te, meta)
666
- end
667
-
668
- end
669
-
670
- end
671
-
672
- end
673
- when 29 then
674
- begin
675
- begin
676
- begin
677
- te = p;
678
- p = p - 1;
679
- begin
680
- meta[:col] += te - ts
681
- end
682
-
683
- end
684
-
685
- end
686
-
687
- end
688
- when 30 then
689
- begin
690
- begin
691
- begin
692
- te = p;
693
- p = p - 1;
694
- begin
695
- emit(:UNKNOWN_CHAR, ts, te, meta)
696
- end
697
-
698
- end
699
-
700
- end
701
-
702
- end
703
- when 5 then
704
- begin
705
- begin
706
- begin
707
- p = ((te))-1;
708
- begin
709
- emit(:INT, ts, te, meta)
710
- end
711
-
712
- end
713
-
714
- end
715
-
716
- end
717
- when 1 then
718
- begin
719
- begin
720
- begin
721
- p = ((te))-1;
722
- begin
723
- emit(:UNKNOWN_CHAR, ts, te, meta)
724
- end
725
-
726
- end
727
-
728
- end
729
-
730
- end
731
- when 3 then
732
- begin
733
- begin
734
- begin
735
- case act
736
- when -2 then
737
- begin
738
- end
739
- when 2 then
740
- begin
741
- p = ((te))-1;
742
- begin
743
- emit(:INT, ts, te, meta)
744
- end
745
-
746
- end
747
- when 3 then
748
- begin
749
- p = ((te))-1;
750
- begin
751
- emit(:FLOAT, ts, te, meta)
752
- end
753
-
754
- end
755
- when 4 then
756
- begin
757
- p = ((te))-1;
758
- begin
759
- emit(:ON, ts, te, meta, "on")
760
- end
761
-
762
- end
763
- when 5 then
764
- begin
765
- p = ((te))-1;
766
- begin
767
- emit(:FRAGMENT, ts, te, meta, "fragment")
768
- end
769
-
770
- end
771
- when 6 then
772
- begin
773
- p = ((te))-1;
774
- begin
775
- emit(:TRUE, ts, te, meta, "true")
776
- end
777
-
778
- end
779
- when 7 then
780
- begin
781
- p = ((te))-1;
782
- begin
783
- emit(:FALSE, ts, te, meta, "false")
784
- end
785
-
786
- end
787
- when 8 then
788
- begin
789
- p = ((te))-1;
790
- begin
791
- emit(:NULL, ts, te, meta, "null")
792
- end
793
-
794
- end
795
- when 9 then
796
- begin
797
- p = ((te))-1;
798
- begin
799
- emit(:QUERY, ts, te, meta, "query")
800
- end
801
-
802
- end
803
- when 10 then
804
- begin
805
- p = ((te))-1;
806
- begin
807
- emit(:MUTATION, ts, te, meta, "mutation")
808
- end
809
-
810
- end
811
- when 11 then
812
- begin
813
- p = ((te))-1;
814
- begin
815
- emit(:SUBSCRIPTION, ts, te, meta, "subscription")
816
- end
817
-
818
- end
819
- when 12 then
820
- begin
821
- p = ((te))-1;
822
- begin
823
- emit(:SCHEMA, ts, te, meta)
824
- end
825
-
826
- end
827
- when 13 then
828
- begin
829
- p = ((te))-1;
830
- begin
831
- emit(:SCALAR, ts, te, meta)
832
- end
833
-
834
- end
835
- when 14 then
836
- begin
837
- p = ((te))-1;
838
- begin
839
- emit(:TYPE, ts, te, meta)
840
- end
841
-
842
- end
843
- when 15 then
844
- begin
845
- p = ((te))-1;
846
- begin
847
- emit(:EXTEND, ts, te, meta)
848
- end
849
-
850
- end
851
- when 16 then
852
- begin
853
- p = ((te))-1;
854
- begin
855
- emit(:IMPLEMENTS, ts, te, meta)
856
- end
857
-
858
- end
859
- when 17 then
860
- begin
861
- p = ((te))-1;
862
- begin
863
- emit(:INTERFACE, ts, te, meta)
864
- end
865
-
866
- end
867
- when 18 then
868
- begin
869
- p = ((te))-1;
870
- begin
871
- emit(:UNION, ts, te, meta)
872
- end
873
-
874
- end
875
- when 19 then
876
- begin
877
- p = ((te))-1;
878
- begin
879
- emit(:ENUM, ts, te, meta)
880
- end
881
-
882
- end
883
- when 20 then
884
- begin
885
- p = ((te))-1;
886
- begin
887
- emit(:INPUT, ts, te, meta)
888
- end
889
-
890
- end
891
- when 21 then
892
- begin
893
- p = ((te))-1;
894
- begin
895
- emit(:DIRECTIVE, ts, te, meta)
896
- end
897
-
898
- end
899
- when 22 then
900
- begin
901
- p = ((te))-1;
902
- begin
903
- emit(:REPEATABLE, ts, te, meta, "repeatable")
904
- end
905
-
906
- end
907
- when 30 then
908
- begin
909
- p = ((te))-1;
910
- begin
911
- emit_string(ts, te, meta, block: false)
912
- end
913
-
914
- end
915
- when 31 then
916
- begin
917
- p = ((te))-1;
918
- begin
919
- emit_string(ts, te, meta, block: true)
920
- end
921
-
922
- end
923
- when 39 then
924
- begin
925
- p = ((te))-1;
926
- begin
927
- emit(:IDENTIFIER, ts, te, meta)
928
- end
929
-
930
-
931
- end
932
- end
933
-
934
- end
935
-
936
-
937
- end
938
-
939
- end
940
- when 19 then
941
- begin
942
- begin
943
- begin
944
- te = p+1;
945
-
946
- end
947
-
948
- end
949
- begin
950
- begin
951
- act = 2;
952
-
953
- end
954
-
955
- end
956
-
957
- end
958
- when 6 then
959
- begin
960
- begin
961
- begin
962
- te = p+1;
963
-
964
- end
965
-
966
- end
967
- begin
968
- begin
969
- act = 3;
970
-
971
- end
972
-
973
- end
974
-
975
- end
976
- when 49 then
977
- begin
978
- begin
979
- begin
980
- te = p+1;
981
-
982
- end
983
-
984
- end
985
- begin
986
- begin
987
- act = 4;
988
-
989
- end
990
-
991
- end
992
-
993
- end
994
- when 43 then
995
- begin
996
- begin
997
- begin
998
- te = p+1;
999
-
1000
- end
1001
-
1002
- end
1003
- begin
1004
- begin
1005
- act = 5;
1006
-
1007
- end
1008
-
1009
- end
1010
-
1011
- end
1012
- when 55 then
1013
- begin
1014
- begin
1015
- begin
1016
- te = p+1;
1017
-
1018
- end
1019
-
1020
- end
1021
- begin
1022
- begin
1023
- act = 6;
1024
-
1025
- end
1026
-
1027
- end
1028
-
1029
- end
1030
- when 42 then
1031
- begin
1032
- begin
1033
- begin
1034
- te = p+1;
1035
-
1036
- end
1037
-
1038
- end
1039
- begin
1040
- begin
1041
- act = 7;
1042
-
1043
- end
1044
-
1045
- end
1046
-
1047
- end
1048
- when 48 then
1049
- begin
1050
- begin
1051
- begin
1052
- te = p+1;
1053
-
1054
- end
1055
-
1056
- end
1057
- begin
1058
- begin
1059
- act = 8;
1060
-
1061
- end
1062
-
1063
- end
1064
-
1065
- end
1066
- when 50 then
1067
- begin
1068
- begin
1069
- begin
1070
- te = p+1;
1071
-
1072
- end
1073
-
1074
- end
1075
- begin
1076
- begin
1077
- act = 9;
1078
-
1079
- end
1080
-
1081
- end
1082
-
1083
- end
1084
- when 47 then
1085
- begin
1086
- begin
1087
- begin
1088
- te = p+1;
1089
-
1090
- end
1091
-
1092
- end
1093
- begin
1094
- begin
1095
- act = 10;
1096
-
1097
- end
1098
-
1099
- end
1100
-
1101
- end
1102
- when 54 then
1103
- begin
1104
- begin
1105
- begin
1106
- te = p+1;
1107
-
1108
- end
1109
-
1110
- end
1111
- begin
1112
- begin
1113
- act = 11;
1114
-
1115
- end
1116
-
1117
- end
1118
-
1119
- end
1120
- when 53 then
1121
- begin
1122
- begin
1123
- begin
1124
- te = p+1;
1125
-
1126
- end
1127
-
1128
- end
1129
- begin
1130
- begin
1131
- act = 12;
1132
-
1133
- end
1134
-
1135
- end
1136
-
1137
- end
1138
- when 52 then
1139
- begin
1140
- begin
1141
- begin
1142
- te = p+1;
1143
-
1144
- end
1145
-
1146
- end
1147
- begin
1148
- begin
1149
- act = 13;
1150
-
1151
- end
1152
-
1153
- end
1154
-
1155
- end
1156
- when 56 then
1157
- begin
1158
- begin
1159
- begin
1160
- te = p+1;
1161
-
1162
- end
1163
-
1164
- end
1165
- begin
1166
- begin
1167
- act = 14;
1168
-
1169
- end
1170
-
1171
- end
1172
-
1173
- end
1174
- when 41 then
1175
- begin
1176
- begin
1177
- begin
1178
- te = p+1;
1179
-
1180
- end
1181
-
1182
- end
1183
- begin
1184
- begin
1185
- act = 15;
1186
-
1187
- end
1188
-
1189
- end
1190
-
1191
- end
1192
- when 44 then
1193
- begin
1194
- begin
1195
- begin
1196
- te = p+1;
1197
-
1198
- end
1199
-
1200
- end
1201
- begin
1202
- begin
1203
- act = 16;
1204
-
1205
- end
1206
-
1207
- end
1208
-
1209
- end
1210
- when 46 then
1211
- begin
1212
- begin
1213
- begin
1214
- te = p+1;
1215
-
1216
- end
1217
-
1218
- end
1219
- begin
1220
- begin
1221
- act = 17;
1222
-
1223
- end
1224
-
1225
- end
1226
-
1227
- end
1228
- when 57 then
1229
- begin
1230
- begin
1231
- begin
1232
- te = p+1;
1233
-
1234
- end
1235
-
1236
- end
1237
- begin
1238
- begin
1239
- act = 18;
1240
-
1241
- end
1242
-
1243
- end
1244
-
1245
- end
1246
- when 40 then
1247
- begin
1248
- begin
1249
- begin
1250
- te = p+1;
1251
-
1252
- end
1253
-
1254
- end
1255
- begin
1256
- begin
1257
- act = 19;
1258
-
1259
- end
1260
-
1261
- end
1262
-
1263
- end
1264
- when 45 then
1265
- begin
1266
- begin
1267
- begin
1268
- te = p+1;
1269
-
1270
- end
1271
-
1272
- end
1273
- begin
1274
- begin
1275
- act = 20;
1276
-
1277
- end
1278
-
1279
- end
1280
-
1281
- end
1282
- when 39 then
1283
- begin
1284
- begin
1285
- begin
1286
- te = p+1;
1287
-
1288
- end
1289
-
1290
- end
1291
- begin
1292
- begin
1293
- act = 21;
1294
-
1295
- end
1296
-
1297
- end
1298
-
1299
- end
1300
- when 51 then
1301
- begin
1302
- begin
1303
- begin
1304
- te = p+1;
1305
-
1306
- end
1307
-
1308
- end
1309
- begin
1310
- begin
1311
- act = 22;
1312
-
1313
- end
1314
-
1315
- end
1316
-
1317
- end
1318
- when 31 then
1319
- begin
1320
- begin
1321
- begin
1322
- te = p+1;
1323
-
1324
- end
1325
-
1326
- end
1327
- begin
1328
- begin
1329
- act = 30;
1330
-
1331
- end
1332
-
1333
- end
1334
-
1335
- end
1336
- when 4 then
1337
- begin
1338
- begin
1339
- begin
1340
- te = p+1;
1341
-
1342
- end
1343
-
1344
- end
1345
- begin
1346
- begin
1347
- act = 31;
1348
-
1349
- end
1350
-
1351
- end
1352
-
1353
- end
1354
- when 23 then
1355
- begin
1356
- begin
1357
- begin
1358
- te = p+1;
1359
-
1360
- end
1361
-
1362
- end
1363
- begin
1364
- begin
1365
- act = 39;
1366
-
1367
- end
1368
-
1369
- end
1370
-
1371
-
1372
- end
1373
- end
1374
- case _graphql_lexer_to_state_actions[cs]
1375
- when -2 then
1376
- begin
1377
- end
1378
- when 9 then
1379
- begin
1380
- begin
1381
- begin
1382
- ts = 0;
1383
-
1384
- end
1385
-
1386
- end
1387
-
1388
-
1389
- end
1390
- end
1391
- if ( cs == 0 )
1392
- _cont = 0;
1393
-
1394
- end
1395
- if ( _cont == 1 )
1396
- p += 1;
1397
-
1398
- end
1399
-
1400
- end
1401
-
1402
- end
1403
-
1404
- end
1405
-
1406
- end
1407
-
1408
- end
1409
-
1410
- end
1411
-
1412
- end
1413
- meta[:tokens]
1414
- end
1415
-
1416
- def self.record_comment(ts, te, meta)
1417
- token = GraphQL::Language::Token.new(
1418
- :COMMENT,
1419
- meta[:data][ts, te - ts].pack(PACK_DIRECTIVE).force_encoding(UTF_8_ENCODING),
1420
- meta[:line],
1421
- meta[:col],
1422
- meta[:previous_token],
1423
- )
1424
-
1425
- meta[:previous_token] = token
1426
-
1427
- meta[:col] += te - ts
1428
- end
1429
-
1430
- def self.emit(token_name, ts, te, meta, token_value = nil)
1431
- token_value ||= meta[:data][ts, te - ts].pack(PACK_DIRECTIVE).force_encoding(UTF_8_ENCODING)
1432
- meta[:tokens] << token = GraphQL::Language::Token.new(
1433
- token_name,
1434
- token_value,
1435
- meta[:line],
1436
- meta[:col],
1437
- meta[:previous_token],
1438
- )
1439
- meta[:previous_token] = token
1440
- # Bump the column counter for the next token
1441
- meta[:col] += te - ts
1442
- end
1443
-
1444
- ESCAPES = /\\["\\\/bfnrt]/
1445
- ESCAPES_REPLACE = {
1446
- '\\"' => '"',
1447
- "\\\\" => "\\",
1448
- "\\/" => '/',
1449
- "\\b" => "\b",
1450
- "\\f" => "\f",
1451
- "\\n" => "\n",
1452
- "\\r" => "\r",
1453
- "\\t" => "\t",
1454
- }
1455
-
1456
- UTF_8 = /\\u(?:([\dAa-f]{4})|\{([\da-f]{4,})\})(?:\\u([\dAa-f]{4}))?/i
1457
-
1458
-
1459
- VALID_STRING = /\A(?:[^\\]|#{ESCAPES}|#{UTF_8})*\z/o
1460
-
1461
- PACK_DIRECTIVE = "c*"
1462
- UTF_8_ENCODING = "UTF-8"
1463
-
1464
- def self.emit_string(ts, te, meta, block:)
1465
- quotes_length = block ? 3 : 1
1466
- value = meta[:data][ts + quotes_length, te - ts - 2 * quotes_length].pack(PACK_DIRECTIVE).force_encoding(UTF_8_ENCODING) || ''
1467
- line_incr = 0
1468
- if block && !value.empty?
1469
- line_incr = value.count("\n")
1470
- value = GraphQL::Language::BlockString.trim_whitespace(value)
1471
- end
1472
-
1473
- if !value.valid_encoding? || !value.match?(VALID_STRING)
1474
- meta[:tokens] << token = GraphQL::Language::Token.new(
1475
- :BAD_UNICODE_ESCAPE,
1476
- value,
1477
- meta[:line],
1478
- meta[:col],
1479
- meta[:previous_token],
1480
- )
1481
- else
1482
- replace_escaped_characters_in_place(value)
1483
-
1484
- if !value.valid_encoding?
1485
- meta[:tokens] << token = GraphQL::Language::Token.new(
1486
- :BAD_UNICODE_ESCAPE,
1487
- value,
1488
- meta[:line],
1489
- meta[:col],
1490
- meta[:previous_token],
1491
- )
1492
- else
1493
- meta[:tokens] << token = GraphQL::Language::Token.new(
1494
- :STRING,
1495
- value,
1496
- meta[:line],
1497
- meta[:col],
1498
- meta[:previous_token],
1499
- )
1500
- end
1501
- end
1502
-
1503
- meta[:previous_token] = token
1504
- meta[:col] += te - ts
1505
- meta[:line] += line_incr
1506
- end
1507
- end
1508
- end
3
+ module Language
4
+
5
+ class Lexer
6
+ def initialize(graphql_str, filename: nil, max_tokens: nil)
7
+ if !(graphql_str.encoding == Encoding::UTF_8 || graphql_str.ascii_only?)
8
+ graphql_str = graphql_str.dup.force_encoding(Encoding::UTF_8)
9
+ end
10
+ @string = graphql_str
11
+ @filename = filename
12
+ @scanner = StringScanner.new(graphql_str)
13
+ @pos = nil
14
+ @max_tokens = max_tokens || Float::INFINITY
15
+ @tokens_count = 0
16
+ end
17
+
18
+ def eos?
19
+ @scanner.eos?
20
+ end
21
+
22
+ attr_reader :pos
23
+
24
+ def advance
25
+ @scanner.skip(IGNORE_REGEXP)
26
+ return false if @scanner.eos?
27
+ @tokens_count += 1
28
+ if @tokens_count > @max_tokens
29
+ raise_parse_error("This query is too large to execute.")
30
+ end
31
+ @pos = @scanner.pos
32
+ next_byte = @string.getbyte(@pos)
33
+ next_byte_is_for = FIRST_BYTES[next_byte]
34
+ case next_byte_is_for
35
+ when ByteFor::PUNCTUATION
36
+ @scanner.pos += 1
37
+ PUNCTUATION_NAME_FOR_BYTE[next_byte]
38
+ when ByteFor::NAME
39
+ if len = @scanner.skip(KEYWORD_REGEXP)
40
+ case len
41
+ when 2
42
+ :ON
43
+ when 12
44
+ :SUBSCRIPTION
45
+ else
46
+ pos = @pos
47
+
48
+ # Use bytes 2 and 3 as a unique identifier for this keyword
49
+ bytes = (@string.getbyte(pos + 2) << 8) | @string.getbyte(pos + 1)
50
+ KEYWORD_BY_TWO_BYTES[_hash(bytes)]
51
+ end
52
+ else
53
+ @scanner.skip(IDENTIFIER_REGEXP)
54
+ :IDENTIFIER
55
+ end
56
+ when ByteFor::IDENTIFIER
57
+ @scanner.skip(IDENTIFIER_REGEXP)
58
+ :IDENTIFIER
59
+ when ByteFor::NUMBER
60
+ @scanner.skip(NUMERIC_REGEXP)
61
+
62
+ if GraphQL.reject_numbers_followed_by_names
63
+ new_pos = @scanner.pos
64
+ peek_byte = @string.getbyte(new_pos)
65
+ next_first_byte = FIRST_BYTES[peek_byte]
66
+ if next_first_byte == ByteFor::NAME || next_first_byte == ByteFor::IDENTIFIER
67
+ number_part = token_value
68
+ name_part = @scanner.scan(IDENTIFIER_REGEXP)
69
+ raise_parse_error("Name after number is not allowed (in `#{number_part}#{name_part}`)")
70
+ end
71
+ end
72
+ # Check for a matched decimal:
73
+ @scanner[1] ? :FLOAT : :INT
74
+ when ByteFor::ELLIPSIS
75
+ if @string.getbyte(@pos + 1) != 46 || @string.getbyte(@pos + 2) != 46
76
+ raise_parse_error("Expected `...`, actual: #{@string[@pos..@pos + 2].inspect}")
77
+ end
78
+ @scanner.pos += 3
79
+ :ELLIPSIS
80
+ when ByteFor::STRING
81
+ if @scanner.skip(BLOCK_STRING_REGEXP) || @scanner.skip(QUOTED_STRING_REGEXP)
82
+ :STRING
83
+ else
84
+ raise_parse_error("Expected string or block string, but it was malformed")
85
+ end
86
+ else
87
+ @scanner.pos += 1
88
+ :UNKNOWN_CHAR
89
+ end
90
+ rescue ArgumentError => err
91
+ if err.message == "invalid byte sequence in UTF-8"
92
+ raise_parse_error("Parse error on bad Unicode escape sequence", nil, nil)
93
+ end
94
+ end
95
+
96
+ def token_value
97
+ @string.byteslice(@scanner.pos - @scanner.matched_size, @scanner.matched_size)
98
+ rescue StandardError => err
99
+ raise GraphQL::Error, "(token_value failed: #{err.class}: #{err.message})"
100
+ end
101
+
102
+ def debug_token_value(token_name)
103
+ if token_name && Lexer::Punctuation.const_defined?(token_name)
104
+ Lexer::Punctuation.const_get(token_name)
105
+ elsif token_name == :ELLIPSIS
106
+ "..."
107
+ elsif token_name == :STRING
108
+ string_value
109
+ elsif @scanner.matched_size.nil?
110
+ @scanner.peek(1)
111
+ else
112
+ token_value
113
+ end
114
+ end
115
+
116
+ ESCAPES = /\\["\\\/bfnrt]/
117
+ ESCAPES_REPLACE = {
118
+ '\\"' => '"',
119
+ "\\\\" => "\\",
120
+ "\\/" => '/',
121
+ "\\b" => "\b",
122
+ "\\f" => "\f",
123
+ "\\n" => "\n",
124
+ "\\r" => "\r",
125
+ "\\t" => "\t",
126
+ }
127
+ UTF_8 = /\\u(?:([\dAa-f]{4})|\{([\da-f]{4,})\})(?:\\u([\dAa-f]{4}))?/i
128
+ VALID_STRING = /\A(?:[^\\]|#{ESCAPES}|#{UTF_8})*\z/o
129
+ ESCAPED = /(?:#{ESCAPES}|#{UTF_8})/o
130
+
131
+ def string_value
132
+ str = token_value
133
+ is_block = str.start_with?('"""')
134
+ if is_block
135
+ str.gsub!(/\A"""|"""\z/, '')
136
+ return Language::BlockString.trim_whitespace(str)
137
+ else
138
+ str.gsub!(/\A"|"\z/, '')
139
+
140
+ if !str.valid_encoding? || !str.match?(VALID_STRING)
141
+ raise_parse_error("Bad unicode escape in #{str.inspect}")
142
+ else
143
+ Lexer.replace_escaped_characters_in_place(str)
144
+
145
+ if !str.valid_encoding?
146
+ raise_parse_error("Bad unicode escape in #{str.inspect}")
147
+ else
148
+ str
149
+ end
150
+ end
151
+ end
152
+ end
153
+
154
+ def line_number
155
+ @scanner.string[0..@pos].count("\n") + 1
156
+ end
157
+
158
+ def column_number
159
+ @scanner.string[0..@pos].split("\n").last.length
160
+ end
161
+
162
+ def raise_parse_error(message, line = line_number, col = column_number)
163
+ raise GraphQL::ParseError.new(message, line, col, @string, filename: @filename)
164
+ end
165
+
166
+ IGNORE_REGEXP = %r{
167
+ (?:
168
+ [, \c\r\n\t]+ |
169
+ \#.*$
170
+ )*
171
+ }x
172
+ IDENTIFIER_REGEXP = /[_A-Za-z][_0-9A-Za-z]*/
173
+ INT_REGEXP = /-?(?:[0]|[1-9][0-9]*)/
174
+ FLOAT_DECIMAL_REGEXP = /[.][0-9]+/
175
+ FLOAT_EXP_REGEXP = /[eE][+-]?[0-9]+/
176
+ # TODO: FLOAT_EXP_REGEXP should not be allowed to follow INT_REGEXP, integers are not allowed to have exponent parts.
177
+ NUMERIC_REGEXP = /#{INT_REGEXP}(#{FLOAT_DECIMAL_REGEXP}#{FLOAT_EXP_REGEXP}|#{FLOAT_DECIMAL_REGEXP}|#{FLOAT_EXP_REGEXP})?/
178
+
179
+ KEYWORDS = [
180
+ "on",
181
+ "fragment",
182
+ "true",
183
+ "false",
184
+ "null",
185
+ "query",
186
+ "mutation",
187
+ "subscription",
188
+ "schema",
189
+ "scalar",
190
+ "type",
191
+ "extend",
192
+ "implements",
193
+ "interface",
194
+ "union",
195
+ "enum",
196
+ "input",
197
+ "directive",
198
+ "repeatable"
199
+ ].freeze
200
+
201
+ KEYWORD_REGEXP = /#{Regexp.union(KEYWORDS.sort)}\b/
202
+ KEYWORD_BY_TWO_BYTES = [
203
+ :INTERFACE,
204
+ :MUTATION,
205
+ :EXTEND,
206
+ :FALSE,
207
+ :ENUM,
208
+ :TRUE,
209
+ :NULL,
210
+ nil,
211
+ nil,
212
+ nil,
213
+ nil,
214
+ nil,
215
+ nil,
216
+ nil,
217
+ :QUERY,
218
+ nil,
219
+ nil,
220
+ :REPEATABLE,
221
+ :IMPLEMENTS,
222
+ :INPUT,
223
+ :TYPE,
224
+ :SCHEMA,
225
+ nil,
226
+ nil,
227
+ nil,
228
+ :DIRECTIVE,
229
+ :UNION,
230
+ nil,
231
+ nil,
232
+ :SCALAR,
233
+ nil,
234
+ :FRAGMENT
235
+ ]
236
+
237
+ # This produces a unique integer for bytes 2 and 3 of each keyword string
238
+ # See https://tenderlovemaking.com/2023/09/02/fast-tokenizers-with-stringscanner.html
239
+ def _hash key
240
+ (key * 18592990) >> 27 & 0x1f
241
+ end
242
+
243
+ module Punctuation
244
+ LCURLY = '{'
245
+ RCURLY = '}'
246
+ LPAREN = '('
247
+ RPAREN = ')'
248
+ LBRACKET = '['
249
+ RBRACKET = ']'
250
+ COLON = ':'
251
+ VAR_SIGN = '$'
252
+ DIR_SIGN = '@'
253
+ EQUALS = '='
254
+ BANG = '!'
255
+ PIPE = '|'
256
+ AMP = '&'
257
+ end
258
+
259
+ # A sparse array mapping the bytes for each punctuation
260
+ # to a symbol name for that punctuation
261
+ PUNCTUATION_NAME_FOR_BYTE = Punctuation.constants.each_with_object([]) { |name, arr|
262
+ punct = Punctuation.const_get(name)
263
+ arr[punct.ord] = name
264
+ }
265
+
266
+ QUOTE = '"'
267
+ UNICODE_DIGIT = /[0-9A-Za-z]/
268
+ FOUR_DIGIT_UNICODE = /#{UNICODE_DIGIT}{4}/
269
+ N_DIGIT_UNICODE = %r{#{Punctuation::LCURLY}#{UNICODE_DIGIT}{4,}#{Punctuation::RCURLY}}x
270
+ UNICODE_ESCAPE = %r{\\u(?:#{FOUR_DIGIT_UNICODE}|#{N_DIGIT_UNICODE})}
271
+ STRING_ESCAPE = %r{[\\][\\/bfnrt]}
272
+ BLOCK_QUOTE = '"""'
273
+ ESCAPED_QUOTE = /\\"/;
274
+ STRING_CHAR = /#{ESCAPED_QUOTE}|[^"\\\n\r]|#{UNICODE_ESCAPE}|#{STRING_ESCAPE}/
275
+ QUOTED_STRING_REGEXP = %r{#{QUOTE} (?:#{STRING_CHAR})* #{QUOTE}}x
276
+ BLOCK_STRING_REGEXP = %r{
277
+ #{BLOCK_QUOTE}
278
+ (?: [^"\\] | # Any characters that aren't a quote or slash
279
+ (?<!") ["]{1,2} (?!") | # Any quotes that don't have quotes next to them
280
+ \\"{0,3}(?!") | # A slash followed by <= 3 quotes that aren't followed by a quote
281
+ \\ | # A slash
282
+ "{1,2}(?!") # 1 or 2 " followed by something that isn't a quote
283
+ )*
284
+ (?:"")?
285
+ #{BLOCK_QUOTE}
286
+ }xm
287
+
288
+ # Use this array to check, for a given byte that will start a token,
289
+ # what kind of token might it start?
290
+ FIRST_BYTES = Array.new(255)
291
+
292
+ module ByteFor
293
+ NUMBER = 0 # int or float
294
+ NAME = 1 # identifier or keyword
295
+ STRING = 2
296
+ ELLIPSIS = 3
297
+ IDENTIFIER = 4 # identifier, *not* a keyword
298
+ PUNCTUATION = 5
299
+ end
300
+
301
+ (0..9).each { |i| FIRST_BYTES[i.to_s.ord] = ByteFor::NUMBER }
302
+ FIRST_BYTES["-".ord] = ByteFor::NUMBER
303
+ # Some of these may be overwritten below, if keywords start with the same character
304
+ ("A".."Z").each { |char| FIRST_BYTES[char.ord] = ByteFor::IDENTIFIER }
305
+ ("a".."z").each { |char| FIRST_BYTES[char.ord] = ByteFor::IDENTIFIER }
306
+ FIRST_BYTES['_'.ord] = ByteFor::IDENTIFIER
307
+ FIRST_BYTES['.'.ord] = ByteFor::ELLIPSIS
308
+ FIRST_BYTES['"'.ord] = ByteFor::STRING
309
+ KEYWORDS.each { |kw| FIRST_BYTES[kw.getbyte(0)] = ByteFor::NAME }
310
+ Punctuation.constants.each do |punct_name|
311
+ punct = Punctuation.const_get(punct_name)
312
+ FIRST_BYTES[punct.ord] = ByteFor::PUNCTUATION
313
+ end
314
+
315
+
316
+ # Replace any escaped unicode or whitespace with the _actual_ characters
317
+ # To avoid allocating more strings, this modifies the string passed into it
318
+ def self.replace_escaped_characters_in_place(raw_string)
319
+ raw_string.gsub!(ESCAPED) do |matched_str|
320
+ if (point_str_1 = $1 || $2)
321
+ codepoint_1 = point_str_1.to_i(16)
322
+ if (codepoint_2 = $3)
323
+ codepoint_2 = codepoint_2.to_i(16)
324
+ if (codepoint_1 >= 0xD800 && codepoint_1 <= 0xDBFF) && # leading surrogate
325
+ (codepoint_2 >= 0xDC00 && codepoint_2 <= 0xDFFF) # trailing surrogate
326
+ # A surrogate pair
327
+ combined = ((codepoint_1 - 0xD800) * 0x400) + (codepoint_2 - 0xDC00) + 0x10000
328
+ [combined].pack('U'.freeze)
329
+ else
330
+ # Two separate code points
331
+ [codepoint_1].pack('U'.freeze) + [codepoint_2].pack('U'.freeze)
332
+ end
333
+ else
334
+ [codepoint_1].pack('U'.freeze)
335
+ end
336
+ else
337
+ ESCAPES_REPLACE[matched_str]
338
+ end
339
+ end
340
+ nil
341
+ end
342
+
343
+ # This is not used during parsing because the parser
344
+ # doesn't actually need tokens.
345
+ def self.tokenize(string)
346
+ lexer = GraphQL::Language::Lexer.new(string)
347
+ tokens = []
348
+ while (token_name = lexer.advance)
349
+ new_token = [
350
+ token_name,
351
+ lexer.line_number,
352
+ lexer.column_number,
353
+ lexer.debug_token_value(token_name),
354
+ ]
355
+ tokens << new_token
356
+ end
357
+ tokens
358
+ end
359
+ end
360
+ end
1509
361
  end