herb 0.11.1 → 0.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +4 -2
  3. data/config.yml +6 -0
  4. data/ext/herb/extconf.rb +8 -31
  5. data/ext/herb/nodes.c +75 -75
  6. data/ext/herb/parser_options_helpers.c +26 -0
  7. data/lib/herb/analysis/partial_index.rb +1 -1
  8. data/lib/herb/analysis/partial_resolution.rb +27 -0
  9. data/lib/herb/ast/helpers.rb +1 -1
  10. data/lib/herb/configuration.rb +11 -1
  11. data/lib/herb/dev/classifier.rb +1 -1
  12. data/lib/herb/engine/compiler.rb +5 -8
  13. data/lib/herb/engine/slots/dynamics_compiler.rb +53 -14
  14. data/lib/herb/engine/slots/subtree_compiler.rb +1 -1
  15. data/lib/herb/engine/slots/visitor.rb +32 -4
  16. data/lib/herb/engine/visitors/instrumentation_visitor.rb +18 -6
  17. data/lib/herb/parser_options.rb +6 -3
  18. data/lib/herb/project.rb +19 -8
  19. data/lib/herb/version.rb +1 -1
  20. data/lib/herb.rb +1 -1
  21. data/sig/herb/analysis/partial_resolution.rbs +8 -0
  22. data/sig/herb/configuration.rbs +3 -0
  23. data/sig/herb/engine/slots/dynamics_compiler.rbs +24 -7
  24. data/sig/herb/engine/slots/visitor.rbs +14 -0
  25. data/sig/herb/engine/visitors/instrumentation_visitor.rbs +5 -1
  26. data/sig/herb/parser_options.rbs +6 -4
  27. data/sig/herb.rbs +2 -2
  28. data/src/analyze/action_view/attribute_extraction_helpers.c +40 -21
  29. data/src/analyze/action_view/generated_handlers.c +36 -36
  30. data/src/analyze/action_view/image_tag.c +7 -3
  31. data/src/analyze/action_view/javascript_include_tag.c +6 -3
  32. data/src/analyze/action_view/link_to.c +23 -23
  33. data/src/analyze/action_view/registry.c +7 -3
  34. data/src/analyze/action_view/tag_helper_node_builders.c +6 -13
  35. data/src/analyze/action_view/tag_helpers.c +139 -90
  36. data/src/analyze/action_view/turbo_frame_tag.c +5 -4
  37. data/src/analyze/analyze.c +35 -19
  38. data/src/analyze/analyze_helpers.c +161 -188
  39. data/src/analyze/analyzed_ruby.c +8 -7
  40. data/src/analyze/control_type.c +29 -22
  41. data/src/analyze/herb_directives.c +16 -20
  42. data/src/analyze/iteration_nodes.c +69 -24
  43. data/src/analyze/parse_errors.c +32 -22
  44. data/src/analyze/postfix_conditionals.c +23 -13
  45. data/src/analyze/prism_annotate.c +29 -28
  46. data/src/analyze/render_nodes.c +51 -41
  47. data/src/analyze/strict_locals.c +14 -15
  48. data/src/analyze/ternary_conditionals.c +14 -10
  49. data/src/herb.c +10 -8
  50. data/src/include/analyze/action_view/tag_helper_handler.h +1 -1
  51. data/src/include/analyze/action_view/tag_helper_node_builders.h +1 -0
  52. data/src/include/analyze/action_view/tag_helpers.h +1 -1
  53. data/src/include/analyze/analyze.h +3 -2
  54. data/src/include/analyze/analyzed_ruby.h +4 -2
  55. data/src/include/analyze/helpers.h +6 -6
  56. data/src/include/herb.h +3 -2
  57. data/src/include/parser/parser_options.h +5 -0
  58. data/src/include/prism/prism_context.h +12 -12
  59. data/src/include/prism/prism_helpers.h +30 -0
  60. data/src/include/prism_version.h +11 -0
  61. data/src/include/version.h +1 -1
  62. data/src/parser/parser_helpers.c +1 -2
  63. data/src/parser.c +6 -7
  64. data/src/parser_options_defaults.c +1 -0
  65. data/src/prism/prism_helpers.c +84 -50
  66. data/src/prism/ruby_parser.c +20 -20
  67. data/templates/ext/herb/nodes.c.erb +5 -5
  68. data/templates/ext/herb/parser_options_helpers.c.erb +33 -0
  69. data/templates/java/nodes.c.erb +6 -6
  70. data/templates/java/parser_options_helpers.c.erb +41 -2
  71. data/templates/java/parser_options_helpers.h.erb +2 -1
  72. data/templates/javascript/packages/node/extension/nodes.cpp.erb +5 -5
  73. data/templates/javascript/packages/node/extension/parser_options_helpers.cpp.erb +34 -2
  74. data/templates/javascript/packages/node/extension/parser_options_helpers.h.erb +1 -1
  75. data/templates/lib/herb/parser_options.rb.erb +1 -1
  76. data/templates/rust/src/prism/generated_deserialize.rs.erb +90 -44
  77. data/templates/rust/src/prism/generated_prettyprint.rs.erb +18 -27
  78. data/templates/src/analyze/action_view/generated_handlers.c.erb +23 -22
  79. data/templates/src/include/parser/parser_options.h.erb +10 -0
  80. data/templates/src/include/prism_version.h.erb +17 -0
  81. data/templates/src/parser_options_defaults.c.erb +1 -1
  82. data/templates/template.rb +17 -2
  83. data/templates/wasm/nodes.cpp.erb +5 -5
  84. data/templates/wasm/parser_options_helpers.cpp.erb +24 -0
  85. data/vendor/prism/Rakefile +76 -7
  86. data/vendor/prism/config.yml +174 -161
  87. data/vendor/prism/include/prism/arena.h +45 -0
  88. data/vendor/prism/include/prism/arena.hpp +42 -0
  89. data/vendor/prism/include/prism/ast.h +2738 -611
  90. data/vendor/prism/include/prism/ast.hpp +641 -0
  91. data/vendor/prism/include/prism/buffer.h +60 -0
  92. data/vendor/prism/include/prism/buffer.hpp +55 -0
  93. data/vendor/prism/include/prism/comments.h +72 -0
  94. data/vendor/prism/include/prism/compiler/accel.h +26 -0
  95. data/vendor/prism/include/prism/compiler/align.h +36 -0
  96. data/vendor/prism/include/prism/compiler/assume.h +25 -0
  97. data/vendor/prism/include/prism/compiler/branch.h +26 -0
  98. data/vendor/prism/include/prism/compiler/bswap.h +46 -0
  99. data/vendor/prism/include/prism/compiler/cplusplus.hpp +16 -0
  100. data/vendor/prism/include/prism/compiler/endianness.h +34 -0
  101. data/vendor/prism/include/prism/compiler/exceptions.hpp +17 -0
  102. data/vendor/prism/include/prism/compiler/exported.h +24 -0
  103. data/vendor/prism/include/prism/compiler/fallthrough.h +22 -0
  104. data/vendor/prism/include/prism/compiler/filesystem.h +32 -0
  105. data/vendor/prism/include/prism/compiler/flex_array.h +19 -0
  106. data/vendor/prism/include/prism/compiler/force_inline.h +21 -0
  107. data/vendor/prism/include/prism/compiler/format.h +27 -0
  108. data/vendor/prism/include/prism/compiler/inline.h +17 -0
  109. data/vendor/prism/include/prism/compiler/lifetimebound.hpp +25 -0
  110. data/vendor/prism/include/prism/compiler/nodiscard.h +22 -0
  111. data/vendor/prism/include/prism/compiler/nonnull.h +18 -0
  112. data/vendor/prism/include/prism/compiler/unused.h +18 -0
  113. data/vendor/prism/include/prism/constant_pool.h +106 -0
  114. data/vendor/prism/include/prism/diagnostic.h +55 -402
  115. data/vendor/prism/include/prism/errors_format.h +61 -0
  116. data/vendor/prism/include/prism/excludes.h +29 -0
  117. data/vendor/prism/include/prism/integer.h +41 -0
  118. data/vendor/prism/include/prism/internal/allocator.h +68 -0
  119. data/vendor/prism/include/prism/internal/allocator_debug.h +88 -0
  120. data/vendor/prism/include/prism/internal/arena.h +108 -0
  121. data/vendor/prism/include/prism/internal/bit.h +42 -0
  122. data/vendor/prism/include/prism/internal/buffer.h +94 -0
  123. data/vendor/prism/include/prism/internal/char.h +145 -0
  124. data/vendor/prism/include/prism/internal/comments.h +54 -0
  125. data/vendor/prism/include/prism/internal/constant_pool.h +152 -0
  126. data/vendor/prism/include/prism/internal/diagnostic.h +389 -0
  127. data/vendor/prism/include/prism/{encoding.h → internal/encoding.h} +27 -68
  128. data/vendor/prism/include/prism/internal/integer.h +68 -0
  129. data/vendor/prism/include/prism/internal/isinf.h +16 -0
  130. data/vendor/prism/include/prism/internal/line_offset_list.h +34 -0
  131. data/vendor/prism/include/prism/{util/pm_list.h → internal/list.h} +11 -52
  132. data/vendor/prism/include/prism/internal/magic_comments.h +23 -0
  133. data/vendor/prism/include/prism/internal/memchr.h +15 -0
  134. data/vendor/prism/include/prism/internal/node.h +42 -0
  135. data/vendor/prism/include/prism/internal/options.h +232 -0
  136. data/vendor/prism/include/prism/internal/parser.h +1015 -0
  137. data/vendor/prism/include/prism/internal/regexp.h +26 -0
  138. data/vendor/prism/include/prism/internal/serialize.h +39 -0
  139. data/vendor/prism/include/prism/internal/source.h +72 -0
  140. data/vendor/prism/include/prism/internal/static_literals.h +60 -0
  141. data/vendor/prism/include/prism/internal/stringy.h +30 -0
  142. data/vendor/prism/include/prism/{util/pm_strncasecmp.h → internal/strncasecmp.h} +3 -17
  143. data/vendor/prism/include/prism/{util/pm_strpbrk.h → internal/strpbrk.h} +7 -20
  144. data/vendor/prism/include/prism/internal/tokens.h +11 -0
  145. data/vendor/prism/include/prism/internal/xxh3.h +16 -0
  146. data/vendor/prism/include/prism/json.h +40 -0
  147. data/vendor/prism/include/prism/line_offset_list.h +69 -0
  148. data/vendor/prism/include/prism/magic_comments.h +53 -0
  149. data/vendor/prism/include/prism/node.h +59 -49
  150. data/vendor/prism/include/prism/node.hpp +272 -0
  151. data/vendor/prism/include/prism/node_type.hpp +38 -0
  152. data/vendor/prism/include/prism/options.h +154 -279
  153. data/vendor/prism/include/prism/options.hpp +43 -0
  154. data/vendor/prism/include/prism/parser.h +367 -870
  155. data/vendor/prism/include/prism/parser.hpp +274 -0
  156. data/vendor/prism/include/prism/prettyprint.h +14 -9
  157. data/vendor/prism/include/prism/serialize.h +123 -0
  158. data/vendor/prism/include/prism/source.h +163 -0
  159. data/vendor/prism/include/prism/stream.h +36 -0
  160. data/vendor/prism/include/prism/string_query.h +82 -0
  161. data/vendor/prism/include/prism/stringy.h +61 -0
  162. data/vendor/prism/include/prism/stringy.hpp +31 -0
  163. data/vendor/prism/include/prism/version.h +20 -3
  164. data/vendor/prism/include/prism.h +35 -320
  165. data/vendor/prism/include/prism.hpp +24 -0
  166. data/vendor/prism/src/arena.c +122 -0
  167. data/vendor/prism/src/{util/pm_buffer.c → buffer.c} +53 -21
  168. data/vendor/prism/src/{util/pm_char.c → char.c} +28 -57
  169. data/vendor/prism/src/comments.c +455 -0
  170. data/vendor/prism/src/constant_pool.c +406 -0
  171. data/vendor/prism/src/diagnostic.c +120 -68
  172. data/vendor/prism/src/encoding.c +8 -3
  173. data/vendor/prism/src/errors_format.c +519 -0
  174. data/vendor/prism/src/{util/pm_integer.c → integer.c} +38 -22
  175. data/vendor/prism/src/json.c +5733 -0
  176. data/vendor/prism/src/line_offset_list.c +100 -0
  177. data/vendor/prism/src/list.c +24 -0
  178. data/vendor/prism/src/{util/pm_memchr.c → memchr.c} +8 -6
  179. data/vendor/prism/src/node.c +3465 -7787
  180. data/vendor/prism/src/options.c +161 -54
  181. data/vendor/prism/src/parser.c +371 -0
  182. data/vendor/prism/src/prettyprint.c +421 -354
  183. data/vendor/prism/src/prism.c +8522 -7280
  184. data/vendor/prism/src/regexp.c +960 -45
  185. data/vendor/prism/src/serialize.c +2434 -2048
  186. data/vendor/prism/src/source.c +524 -0
  187. data/vendor/prism/src/static_literals.c +303 -360
  188. data/vendor/prism/src/string_query.c +180 -0
  189. data/vendor/prism/src/stringy.c +61 -0
  190. data/vendor/prism/src/{util/pm_strncasecmp.c → strncasecmp.c} +5 -4
  191. data/vendor/prism/src/strpbrk.c +447 -0
  192. data/vendor/prism/src/{token_type.c → tokens.c} +39 -18
  193. data/vendor/prism/src/xxh3.c +292 -0
  194. data/vendor/prism/templates/ext/prism/api_node.c.erb +58 -44
  195. data/vendor/prism/templates/include/prism/ast.h.erb +67 -17
  196. data/vendor/prism/templates/include/prism/ast.hpp.erb +31 -0
  197. data/vendor/prism/templates/include/prism/internal/diagnostic.h.erb +60 -0
  198. data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/AbstractNodeVisitor.java.erb +1 -1
  199. data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/Loader.java.erb +232 -133
  200. data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/Nodes.java.erb +62 -23
  201. data/vendor/prism/templates/javascript/src/deserialize.js.erb +153 -146
  202. data/vendor/prism/templates/javascript/src/nodes.js.erb +4 -9
  203. data/vendor/prism/templates/lib/prism/compiler.rb.erb +14 -5
  204. data/vendor/prism/templates/lib/prism/dispatcher.rb.erb +20 -12
  205. data/vendor/prism/templates/lib/prism/dot_visitor.rb.erb +37 -11
  206. data/vendor/prism/templates/lib/prism/dsl.rb.erb +43 -4
  207. data/vendor/prism/templates/lib/prism/inspect_visitor.rb.erb +26 -10
  208. data/vendor/prism/templates/lib/prism/mutation_compiler.rb.erb +5 -2
  209. data/vendor/prism/templates/lib/prism/node.rb.erb +283 -105
  210. data/vendor/prism/templates/lib/prism/reflection.rb.erb +11 -2
  211. data/vendor/prism/templates/lib/prism/serialize.rb.erb +291 -134
  212. data/vendor/prism/templates/lib/prism/visitor.rb.erb +18 -0
  213. data/vendor/prism/templates/src/diagnostic.c.erb +114 -63
  214. data/vendor/prism/templates/src/json.c.erb +130 -0
  215. data/vendor/prism/templates/src/node.c.erb +79 -236
  216. data/vendor/prism/templates/src/prettyprint.c.erb +24 -13
  217. data/vendor/prism/templates/src/serialize.c.erb +369 -183
  218. data/vendor/prism/templates/src/{token_type.c.erb → tokens.c.erb} +22 -11
  219. data/vendor/prism/templates/template.rb +193 -91
  220. metadata +100 -42
  221. data/vendor/prism/include/prism/defines.h +0 -260
  222. data/vendor/prism/include/prism/pack.h +0 -163
  223. data/vendor/prism/include/prism/regexp.h +0 -43
  224. data/vendor/prism/include/prism/static_literals.h +0 -121
  225. data/vendor/prism/include/prism/util/pm_buffer.h +0 -236
  226. data/vendor/prism/include/prism/util/pm_char.h +0 -204
  227. data/vendor/prism/include/prism/util/pm_constant_pool.h +0 -218
  228. data/vendor/prism/include/prism/util/pm_integer.h +0 -130
  229. data/vendor/prism/include/prism/util/pm_memchr.h +0 -29
  230. data/vendor/prism/include/prism/util/pm_newline_list.h +0 -113
  231. data/vendor/prism/include/prism/util/pm_string.h +0 -200
  232. data/vendor/prism/src/pack.c +0 -509
  233. data/vendor/prism/src/util/pm_constant_pool.c +0 -342
  234. data/vendor/prism/src/util/pm_list.c +0 -49
  235. data/vendor/prism/src/util/pm_newline_list.c +0 -125
  236. data/vendor/prism/src/util/pm_string.c +0 -381
  237. data/vendor/prism/src/util/pm_strpbrk.c +0 -206
  238. data/vendor/prism/templates/include/prism/diagnostic.h.erb +0 -130
  239. data/vendor/prism/templates/rbi/prism/dsl.rbi.erb +0 -68
  240. data/vendor/prism/templates/rbi/prism/node.rbi.erb +0 -167
  241. data/vendor/prism/templates/rbi/prism/visitor.rbi.erb +0 -18
  242. data/vendor/prism/templates/sig/prism/_private/dot_visitor.rbs.erb +0 -45
  243. data/vendor/prism/templates/sig/prism/dsl.rbs.erb +0 -31
  244. data/vendor/prism/templates/sig/prism/mutation_compiler.rbs.erb +0 -7
  245. data/vendor/prism/templates/sig/prism/node.rbs.erb +0 -136
  246. data/vendor/prism/templates/sig/prism/visitor.rbs.erb +0 -17
  247. data/vendor/prism/templates/sig/prism.rbs.erb +0 -92
