herb 0.7.2-aarch64-linux-gnu → 0.7.4-aarch64-linux-gnu

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 (133) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +2 -0
  3. data/README.md +1 -1
  4. data/Rakefile +46 -1
  5. data/config.yml +714 -0
  6. data/ext/herb/extconf.rb +2 -1
  7. data/ext/herb/nodes.c +1 -1
  8. data/herb.gemspec +3 -0
  9. data/lib/herb/3.0/herb.so +0 -0
  10. data/lib/herb/3.1/herb.so +0 -0
  11. data/lib/herb/3.2/herb.so +0 -0
  12. data/lib/herb/3.3/herb.so +0 -0
  13. data/lib/herb/3.4/herb.so +0 -0
  14. data/lib/herb/engine.rb +8 -1
  15. data/lib/herb/version.rb +1 -1
  16. data/src/analyze.c +5 -9
  17. data/src/analyze_helpers.c +17 -6
  18. data/src/herb.c +2 -2
  19. data/src/include/parser.h +2 -2
  20. data/src/include/pretty_print.h +1 -1
  21. data/src/include/version.h +1 -1
  22. data/src/parser.c +3 -2
  23. data/src/pretty_print.c +1 -1
  24. data/templates/ext/herb/error_helpers.c.erb +85 -0
  25. data/templates/ext/herb/error_helpers.h.erb +12 -0
  26. data/templates/ext/herb/nodes.c.erb +90 -0
  27. data/templates/ext/herb/nodes.h.erb +9 -0
  28. data/templates/javascript/packages/core/src/errors.ts.erb +193 -0
  29. data/templates/javascript/packages/core/src/node-type-guards.ts.erb +325 -0
  30. data/templates/javascript/packages/core/src/nodes.ts.erb +414 -0
  31. data/templates/javascript/packages/core/src/visitor.ts.erb +29 -0
  32. data/templates/javascript/packages/node/extension/error_helpers.cpp.erb +113 -0
  33. data/templates/javascript/packages/node/extension/error_helpers.h.erb +17 -0
  34. data/templates/javascript/packages/node/extension/nodes.cpp.erb +111 -0
  35. data/templates/javascript/packages/node/extension/nodes.h.erb +17 -0
  36. data/templates/lib/herb/ast/nodes.rb.erb +117 -0
  37. data/templates/lib/herb/errors.rb.erb +106 -0
  38. data/templates/lib/herb/visitor.rb.erb +28 -0
  39. data/templates/sig/serialized_ast_errors.rbs.erb +10 -0
  40. data/templates/sig/serialized_ast_nodes.rbs.erb +10 -0
  41. data/templates/src/ast_nodes.c.erb +145 -0
  42. data/templates/src/ast_pretty_print.c.erb +97 -0
  43. data/templates/src/errors.c.erb +245 -0
  44. data/templates/src/include/ast_nodes.h.erb +46 -0
  45. data/templates/src/include/ast_pretty_print.h.erb +14 -0
  46. data/templates/src/include/errors.h.erb +58 -0
  47. data/templates/src/visitor.c.erb +47 -0
  48. data/templates/template.rb +406 -0
  49. data/templates/wasm/error_helpers.cpp.erb +93 -0
  50. data/templates/wasm/error_helpers.h.erb +15 -0
  51. data/templates/wasm/nodes.cpp.erb +79 -0
  52. data/templates/wasm/nodes.h.erb +15 -0
  53. data/vendor/prism/Rakefile +75 -0
  54. data/vendor/prism/config.yml +4713 -0
  55. data/vendor/prism/include/prism/ast.h +8190 -0
  56. data/vendor/prism/include/prism/defines.h +260 -0
  57. data/vendor/prism/include/prism/diagnostic.h +455 -0
  58. data/vendor/prism/include/prism/encoding.h +283 -0
  59. data/vendor/prism/include/prism/node.h +129 -0
  60. data/vendor/prism/include/prism/options.h +482 -0
  61. data/vendor/prism/include/prism/pack.h +163 -0
  62. data/vendor/prism/include/prism/parser.h +933 -0
  63. data/vendor/prism/include/prism/prettyprint.h +34 -0
  64. data/vendor/prism/include/prism/regexp.h +43 -0
  65. data/vendor/prism/include/prism/static_literals.h +121 -0
  66. data/vendor/prism/include/prism/util/pm_buffer.h +236 -0
  67. data/vendor/prism/include/prism/util/pm_char.h +204 -0
  68. data/vendor/prism/include/prism/util/pm_constant_pool.h +218 -0
  69. data/vendor/prism/include/prism/util/pm_integer.h +130 -0
  70. data/vendor/prism/include/prism/util/pm_list.h +103 -0
  71. data/vendor/prism/include/prism/util/pm_memchr.h +29 -0
  72. data/vendor/prism/include/prism/util/pm_newline_list.h +113 -0
  73. data/vendor/prism/include/prism/util/pm_string.h +200 -0
  74. data/vendor/prism/include/prism/util/pm_strncasecmp.h +32 -0
  75. data/vendor/prism/include/prism/util/pm_strpbrk.h +46 -0
  76. data/vendor/prism/include/prism/version.h +29 -0
  77. data/vendor/prism/include/prism.h +408 -0
  78. data/vendor/prism/src/diagnostic.c +848 -0
  79. data/vendor/prism/src/encoding.c +5235 -0
  80. data/vendor/prism/src/node.c +8676 -0
  81. data/vendor/prism/src/options.c +328 -0
  82. data/vendor/prism/src/pack.c +509 -0
  83. data/vendor/prism/src/prettyprint.c +8941 -0
  84. data/vendor/prism/src/prism.c +23302 -0
  85. data/vendor/prism/src/regexp.c +790 -0
  86. data/vendor/prism/src/serialize.c +2268 -0
  87. data/vendor/prism/src/static_literals.c +617 -0
  88. data/vendor/prism/src/token_type.c +703 -0
  89. data/vendor/prism/src/util/pm_buffer.c +357 -0
  90. data/vendor/prism/src/util/pm_char.c +318 -0
  91. data/vendor/prism/src/util/pm_constant_pool.c +342 -0
  92. data/vendor/prism/src/util/pm_integer.c +670 -0
  93. data/vendor/prism/src/util/pm_list.c +49 -0
  94. data/vendor/prism/src/util/pm_memchr.c +35 -0
  95. data/vendor/prism/src/util/pm_newline_list.c +125 -0
  96. data/vendor/prism/src/util/pm_string.c +383 -0
  97. data/vendor/prism/src/util/pm_strncasecmp.c +36 -0
  98. data/vendor/prism/src/util/pm_strpbrk.c +206 -0
  99. data/vendor/prism/templates/ext/prism/api_node.c.erb +282 -0
  100. data/vendor/prism/templates/include/prism/ast.h.erb +226 -0
  101. data/vendor/prism/templates/include/prism/diagnostic.h.erb +130 -0
  102. data/vendor/prism/templates/java/org/prism/AbstractNodeVisitor.java.erb +22 -0
  103. data/vendor/prism/templates/java/org/prism/Loader.java.erb +434 -0
  104. data/vendor/prism/templates/java/org/prism/Nodes.java.erb +403 -0
  105. data/vendor/prism/templates/javascript/src/deserialize.js.erb +448 -0
  106. data/vendor/prism/templates/javascript/src/nodes.js.erb +197 -0
  107. data/vendor/prism/templates/javascript/src/visitor.js.erb +78 -0
  108. data/vendor/prism/templates/lib/prism/compiler.rb.erb +43 -0
  109. data/vendor/prism/templates/lib/prism/dispatcher.rb.erb +103 -0
  110. data/vendor/prism/templates/lib/prism/dot_visitor.rb.erb +189 -0
  111. data/vendor/prism/templates/lib/prism/dsl.rb.erb +133 -0
  112. data/vendor/prism/templates/lib/prism/inspect_visitor.rb.erb +131 -0
  113. data/vendor/prism/templates/lib/prism/mutation_compiler.rb.erb +19 -0
  114. data/vendor/prism/templates/lib/prism/node.rb.erb +515 -0
  115. data/vendor/prism/templates/lib/prism/reflection.rb.erb +136 -0
  116. data/vendor/prism/templates/lib/prism/serialize.rb.erb +602 -0
  117. data/vendor/prism/templates/lib/prism/visitor.rb.erb +55 -0
  118. data/vendor/prism/templates/rbi/prism/dsl.rbi.erb +68 -0
  119. data/vendor/prism/templates/rbi/prism/node.rbi.erb +164 -0
  120. data/vendor/prism/templates/rbi/prism/visitor.rbi.erb +18 -0
  121. data/vendor/prism/templates/sig/prism/_private/dot_visitor.rbs.erb +45 -0
  122. data/vendor/prism/templates/sig/prism/dsl.rbs.erb +31 -0
  123. data/vendor/prism/templates/sig/prism/mutation_compiler.rbs.erb +7 -0
  124. data/vendor/prism/templates/sig/prism/node.rbs.erb +132 -0
  125. data/vendor/prism/templates/sig/prism/visitor.rbs.erb +17 -0
  126. data/vendor/prism/templates/sig/prism.rbs.erb +89 -0
  127. data/vendor/prism/templates/src/diagnostic.c.erb +523 -0
  128. data/vendor/prism/templates/src/node.c.erb +333 -0
  129. data/vendor/prism/templates/src/prettyprint.c.erb +166 -0
  130. data/vendor/prism/templates/src/serialize.c.erb +406 -0
  131. data/vendor/prism/templates/src/token_type.c.erb +369 -0
  132. data/vendor/prism/templates/template.rb +689 -0
  133. metadata +112 -2
@@ -0,0 +1,226 @@
1
+ /**
2
+ * @file ast.h
3
+ *
4
+ * The abstract syntax tree.
5
+ *
6
+ * --
7
+ */
8
+ #ifndef PRISM_AST_H
9
+ #define PRISM_AST_H
10
+
11
+ #include "prism/defines.h"
12
+ #include "prism/util/pm_constant_pool.h"
13
+ #include "prism/util/pm_integer.h"
14
+ #include "prism/util/pm_string.h"
15
+
16
+ #include <assert.h>
17
+ #include <stddef.h>
18
+ #include <stdint.h>
19
+
20
+ /**
21
+ * This enum represents every type of token in the Ruby source.
22
+ */
23
+ typedef enum pm_token_type {
24
+ <%- tokens.each do |token| -%>
25
+ /** <%= token.comment %> */
26
+ PM_TOKEN_<%= token.name %><%= " = #{token.value}" if token.value %>,
27
+
28
+ <%- end -%>
29
+ /** The maximum token value. */
30
+ PM_TOKEN_MAXIMUM,
31
+ } pm_token_type_t;
32
+
33
+ /**
34
+ * This struct represents a token in the Ruby source. We use it to track both
35
+ * type and location information.
36
+ */
37
+ typedef struct {
38
+ /** The type of the token. */
39
+ pm_token_type_t type;
40
+
41
+ /** A pointer to the start location of the token in the source. */
42
+ const uint8_t *start;
43
+
44
+ /** A pointer to the end location of the token in the source. */
45
+ const uint8_t *end;
46
+ } pm_token_t;
47
+
48
+ /**
49
+ * This represents a range of bytes in the source string to which a node or
50
+ * token corresponds.
51
+ */
52
+ typedef struct {
53
+ /** A pointer to the start location of the range in the source. */
54
+ const uint8_t *start;
55
+
56
+ /** A pointer to the end location of the range in the source. */
57
+ const uint8_t *end;
58
+ } pm_location_t;
59
+
60
+ struct pm_node;
61
+
62
+ /**
63
+ * A list of nodes in the source, most often used for lists of children.
64
+ */
65
+ typedef struct pm_node_list {
66
+ /** The number of nodes in the list. */
67
+ size_t size;
68
+
69
+ /** The capacity of the list that has been allocated. */
70
+ size_t capacity;
71
+
72
+ /** The nodes in the list. */
73
+ struct pm_node **nodes;
74
+ } pm_node_list_t;
75
+
76
+ /**
77
+ * This enum represents every type of node in the Ruby syntax tree.
78
+ */
79
+ enum pm_node_type {
80
+ <%- nodes.each_with_index do |node, index| -%>
81
+ /** <%= node.name %> */
82
+ <%= node.type %> = <%= index + 1 %>,
83
+
84
+ <%- end -%>
85
+ /** A special kind of node used for compilation. */
86
+ PM_SCOPE_NODE
87
+ };
88
+
89
+ /**
90
+ * This is the type of node embedded in the node struct. We explicitly control
91
+ * the size of it here to avoid having the variable-width enum.
92
+ */
93
+ typedef uint16_t pm_node_type_t;
94
+
95
+ /**
96
+ * These are the flags embedded in the node struct. We explicitly control the
97
+ * size of it here to avoid having the variable-width enum.
98
+ */
99
+ typedef uint16_t pm_node_flags_t;
100
+
101
+ /**
102
+ * We store the flags enum in every node in the tree. Some flags are common to
103
+ * all nodes (the ones listed below). Others are specific to certain node types.
104
+ */
105
+ static const pm_node_flags_t PM_NODE_FLAG_NEWLINE = 0x1;
106
+ static const pm_node_flags_t PM_NODE_FLAG_STATIC_LITERAL = 0x2;
107
+
108
+ /**
109
+ * Cast the type to an enum to allow the compiler to provide exhaustiveness
110
+ * checking.
111
+ */
112
+ #define PM_NODE_TYPE(node) ((enum pm_node_type) (node)->type)
113
+
114
+ /**
115
+ * Return true if the type of the given node matches the given type.
116
+ */
117
+ #define PM_NODE_TYPE_P(node, type) (PM_NODE_TYPE(node) == (type))
118
+
119
+ /**
120
+ * Return true if the given flag is set on the given node.
121
+ */
122
+ #define PM_NODE_FLAG_P(node, flag) ((((pm_node_t *)(node))->flags & (flag)) != 0)
123
+
124
+ /**
125
+ * This is the base structure that represents a node in the syntax tree. It is
126
+ * embedded into every node type.
127
+ */
128
+ typedef struct pm_node {
129
+ /**
130
+ * This represents the type of the node. It somewhat maps to the nodes that
131
+ * existed in the original grammar and ripper, but it's not a 1:1 mapping.
132
+ */
133
+ pm_node_type_t type;
134
+
135
+ /**
136
+ * This represents any flags on the node. Some are common to all nodes, and
137
+ * some are specific to the type of node.
138
+ */
139
+ pm_node_flags_t flags;
140
+
141
+ /**
142
+ * The unique identifier for this node, which is deterministic based on the
143
+ * source. It is used to identify unique nodes across parses.
144
+ */
145
+ uint32_t node_id;
146
+
147
+ /**
148
+ * This is the location of the node in the source. It's a range of bytes
149
+ * containing a start and an end.
150
+ */
151
+ pm_location_t location;
152
+ } pm_node_t;
153
+ <%- nodes.each do |node| -%>
154
+
155
+ /**
156
+ * <%= node.name %>
157
+ *
158
+ <%- node.each_comment_line do |line| -%>
159
+ *<%= line %>
160
+ <%- end -%>
161
+ *
162
+ * Type: ::<%= node.type %>
163
+ <% if (node_flags = node.flags) %>
164
+ * Flags (#pm_<%= node_flags.human %>):
165
+ <%- node_flags.values.each do |value| -%>
166
+ * * ::PM_<%= node_flags.human.upcase %>_<%= value.name %>
167
+ <%- end -%>
168
+ <%- end -%>
169
+ *
170
+ * @extends pm_node_t
171
+ */
172
+ typedef struct pm_<%= node.human %> {
173
+ /** The embedded base node. */
174
+ pm_node_t base;
175
+
176
+ <%- node.fields.each do |field| -%>
177
+
178
+ /**
179
+ * <%= node.name %>#<%= field.name %>
180
+ <%- if field.comment -%>
181
+ *
182
+ <%- field.each_comment_line do |line| -%>
183
+ *<%= line %>
184
+ <%- end -%>
185
+ <%- end -%>
186
+ */
187
+ <%= case field
188
+ when Prism::Template::NodeField, Prism::Template::OptionalNodeField then "struct #{field.c_type} *#{field.name}"
189
+ when Prism::Template::NodeListField then "struct pm_node_list #{field.name}"
190
+ when Prism::Template::ConstantField, Prism::Template::OptionalConstantField then "pm_constant_id_t #{field.name}"
191
+ when Prism::Template::ConstantListField then "pm_constant_id_list_t #{field.name}"
192
+ when Prism::Template::StringField then "pm_string_t #{field.name}"
193
+ when Prism::Template::LocationField, Prism::Template::OptionalLocationField then "pm_location_t #{field.name}"
194
+ when Prism::Template::UInt8Field then "uint8_t #{field.name}"
195
+ when Prism::Template::UInt32Field then "uint32_t #{field.name}"
196
+ when Prism::Template::IntegerField then "pm_integer_t #{field.name}"
197
+ when Prism::Template::DoubleField then "double #{field.name}"
198
+ else raise field.class.name
199
+ end
200
+ %>;
201
+ <%- end -%>
202
+ } pm_<%= node.human %>_t;
203
+ <%- end -%>
204
+ <%- flags.each do |flag| -%>
205
+
206
+ /**
207
+ * <%= flag.comment %>
208
+ */
209
+ typedef enum pm_<%= flag.human %> {
210
+ <%- flag.values.each_with_index do |value, index| -%>
211
+ <%= "\n" if index > 0 -%>
212
+ /** <%= value.comment %> */
213
+ PM_<%= flag.human.upcase %>_<%= value.name %> = <%= 1 << (index + Prism::Template::COMMON_FLAGS_COUNT) %>,
214
+ <%- end -%>
215
+ } pm_<%= flag.human %>_t;
216
+ <%- end -%>
217
+
218
+ /**
219
+ * When we're serializing to Java, we want to skip serializing the location
220
+ * fields as they won't be used by JRuby or TruffleRuby. This boolean allows us
221
+ * to specify that through the environment. It will never be true except for in
222
+ * those build systems.
223
+ */
224
+ #define PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS <%= Prism::Template::SERIALIZE_ONLY_SEMANTICS_FIELDS ? 1 : 0 %>
225
+
226
+ #endif
@@ -0,0 +1,130 @@
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
@@ -0,0 +1,22 @@
1
+ package org.prism;
2
+
3
+ // GENERATED BY <%= File.basename(__FILE__) %>
4
+ // @formatter:off
5
+ public abstract class AbstractNodeVisitor<T> {
6
+
7
+ protected abstract T defaultVisit(Nodes.Node node);
8
+
9
+ <%- nodes.each do |node| -%>
10
+ /**
11
+ * Visit a <%= node.name %> node.
12
+ *
13
+ * @param node The node to visit.
14
+ * @return The result of visiting the node.
15
+ */
16
+ public T visit<%= node.name -%>(Nodes.<%= node.name -%> node) {
17
+ return defaultVisit(node);
18
+ }
19
+
20
+ <%- end -%>
21
+ }
22
+ // @formatter:on