@@ -1,130 +0,0 @@
1
- /**
2
- * @file diagnostic.h
3
- *
4
- * A list of diagnostics generated during parsing.
5
- */
6
- #ifndef PRISM_DIAGNOSTIC_H
7
- #define PRISM_DIAGNOSTIC_H
8
-
9
- #include "prism/ast.h"
10
- #include "prism/defines.h"
11
- #include "prism/util/pm_list.h"
12
-
13
- #include <stdbool.h>
14
- #include <stdlib.h>
15
- #include <assert.h>
16
-
17
- /**
18
- * The diagnostic IDs of all of the diagnostics, used to communicate the types
19
- * of errors between the parser and the user.
20
- */
21
- typedef enum {
22
- // These are the error diagnostics.
23
- <%- errors.each do |error| -%>
24
- PM_ERR_<%= error.name %>,
25
- <%- end -%>
26
-
27
- // These are the warning diagnostics.
28
- <%- warnings.each do |warning| -%>
29
- PM_WARN_<%= warning.name %>,
30
- <%- end -%>
31
- } pm_diagnostic_id_t;
32
-
33
- /**
34
- * This struct represents a diagnostic generated during parsing.
35
- *
36
- * @extends pm_list_node_t
37
- */
38
- typedef struct {
39
- /** The embedded base node. */
40
- pm_list_node_t node;
41
-
42
- /** The location of the diagnostic in the source. */
43
- pm_location_t location;
44
-
45
- /** The ID of the diagnostic. */
46
- pm_diagnostic_id_t diag_id;
47
-
48
- /** The message associated with the diagnostic. */
49
- const char *message;
50
-
51
- /**
52
- * Whether or not the memory related to the message of this diagnostic is
53
- * owned by this diagnostic. If it is, it needs to be freed when the
54
- * diagnostic is freed.
55
- */
56
- bool owned;
57
-
58
- /**
59
- * The level of the diagnostic, see `pm_error_level_t` and
60
- * `pm_warning_level_t` for possible values.
61
- */
62
- uint8_t level;
63
- } pm_diagnostic_t;
64
-
65
- /**
66
- * The levels of errors generated during parsing.
67
- */
68
- typedef enum {
69
- /** For errors that should raise a syntax error. */
70
- PM_ERROR_LEVEL_SYNTAX = 0,
71
-
72
- /** For errors that should raise an argument error. */
73
- PM_ERROR_LEVEL_ARGUMENT = 1,
74
-
75
- /** For errors that should raise a load error. */
76
- PM_ERROR_LEVEL_LOAD = 2
77
- } pm_error_level_t;
78
-
79
- /**
80
- * The levels of warnings generated during parsing.
81
- */
82
- typedef enum {
83
- /** For warnings which should be emitted if $VERBOSE != nil. */
84
- PM_WARNING_LEVEL_DEFAULT = 0,
85
-
86
- /** For warnings which should be emitted if $VERBOSE == true. */
87
- PM_WARNING_LEVEL_VERBOSE = 1
88
- } pm_warning_level_t;
89
-
90
- /**
91
- * Get the human-readable name of the given diagnostic ID.
92
- *
93
- * @param diag_id The diagnostic ID.
94
- * @return The human-readable name of the diagnostic ID.
95
- */
96
- const char * pm_diagnostic_id_human(pm_diagnostic_id_t diag_id);
97
-
98
- /**
99
- * Append a diagnostic to the given list of diagnostics that is using shared
100
- * memory for its message.
101
- *
102
- * @param list The list to append to.
103
- * @param start The start of the diagnostic.
104
- * @param end The end of the diagnostic.
105
- * @param diag_id The diagnostic ID.
106
- * @return Whether the diagnostic was successfully appended.
107
- */
108
- bool pm_diagnostic_list_append(pm_list_t *list, const uint8_t *start, const uint8_t *end, pm_diagnostic_id_t diag_id);
109
-
110
- /**
111
- * Append a diagnostic to the given list of diagnostics that is using a format
112
- * string for its message.
113
- *
114
- * @param list The list to append to.
115
- * @param start The start of the diagnostic.
116
- * @param end The end of the diagnostic.
117
- * @param diag_id The diagnostic ID.
118
- * @param ... The arguments to the format string for the message.
119
- * @return Whether the diagnostic was successfully appended.
120
- */
121
- bool pm_diagnostic_list_append_format(pm_list_t *list, const uint8_t *start, const uint8_t *end, pm_diagnostic_id_t diag_id, ...);
122
-
123
- /**
124
- * Deallocate the internal state of the given diagnostic list.
125
- *
126
- * @param list The list to deallocate.
127
- */
128
- void pm_diagnostic_list_free(pm_list_t *list);
129
-
130
- #endif
@@ -1,68 +0,0 @@
1
- module Prism::DSL
2
- sig { params(string: String).returns(Prism::Source) }
3
- def source(string); end
4
-
5
- sig { params(source: Prism::Source, start_offset: Integer, length: Integer).returns(Prism::Location) }
6
- def location(source: default_source, start_offset: 0, length: 0); end
7
- <%- nodes.each do |node| -%>
8
- <%-
9
- params = [
10
- ["source", "default_source", "Prism::Source"],
11
- ["node_id", "0", "Integer"],
12
- ["location", "default_location", "Prism::Location"],
13
- ["flags", "0", "Integer"]
14
- ].concat(node.fields.map { |field|
15
- case field
16
- when Prism::Template::NodeField
17
- kind = field.specific_kind || field.union_kind&.first
18
- if kind.nil?
19
- [field.name, "default_node(source, location)", field.rbi_class]
20
- else
21
- [field.name, %Q{#{kind.gsub(/(?<=.)[A-Z]/, "_\\0").downcase}(source: source)}, field.rbi_class]
22
- end
23
- when Prism::Template::OptionalNodeField
24
- [field.name, "nil", field.rbi_class]
25
- when Prism::Template::NodeListField
26
- [field.name, "[]", field.rbi_class]
27
- when Prism::Template::ConstantField
28
- [field.name, ":\"\"", field.rbi_class]
29
- when Prism::Template::OptionalConstantField
30
- [field.name, "nil", field.rbi_class]
31
- when Prism::Template::ConstantListField
32
- [field.name, "[]", field.rbi_class]
33
- when Prism::Template::StringField
34
- [field.name, "\"\"", field.rbi_class]
35
- when Prism::Template::LocationField
36
- [field.name, "location", field.rbi_class]
37
- when Prism::Template::OptionalLocationField
38
- [field.name, "nil", field.rbi_class]
39
- when Prism::Template::UInt8Field, Prism::Template::UInt32Field, Prism::Template::IntegerField
40
- [field.name, "0", field.rbi_class]
41
- when Prism::Template::DoubleField
42
- [field.name, "0.0", field.rbi_class]
43
- else
44
- raise
45
- end
46
- })
47
- -%>
48
-
49
- sig { params(<%= params.map { |(name, _, type)| "#{name}: #{type}" }.join(", ") %>).returns(Prism::<%= node.name %>) }
50
- def <%= node.human %>(<%= params.map { |(name, default, _)| "#{name}: #{default}" }.join(", ") %>); end
51
- <%- end -%>
52
- <%- flags.each do |flag| -%>
53
-
54
- sig { params(name: Symbol).returns(Integer) }
55
- def <%= flag.human.chomp("s") %>(name); end
56
- <%- end -%>
57
-
58
- private
59
-
60
- sig { returns(Prism::Source) }
61
- def default_source; end
62
-
63
- sig { returns(Prism::Location) }
64
- def default_location; end
65
-
66
- sig { params(source: Prism::Source, location: Prism::Location).returns(Prism::Node) }
67
- def default_node(source, location); end
68
- end
@@ -1,167 +0,0 @@
1
- class Prism::Node
2
- abstract!
3
-
4
- sig { returns(Prism::Source) }
5
- def source; end
6
-
7
- sig { returns(Integer) }
8
- def node_id; end
9
-
10
- sig { returns(Prism::Location) }
11
- def location; end
12
-
13
- sig{ returns(Integer) }
14
- def flags; end
15
-
16
- sig { returns(T::Boolean) }
17
- def newline?; end
18
-
19
- sig { returns(T::Boolean) }
20
- def static_literal?; end
21
-
22
- sig { returns(Integer) }
23
- def start_offset; end
24
-
25
- sig { returns(Integer) }
26
- def end_offset; end
27
-
28
- sig { returns(T::Array[String]) }
29
- def source_lines; end
30
-
31
- sig { returns(T::Array[String]) }
32
- def script_lines; end
33
-
34
- sig { returns(String) }
35
- def slice; end
36
-
37
- sig { returns(String) }
38
- def slice_lines; end
39
-
40
- sig { params(q: T.untyped).void }
41
- def pretty_print(q); end
42
-
43
- sig { returns(String) }
44
- def to_dot; end
45
-
46
- sig { params(line: Integer, column: Integer).returns(T::Array[Prism::Node]) }
47
- def tunnel(line, column); end
48
-
49
- sig { params(block: T.proc.params(node: Prism::Node).returns(T::Boolean)).returns(T.nilable(Prism::Node)) }
50
- def breadth_first_search(&block); end
51
-
52
- sig { params(block: T.proc.params(node: Prism::Node).returns(T::Boolean)).returns(T::Array[Prism::Node]) }
53
- def breadth_first_search_all(&block); end
54
-
55
- sig { abstract.params(visitor: Prism::Visitor).returns(T.untyped) }
56
- def accept(visitor); end
57
-
58
- sig { abstract.returns(T::Array[T.nilable(Prism::Node)]) }
59
- def child_nodes; end
60
-
61
- sig { abstract.returns(T::Array[T.nilable(Prism::Node)]) }
62
- def deconstruct; end
63
-
64
- sig { abstract.returns(T::Array[Prism::Node]) }
65
- def compact_child_nodes; end
66
-
67
- sig { abstract.returns(T::Array[T.any(Prism::Node, Prism::Location)]) }
68
- def comment_targets; end
69
-
70
- sig { abstract.returns(T::Array[Prism::Reflection::Field]) }
71
- def fields; end
72
-
73
- sig { abstract.returns(Symbol) }
74
- def type; end
75
-
76
- sig { abstract.returns(String) }
77
- def inspect; end
78
- end
79
- <%- nodes.each do |node| -%>
80
-
81
- <%- node.each_comment_line do |line| -%>
82
- #<%= line %>
83
- <%- end -%>
84
- class Prism::<%= node.name -%> < Prism::Node
85
- <%- if (node_flags = node.flags) -%>
86
- <%- node_flags.values.each do |value| -%>
87
- sig { returns(T::Boolean) }
88
- def <%= value.name.downcase %>?; end
89
-
90
- <%- end -%>
91
- <%- end -%>
92
- <%- node.fields.each do |field| -%>
93
- sig { returns(<%= field.rbi_class %>) }
94
- def <%= field.name %>; end
95
-
96
- <%- end -%>
97
- sig { params(<%= ["source: Prism::Source", "node_id: Integer", "location: Prism::Location", "flags: Integer", *node.fields.map { |field| "#{field.name}: #{field.rbi_class}" }].join(", ") %>).void }
98
- def initialize(<%= ["source", "node_id", "location", "flags", *node.fields.map(&:name)].join(", ") %>); end
99
-
100
- sig { override.params(visitor: Prism::Visitor).returns(T.untyped) }
101
- def accept(visitor); end
102
-
103
- sig { override.returns(T::Array[T.nilable(Prism::Node)]) }
104
- def child_nodes; end
105
-
106
- sig { override.returns(T::Array[T.nilable(Prism::Node)]) }
107
- def deconstruct; end
108
-
109
- sig { override.returns(T::Array[Prism::Node]) }
110
- def compact_child_nodes; end
111
-
112
- sig { override.returns(T::Array[T.any(Prism::Node, Prism::Location)]) }
113
- def comment_targets; end
114
-
115
- sig { params(<%= (["node_id: Integer", "location: Prism::Location", "flags: Integer"] + node.fields.map { |field| "#{field.name}: #{field.rbi_class}" }).join(", ") %>).returns(Prism::<%= node.name %>) }
116
- def copy(<%= (["node_id", "location", "flags"] + node.fields.map(&:name)).map { |field| "#{field}: self.#{field}" }.join(", ") %>); end
117
-
118
- sig { params(keys: T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, T.untyped]) }
119
- def deconstruct_keys(keys); end
120
- <%- node.fields.each do |field| -%>
121
- <%- case field -%>
122
- <%- when Prism::Template::LocationField -%>
123
- <%- raise unless field.name.end_with?("_loc") -%>
124
- <%- next if node.fields.any? { |other| other.name == field.name.delete_suffix("_loc") } -%>
125
-
126
- sig { returns(String) }
127
- def <%= field.name.delete_suffix("_loc") %>; end
128
- <%- when Prism::Template::OptionalLocationField -%>
129
- <%- raise unless field.name.end_with?("_loc") -%>
130
- <%- next if node.fields.any? { |other| other.name == field.name.delete_suffix("_loc") } -%>
131
-
132
- sig { returns(T.nilable(String)) }
133
- def <%= field.name.delete_suffix("_loc") %>; end
134
- <%- end -%>
135
- <%- end -%>
136
-
137
- sig { override.returns(T::Array[Prism::Reflection::Field]) }
138
- def fields; end
139
-
140
- sig { override.returns(String) }
141
- def inspect; end
142
-
143
- sig { override.returns(Symbol) }
144
- def type; end
145
- end
146
- <%- end -%>
147
- <%- flags.each do |flag| -%>
148
-
149
- # <%= flag.comment %>
150
- module Prism::<%= flag.name %>
151
- <%- flag.values.each_with_index do |value, index| -%>
152
- # <%= value.comment %>
153
- <%= value.name %> = T.let(1 << <%= index + Prism::Template::COMMON_FLAGS_COUNT %>, Integer)
154
- <%- end -%>
155
- end
156
- <%- end -%>
157
-
158
- # The flags that are common to all nodes.
159
- module Prism::NodeFlags
160
- # A flag to indicate that the node is a candidate to emit a :line event
161
- # through tracepoint when compiled.
162
- NEWLINE = T.let(1, Integer)
163
-
164
- # A flag to indicate that the value that the node represents is a value that
165
- # can be determined at parse-time.
166
- STATIC_LITERAL = T.let(2, Integer)
167
- end
@@ -1,18 +0,0 @@
1
- class Prism::BasicVisitor
2
- sig { params(node: T.nilable(Prism::Node)).void }
3
- def visit(node); end
4
-
5
- sig { params(nodes: T::Array[T.nilable(Prism::Node)]).void }
6
- def visit_all(nodes); end
7
-
8
- sig { params(node: Prism::Node).void }
9
- def visit_child_nodes(node); end
10
- end
11
-
12
- class Prism::Visitor < Prism::BasicVisitor
13
- <%- nodes.each_with_index do |node, index| -%>
14
- <%= "\n" if index != 0 -%>
15
- sig { params(node: Prism::<%= node.name %>).void }
16
- def visit_<%= node.human %>(node); end
17
- <%- end -%>
18
- end
@@ -1,45 +0,0 @@
1
- module Prism
2
- class DotVisitor < Visitor
3
- class Field
4
- attr_reader name: String
5
- attr_reader value: String?
6
- attr_reader port: bool
7
-
8
- def initialize: (String name, String? value, bool port) -> void
9
- def to_dot: () -> String
10
- end
11
-
12
- class Table
13
- attr_reader name: String
14
- attr_reader fields: Array[Field]
15
-
16
- def initialize: (String name) -> void
17
- def field: (String name, ?String? value, ?port: bool) -> void
18
- def to_dot: () -> String
19
- end
20
-
21
- class Digraph
22
- attr_reader nodes: Array[String]
23
- attr_reader waypoints: Array[String]
24
- attr_reader edges: Array[String]
25
-
26
- def initialize: () -> void
27
- def node: (String value) -> void
28
- def waypoint: (String value) -> void
29
- def edge: (String value) -> void
30
-
31
- def to_dot: () -> String
32
- end
33
-
34
- attr_reader digraph: Digraph
35
-
36
- private
37
-
38
- def node_id: (Prism::node node) -> String
39
- def location_inspect: (Location location) -> String
40
-
41
- <%- flags.each do |flag| -%>
42
- def <%= flag.human %>_inspect: (<%= nodes.filter_map { |node| node.name if node.flags == flag }.join(" | ") %> node) -> String
43
- <%- end -%>
44
- end
45
- end
@@ -1,31 +0,0 @@
1
- module Prism
2
- module DSL
3
- def source: (String string) -> Source
4
-
5
- def location: (?source: Source, ?start_offset: Integer, ?length: Integer) -> Location
6
- <%- nodes.each do |node| -%>
7
- <%-
8
- params = [
9
- ["source", "Source"],
10
- ["node_id", "Integer"],
11
- ["location", "Location"],
12
- ["flags", "Integer"]
13
- ].concat(node.fields.map { |field| [field.name, field.rbs_class] })
14
- -%>
15
-
16
- def <%= node.human %>: (<%= params.map { |(name, type)| "?#{name}: #{type}" }.join(", ") %>) -> <%= node.name %>
17
- <%- end -%>
18
- <%- flags.each do |flag| -%>
19
-
20
- def <%= flag.human.chomp("s") %>: (Symbol name) -> Integer
21
- <%- end -%>
22
-
23
- private
24
-
25
- def default_source: () -> Source
26
-
27
- def default_location: () -> Location
28
-
29
- def default_node: (Source source, Location location) -> node
30
- end
31
- end
@@ -1,7 +0,0 @@
1
- module Prism
2
- class MutationCompiler < Compiler
3
- <%- nodes.each do |node| -%>
4
- def visit_<%= node.human %>: (<%= node.name %>) -> node?
5
- <%- end -%>
6
- end
7
- end
@@ -1,136 +0,0 @@
1
- module Prism
2
- class Node
3
- attr_reader source: Source
4
- attr_reader node_id: Integer
5
- attr_reader location: Location
6
- attr_reader flags: Integer
7
-
8
- def newline?: () -> bool
9
- def static_literal?: () -> bool
10
-
11
- def accept: (_Visitor) -> void
12
- def child_nodes: () -> Array[Prism::node?]
13
- def comment_targets: () -> Array[Prism::node | Location]
14
- def compact_child_nodes: () -> Array[Prism::node]
15
- def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator[Prism::node]
16
- def self.fields: () -> Array[Prism::Reflection::Field]
17
- def type: () -> Symbol
18
- def self.type: () -> Symbol
19
-
20
- def source_lines: () -> Array[String]
21
- alias script_lines source_lines
22
- def slice: () -> String
23
- def slice_lines: () -> String
24
- def pretty_print: (untyped q) -> untyped
25
- def to_dot: () -> String
26
- def tunnel: (Integer line, Integer column) -> Array[Prism::node]
27
- def breadth_first_search: () { (Prism::node) -> bool } -> Prism::node?
28
- alias find breadth_first_search
29
- def breadth_first_search_all: () { (Prism::node) -> bool } -> Array[Prism::node]
30
- alias find_all breadth_first_search_all
31
- def newline!: (Array[untyped]) -> void
32
-
33
- def save: (_Repository repository) -> void
34
- def save_location: (_Repository repository) -> void
35
-
36
- def leading_comments: () -> Array[comment]
37
- def trailing_comments: () -> Array[comment]
38
- def comments: () -> Array[comment]
39
-
40
- def start_offset: () -> Integer
41
- def start_character_offset: () -> Integer
42
- def start_code_units_offset: (Encoding encoding) -> Integer
43
- def cached_start_code_units_offset: (_CodeUnitsCache cache) -> Integer
44
-
45
- def end_offset: () -> Integer
46
- def end_character_offset: () -> Integer
47
- def end_code_units_offset: (Encoding encoding) -> Integer
48
- def cached_end_code_units_offset: (_CodeUnitsCache cache) -> Integer
49
-
50
- def start_line: () -> Integer
51
- def end_line: () -> Integer
52
-
53
- def start_column: () -> Integer
54
- def start_character_column: () -> Integer
55
- def start_code_units_column: (Encoding encoding) -> Integer
56
- def cached_start_code_units_column: (_CodeUnitsCache cache) -> Integer
57
-
58
- def end_column: () -> Integer
59
- def end_character_column: () -> Integer
60
- def end_code_units_column: (Encoding encoding) -> Integer
61
- def cached_end_code_units_column: (_CodeUnitsCache cache) -> Integer
62
- end
63
-
64
- # Methods implemented by every subclass of Node
65
- interface _Node
66
- def deconstruct: () -> Array[Prism::node?]
67
- def inspect: () -> String
68
- end
69
-
70
- type node = Node & _Node
71
-
72
- interface _Repository
73
- def enter: (Integer node_id, Symbol field_name) -> void
74
- end
75
-
76
- <%- nodes.each do |node| -%>
77
-
78
- <%- node.each_comment_line do |line| -%>
79
- #<%= line %>
80
- <%- end -%>
81
- class <%= node.name -%> < Node
82
- include _Node
83
- <%- if (node_flags = node.flags) -%>
84
-
85
- <%- node_flags.values.each do |value| -%>
86
- def <%= value.name.downcase %>?: () -> bool
87
- <%- end -%>
88
- <%- end -%>
89
-
90
- <%- node.fields.each do |field| -%>
91
- attr_reader <%= field.name %>: <%= field.rbs_class %>
92
- <%- end -%>
93
- <%- if (locations = node.fields.select { |field| field.is_a?(Prism::Template::LocationField) || field.is_a?(Prism::Template::OptionalLocationField) }) -%>
94
-
95
- <%- locations.each do |field| -%>
96
- def save_<%= field.name %>: (_Repository repository) -> void
97
- <%- end -%>
98
- <%- end -%>
99
-
100
- def initialize: (<%= ["Source source", "Integer node_id", "Location location", "Integer flags", *node.fields.map { |field| "#{field.rbs_class} #{field.name}" }].join(", ") %>) -> void
101
- def copy: (<%= (["?node_id: Integer", "?location: Location", "?flags: Integer"] + node.fields.map { |field| "?#{field.name}: #{field.rbs_class}" }).join(", ") %>) -> <%= node.name %>
102
- def deconstruct_keys: (Array[Symbol] keys) -> { <%= (["node_id: Integer", "location: Location"] + node.fields.map { |field| "#{field.name}: #{field.rbs_class}" }).join(", ") %> }
103
- <%- node.fields.each do |field| -%>
104
- <%- case field -%>
105
- <%- when Prism::Template::LocationField -%>
106
- <%- raise unless field.name.end_with?("_loc") -%>
107
- <%- next if node.fields.any? { |other| other.name == field.name.delete_suffix("_loc") } -%>
108
- def <%= field.name.delete_suffix("_loc") %>: () -> String
109
- <%- when Prism::Template::OptionalLocationField -%>
110
- <%- raise unless field.name.end_with?("_loc") -%>
111
- <%- next if node.fields.any? { |other| other.name == field.name.delete_suffix("_loc") } -%>
112
- def <%= field.name.delete_suffix("_loc") %>: () -> String?
113
- <%- end -%>
114
- <%- end -%>
115
- def type: () -> :<%= node.human %>
116
- | ...
117
- def self.type: () -> :<%= node.human %>
118
- end
119
- <%- end -%>
120
- <%- flags.each do |flag| -%>
121
-
122
- # <%= flag.comment %>
123
- module <%= flag.name %>
124
- <%- flag.values.each do |value| -%>
125
- # <%= value.comment %>
126
- <%= value.name %>: Integer
127
- <%- end -%>
128
- end
129
- <%- end -%>
130
-
131
- # The flags that are common to all nodes.
132
- module NodeFlags
133
- NEWLINE: Integer
134
- STATIC_LITERAL: Integer
135
- end
136
- end
@@ -1,17 +0,0 @@
1
- module Prism
2
- class BasicVisitor
3
- def visit: (Prism::node?) -> void
4
- def visit_all: (Array[Prism::node?]) -> void
5
- def visit_child_nodes: (Prism::node) -> void
6
- end
7
-
8
- interface _Visitor
9
- <%- nodes.each do |node| -%>
10
- def visit_<%= node.human %>: (<%= node.name %>) -> void
11
- <%- end -%>
12
- end
13
-
14
- class Visitor < BasicVisitor
15
- include _Visitor
16
- end
17
- end