herb 0.11.1-arm-linux-gnu → 0.11.3-arm-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.
- checksums.yaml +4 -4
- data/Makefile +2 -0
- data/Rakefile +4 -2
- data/config.yml +13 -8
- data/ext/herb/error_helpers.c +3 -3
- data/ext/herb/extconf.rb +8 -31
- data/ext/herb/nodes.c +75 -75
- data/ext/herb/parser_options_helpers.c +26 -0
- data/lib/herb/3.2/herb.so +0 -0
- data/lib/herb/3.3/herb.so +0 -0
- data/lib/herb/3.4/herb.so +0 -0
- data/lib/herb/4.0/herb.so +0 -0
- data/lib/herb/analysis/partial_index.rb +1 -1
- data/lib/herb/analysis/partial_resolution.rb +27 -0
- data/lib/herb/ast/erb_render_node.rb +6 -2
- data/lib/herb/ast/helpers.rb +1 -1
- data/lib/herb/cli.rb +7 -3
- data/lib/herb/configuration.rb +11 -1
- data/lib/herb/dev/classifier.rb +1 -1
- data/lib/herb/dev/runner.rb +5 -2
- data/lib/herb/engine/compiler.rb +44 -12
- data/lib/herb/engine/slots/dynamics_compiler.rb +54 -15
- data/lib/herb/engine/slots/state_compiler.rb +9 -1
- data/lib/herb/engine/slots/state_overrides.rb +17 -3
- data/lib/herb/engine/slots/subtree_compiler.rb +1 -1
- data/lib/herb/engine/slots/visitor.rb +69 -11
- data/lib/herb/engine/visitors/instrumentation_visitor.rb +18 -6
- data/lib/herb/engine.rb +11 -1
- data/lib/herb/errors.rb +7 -7
- data/lib/herb/parser_options.rb +6 -3
- data/lib/herb/project.rb +19 -8
- data/lib/herb/version.rb +1 -1
- data/lib/herb.rb +1 -1
- data/sig/herb/analysis/partial_resolution.rbs +8 -0
- data/sig/herb/ast/erb_render_node.rbs +2 -0
- data/sig/herb/configuration.rbs +3 -0
- data/sig/herb/dev/runner.rbs +2 -2
- data/sig/herb/engine/compiler.rbs +9 -0
- data/sig/herb/engine/slots/dynamics_compiler.rbs +24 -7
- data/sig/herb/engine/slots/state_compiler.rbs +3 -0
- data/sig/herb/engine/slots/state_overrides.rbs +11 -2
- data/sig/herb/engine/slots/visitor.rbs +21 -0
- data/sig/herb/engine/visitors/instrumentation_visitor.rbs +5 -1
- data/sig/herb/engine.rbs +2 -0
- data/sig/herb/errors.rbs +2 -2
- data/sig/herb/parser_options.rbs +6 -4
- data/sig/herb.rbs +2 -2
- data/sig/serialized_ast_errors.rbs +1 -1
- data/src/analyze/action_view/attribute_extraction_helpers.c +40 -21
- data/src/analyze/action_view/generated_handlers.c +36 -36
- data/src/analyze/action_view/image_tag.c +7 -3
- data/src/analyze/action_view/javascript_include_tag.c +6 -3
- data/src/analyze/action_view/link_to.c +23 -23
- data/src/analyze/action_view/registry.c +7 -3
- data/src/analyze/action_view/tag_helper_node_builders.c +6 -13
- data/src/analyze/action_view/tag_helpers.c +160 -97
- data/src/analyze/action_view/turbo_frame_tag.c +5 -4
- data/src/analyze/analyze.c +52 -29
- data/src/analyze/analyze_helpers.c +161 -188
- data/src/analyze/analyzed_ruby.c +8 -7
- data/src/analyze/control_type.c +29 -22
- data/src/analyze/herb_directives.c +16 -20
- data/src/analyze/iteration_nodes.c +69 -24
- data/src/analyze/parse_errors.c +32 -22
- data/src/analyze/postfix_conditionals.c +23 -13
- data/src/analyze/prism_annotate.c +29 -28
- data/src/analyze/render_nodes.c +239 -78
- data/src/analyze/strict_locals.c +14 -15
- data/src/analyze/ternary_conditionals.c +14 -10
- data/src/diff/herb_diff_children.c +1 -1
- data/src/diff/herb_diff_nodes.c +1 -9
- data/src/diff/herb_hash_tree.c +1 -1
- data/src/errors.c +17 -22
- data/src/extract.c +47 -7
- data/src/herb.c +10 -8
- data/src/include/analyze/action_view/tag_helper_handler.h +1 -1
- data/src/include/analyze/action_view/tag_helper_node_builders.h +1 -0
- data/src/include/analyze/action_view/tag_helpers.h +1 -1
- data/src/include/analyze/analyze.h +3 -2
- data/src/include/analyze/analyzed_ruby.h +4 -2
- data/src/include/analyze/helpers.h +6 -6
- data/src/include/errors.h +3 -3
- data/src/include/herb.h +3 -2
- data/src/include/parser/parser_options.h +5 -0
- data/src/include/prism/prism_context.h +12 -12
- data/src/include/prism/prism_helpers.h +30 -0
- data/src/include/prism_version.h +11 -0
- data/src/include/version.h +1 -1
- data/src/lexer/token.c +2 -2
- data/src/parser/dot_notation.c +15 -5
- data/src/parser/parser_helpers.c +1 -2
- data/src/parser.c +9 -8
- data/src/parser_options_defaults.c +1 -0
- data/src/prism/prism_helpers.c +84 -50
- data/src/prism/ruby_parser.c +20 -20
- data/templates/ext/herb/nodes.c.erb +5 -5
- data/templates/ext/herb/parser_options_helpers.c.erb +33 -0
- data/templates/java/nodes.c.erb +6 -6
- data/templates/java/parser_options_helpers.c.erb +41 -2
- data/templates/java/parser_options_helpers.h.erb +2 -1
- data/templates/javascript/packages/node/extension/nodes.cpp.erb +5 -5
- data/templates/javascript/packages/node/extension/parser_options_helpers.cpp.erb +34 -2
- data/templates/javascript/packages/node/extension/parser_options_helpers.h.erb +1 -1
- data/templates/lib/herb/parser_options.rb.erb +1 -1
- data/templates/rust/src/prism/generated_deserialize.rs.erb +90 -44
- data/templates/rust/src/prism/generated_prettyprint.rs.erb +18 -27
- data/templates/src/analyze/action_view/generated_handlers.c.erb +23 -22
- data/templates/src/diff/herb_diff_nodes.c.erb +1 -9
- data/templates/src/diff/herb_hash_tree.c.erb +1 -1
- data/templates/src/errors.c.erb +2 -2
- data/templates/src/include/parser/parser_options.h.erb +10 -0
- data/templates/src/include/prism_version.h.erb +17 -0
- data/templates/src/parser_options_defaults.c.erb +1 -1
- data/templates/template.rb +17 -2
- data/templates/wasm/nodes.cpp.erb +5 -5
- data/templates/wasm/parser_options_helpers.cpp.erb +24 -0
- data/vendor/prism/Rakefile +76 -7
- data/vendor/prism/config.yml +174 -161
- data/vendor/prism/include/prism/arena.h +45 -0
- data/vendor/prism/include/prism/arena.hpp +42 -0
- data/vendor/prism/include/prism/ast.h +2738 -611
- data/vendor/prism/include/prism/ast.hpp +641 -0
- data/vendor/prism/include/prism/buffer.h +60 -0
- data/vendor/prism/include/prism/buffer.hpp +55 -0
- data/vendor/prism/include/prism/comments.h +72 -0
- data/vendor/prism/include/prism/compiler/accel.h +26 -0
- data/vendor/prism/include/prism/compiler/align.h +36 -0
- data/vendor/prism/include/prism/compiler/assume.h +25 -0
- data/vendor/prism/include/prism/compiler/branch.h +26 -0
- data/vendor/prism/include/prism/compiler/bswap.h +46 -0
- data/vendor/prism/include/prism/compiler/cplusplus.hpp +16 -0
- data/vendor/prism/include/prism/compiler/endianness.h +34 -0
- data/vendor/prism/include/prism/compiler/exceptions.hpp +17 -0
- data/vendor/prism/include/prism/compiler/exported.h +24 -0
- data/vendor/prism/include/prism/compiler/fallthrough.h +22 -0
- data/vendor/prism/include/prism/compiler/filesystem.h +32 -0
- data/vendor/prism/include/prism/compiler/flex_array.h +19 -0
- data/vendor/prism/include/prism/compiler/force_inline.h +21 -0
- data/vendor/prism/include/prism/compiler/format.h +27 -0
- data/vendor/prism/include/prism/compiler/inline.h +17 -0
- data/vendor/prism/include/prism/compiler/lifetimebound.hpp +25 -0
- data/vendor/prism/include/prism/compiler/nodiscard.h +22 -0
- data/vendor/prism/include/prism/compiler/nonnull.h +18 -0
- data/vendor/prism/include/prism/compiler/unused.h +18 -0
- data/vendor/prism/include/prism/constant_pool.h +106 -0
- data/vendor/prism/include/prism/diagnostic.h +55 -402
- data/vendor/prism/include/prism/errors_format.h +61 -0
- data/vendor/prism/include/prism/excludes.h +29 -0
- data/vendor/prism/include/prism/integer.h +41 -0
- data/vendor/prism/include/prism/internal/allocator.h +68 -0
- data/vendor/prism/include/prism/internal/allocator_debug.h +88 -0
- data/vendor/prism/include/prism/internal/arena.h +108 -0
- data/vendor/prism/include/prism/internal/bit.h +42 -0
- data/vendor/prism/include/prism/internal/buffer.h +94 -0
- data/vendor/prism/include/prism/internal/char.h +145 -0
- data/vendor/prism/include/prism/internal/comments.h +54 -0
- data/vendor/prism/include/prism/internal/constant_pool.h +152 -0
- data/vendor/prism/include/prism/internal/diagnostic.h +389 -0
- data/vendor/prism/include/prism/{encoding.h → internal/encoding.h} +27 -68
- data/vendor/prism/include/prism/internal/integer.h +68 -0
- data/vendor/prism/include/prism/internal/isinf.h +16 -0
- data/vendor/prism/include/prism/internal/line_offset_list.h +34 -0
- data/vendor/prism/include/prism/{util/pm_list.h → internal/list.h} +11 -52
- data/vendor/prism/include/prism/internal/magic_comments.h +23 -0
- data/vendor/prism/include/prism/internal/memchr.h +15 -0
- data/vendor/prism/include/prism/internal/node.h +42 -0
- data/vendor/prism/include/prism/internal/options.h +232 -0
- data/vendor/prism/include/prism/internal/parser.h +1015 -0
- data/vendor/prism/include/prism/internal/regexp.h +26 -0
- data/vendor/prism/include/prism/internal/serialize.h +39 -0
- data/vendor/prism/include/prism/internal/source.h +72 -0
- data/vendor/prism/include/prism/internal/static_literals.h +60 -0
- data/vendor/prism/include/prism/internal/stringy.h +30 -0
- data/vendor/prism/include/prism/{util/pm_strncasecmp.h → internal/strncasecmp.h} +3 -17
- data/vendor/prism/include/prism/{util/pm_strpbrk.h → internal/strpbrk.h} +7 -20
- data/vendor/prism/include/prism/internal/tokens.h +11 -0
- data/vendor/prism/include/prism/internal/xxh3.h +16 -0
- data/vendor/prism/include/prism/json.h +40 -0
- data/vendor/prism/include/prism/line_offset_list.h +69 -0
- data/vendor/prism/include/prism/magic_comments.h +53 -0
- data/vendor/prism/include/prism/node.h +59 -49
- data/vendor/prism/include/prism/node.hpp +272 -0
- data/vendor/prism/include/prism/node_type.hpp +38 -0
- data/vendor/prism/include/prism/options.h +154 -279
- data/vendor/prism/include/prism/options.hpp +43 -0
- data/vendor/prism/include/prism/parser.h +367 -870
- data/vendor/prism/include/prism/parser.hpp +274 -0
- data/vendor/prism/include/prism/prettyprint.h +14 -9
- data/vendor/prism/include/prism/serialize.h +123 -0
- data/vendor/prism/include/prism/source.h +163 -0
- data/vendor/prism/include/prism/stream.h +36 -0
- data/vendor/prism/include/prism/string_query.h +82 -0
- data/vendor/prism/include/prism/stringy.h +61 -0
- data/vendor/prism/include/prism/stringy.hpp +31 -0
- data/vendor/prism/include/prism/version.h +20 -3
- data/vendor/prism/include/prism.h +35 -320
- data/vendor/prism/include/prism.hpp +24 -0
- data/vendor/prism/src/arena.c +122 -0
- data/vendor/prism/src/{util/pm_buffer.c → buffer.c} +53 -21
- data/vendor/prism/src/{util/pm_char.c → char.c} +28 -57
- data/vendor/prism/src/comments.c +455 -0
- data/vendor/prism/src/constant_pool.c +406 -0
- data/vendor/prism/src/diagnostic.c +120 -68
- data/vendor/prism/src/encoding.c +8 -3
- data/vendor/prism/src/errors_format.c +519 -0
- data/vendor/prism/src/{util/pm_integer.c → integer.c} +38 -22
- data/vendor/prism/src/json.c +5733 -0
- data/vendor/prism/src/line_offset_list.c +100 -0
- data/vendor/prism/src/list.c +24 -0
- data/vendor/prism/src/{util/pm_memchr.c → memchr.c} +8 -6
- data/vendor/prism/src/node.c +3465 -7787
- data/vendor/prism/src/options.c +161 -54
- data/vendor/prism/src/parser.c +371 -0
- data/vendor/prism/src/prettyprint.c +421 -354
- data/vendor/prism/src/prism.c +8522 -7280
- data/vendor/prism/src/regexp.c +960 -45
- data/vendor/prism/src/serialize.c +2434 -2048
- data/vendor/prism/src/source.c +524 -0
- data/vendor/prism/src/static_literals.c +303 -360
- data/vendor/prism/src/string_query.c +180 -0
- data/vendor/prism/src/stringy.c +61 -0
- data/vendor/prism/src/{util/pm_strncasecmp.c → strncasecmp.c} +5 -4
- data/vendor/prism/src/strpbrk.c +447 -0
- data/vendor/prism/src/{token_type.c → tokens.c} +39 -18
- data/vendor/prism/src/xxh3.c +292 -0
- data/vendor/prism/templates/ext/prism/api_node.c.erb +58 -44
- data/vendor/prism/templates/include/prism/ast.h.erb +67 -17
- data/vendor/prism/templates/include/prism/ast.hpp.erb +31 -0
- data/vendor/prism/templates/include/prism/internal/diagnostic.h.erb +60 -0
- data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/AbstractNodeVisitor.java.erb +1 -1
- data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/Loader.java.erb +232 -133
- data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/Nodes.java.erb +62 -23
- data/vendor/prism/templates/javascript/src/deserialize.js.erb +153 -146
- data/vendor/prism/templates/javascript/src/nodes.js.erb +4 -9
- data/vendor/prism/templates/lib/prism/compiler.rb.erb +14 -5
- data/vendor/prism/templates/lib/prism/dispatcher.rb.erb +20 -12
- data/vendor/prism/templates/lib/prism/dot_visitor.rb.erb +37 -11
- data/vendor/prism/templates/lib/prism/dsl.rb.erb +43 -4
- data/vendor/prism/templates/lib/prism/inspect_visitor.rb.erb +26 -10
- data/vendor/prism/templates/lib/prism/mutation_compiler.rb.erb +5 -2
- data/vendor/prism/templates/lib/prism/node.rb.erb +283 -105
- data/vendor/prism/templates/lib/prism/reflection.rb.erb +11 -2
- data/vendor/prism/templates/lib/prism/serialize.rb.erb +291 -134
- data/vendor/prism/templates/lib/prism/visitor.rb.erb +18 -0
- data/vendor/prism/templates/src/diagnostic.c.erb +114 -63
- data/vendor/prism/templates/src/json.c.erb +130 -0
- data/vendor/prism/templates/src/node.c.erb +79 -236
- data/vendor/prism/templates/src/prettyprint.c.erb +24 -13
- data/vendor/prism/templates/src/serialize.c.erb +369 -183
- data/vendor/prism/templates/src/{token_type.c.erb → tokens.c.erb} +22 -11
- data/vendor/prism/templates/template.rb +193 -91
- metadata +100 -42
- data/vendor/prism/include/prism/defines.h +0 -260
- data/vendor/prism/include/prism/pack.h +0 -163
- data/vendor/prism/include/prism/regexp.h +0 -43
- data/vendor/prism/include/prism/static_literals.h +0 -121
- data/vendor/prism/include/prism/util/pm_buffer.h +0 -236
- data/vendor/prism/include/prism/util/pm_char.h +0 -204
- data/vendor/prism/include/prism/util/pm_constant_pool.h +0 -218
- data/vendor/prism/include/prism/util/pm_integer.h +0 -130
- data/vendor/prism/include/prism/util/pm_memchr.h +0 -29
- data/vendor/prism/include/prism/util/pm_newline_list.h +0 -113
- data/vendor/prism/include/prism/util/pm_string.h +0 -200
- data/vendor/prism/src/pack.c +0 -509
- data/vendor/prism/src/util/pm_constant_pool.c +0 -342
- data/vendor/prism/src/util/pm_list.c +0 -49
- data/vendor/prism/src/util/pm_newline_list.c +0 -125
- data/vendor/prism/src/util/pm_string.c +0 -381
- data/vendor/prism/src/util/pm_strpbrk.c +0 -206
- data/vendor/prism/templates/include/prism/diagnostic.h.erb +0 -130
- data/vendor/prism/templates/rbi/prism/dsl.rbi.erb +0 -68
- data/vendor/prism/templates/rbi/prism/node.rbi.erb +0 -167
- data/vendor/prism/templates/rbi/prism/visitor.rbi.erb +0 -18
- data/vendor/prism/templates/sig/prism/_private/dot_visitor.rbs.erb +0 -45
- data/vendor/prism/templates/sig/prism/dsl.rbs.erb +0 -31
- data/vendor/prism/templates/sig/prism/mutation_compiler.rbs.erb +0 -7
- data/vendor/prism/templates/sig/prism/node.rbs.erb +0 -136
- data/vendor/prism/templates/sig/prism/visitor.rbs.erb +0 -17
- data/vendor/prism/templates/sig/prism.rbs.erb +0 -92
data/src/analyze/render_nodes.c
CHANGED
|
@@ -9,10 +9,13 @@
|
|
|
9
9
|
#include "../include/lexer/token.h"
|
|
10
10
|
#include "../include/lib/hb_allocator.h"
|
|
11
11
|
#include "../include/lib/hb_array.h"
|
|
12
|
+
#include "../include/lib/hb_buffer.h"
|
|
12
13
|
#include "../include/lib/hb_string.h"
|
|
13
14
|
#include "../include/lib/string.h"
|
|
14
15
|
#include "../include/visitor.h"
|
|
15
16
|
|
|
17
|
+
#include "../include/prism/prism_helpers.h"
|
|
18
|
+
|
|
16
19
|
#include <prism.h>
|
|
17
20
|
#include <stdbool.h>
|
|
18
21
|
#include <string.h>
|
|
@@ -50,9 +53,10 @@ static bool is_render_call(pm_call_node_t* call_node, pm_parser_t* parser) {
|
|
|
50
53
|
if (!call_node || !call_node->name) { return false; }
|
|
51
54
|
if (call_node->receiver && call_node->receiver->type != PM_SELF_NODE) { return false; }
|
|
52
55
|
|
|
53
|
-
pm_constant_t* constant =
|
|
56
|
+
const pm_constant_t* constant = pm_parser_constant(parser, call_node->name);
|
|
54
57
|
|
|
55
|
-
return constant &&
|
|
58
|
+
return constant && pm_constant_length(constant) == 6
|
|
59
|
+
&& strncmp((const char*) pm_constant_start(constant), "render", 6) == 0;
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
static pm_call_node_t* find_render_call(pm_node_t* node, pm_parser_t* parser) {
|
|
@@ -99,9 +103,57 @@ static pm_block_node_t* find_block_on_render_call(pm_call_node_t* render_call) {
|
|
|
99
103
|
return NULL;
|
|
100
104
|
}
|
|
101
105
|
|
|
106
|
+
static bool literal_string_length(pm_node_t* node, size_t* length) {
|
|
107
|
+
if (node->type == PM_STRING_NODE) {
|
|
108
|
+
*length += pm_string_length(&((pm_string_node_t*) node)->unescaped);
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (node->type != PM_INTERPOLATED_STRING_NODE) { return false; }
|
|
113
|
+
|
|
114
|
+
pm_node_list_t* parts = &((pm_interpolated_string_node_t*) node)->parts;
|
|
115
|
+
|
|
116
|
+
for (size_t index = 0; index < parts->size; index++) {
|
|
117
|
+
if (!literal_string_length(parts->nodes[index], length)) { return false; }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static char* append_literal_string(pm_node_t* node, char* cursor) {
|
|
124
|
+
if (node->type == PM_STRING_NODE) {
|
|
125
|
+
pm_string_t* unescaped = &((pm_string_node_t*) node)->unescaped;
|
|
126
|
+
size_t length = pm_string_length(unescaped);
|
|
127
|
+
|
|
128
|
+
memcpy(cursor, pm_string_source(unescaped), length);
|
|
129
|
+
return cursor + length;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
pm_node_list_t* parts = &((pm_interpolated_string_node_t*) node)->parts;
|
|
133
|
+
|
|
134
|
+
for (size_t index = 0; index < parts->size; index++) {
|
|
135
|
+
cursor = append_literal_string(parts->nodes[index], cursor);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return cursor;
|
|
139
|
+
}
|
|
140
|
+
|
|
102
141
|
static char* extract_string_value(pm_node_t* node, hb_allocator_T* allocator) {
|
|
103
142
|
if (!node) { return NULL; }
|
|
104
143
|
|
|
144
|
+
if (node->type == PM_INTERPOLATED_STRING_NODE) {
|
|
145
|
+
size_t length = 0;
|
|
146
|
+
if (!literal_string_length(node, &length)) { return NULL; }
|
|
147
|
+
|
|
148
|
+
char* value = hb_allocator_alloc(allocator, length + 1);
|
|
149
|
+
if (!value) { return NULL; }
|
|
150
|
+
|
|
151
|
+
char* end = append_literal_string(node, value);
|
|
152
|
+
*end = '\0';
|
|
153
|
+
|
|
154
|
+
return value;
|
|
155
|
+
}
|
|
156
|
+
|
|
105
157
|
if (node->type == PM_STRING_NODE) {
|
|
106
158
|
pm_string_node_t* string_node = (pm_string_node_t*) node;
|
|
107
159
|
size_t length = pm_string_length(&string_node->unescaped);
|
|
@@ -117,11 +169,48 @@ static char* extract_string_value(pm_node_t* node, hb_allocator_T* allocator) {
|
|
|
117
169
|
return NULL;
|
|
118
170
|
}
|
|
119
171
|
|
|
120
|
-
static char* extract_source_expression(pm_node_t* node, hb_allocator_T* allocator) {
|
|
172
|
+
static char* extract_source_expression(const uint8_t* erb_content_source, pm_node_t* node, hb_allocator_T* allocator) {
|
|
121
173
|
if (!node) { return NULL; }
|
|
122
174
|
|
|
123
|
-
|
|
124
|
-
|
|
175
|
+
return hb_allocator_strndup(
|
|
176
|
+
allocator,
|
|
177
|
+
(const char*) (erb_content_source + node->location.start),
|
|
178
|
+
node->location.length
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
static void append_ruby_string_argument(
|
|
183
|
+
hb_buffer_T* buffer,
|
|
184
|
+
pm_node_t* node,
|
|
185
|
+
const uint8_t* erb_content_source,
|
|
186
|
+
hb_allocator_T* allocator
|
|
187
|
+
) {
|
|
188
|
+
if (!node) { return; }
|
|
189
|
+
|
|
190
|
+
char* value = node->type == PM_SYMBOL_NODE ? NULL : extract_string_value(node, allocator);
|
|
191
|
+
|
|
192
|
+
if (!value) {
|
|
193
|
+
hb_buffer_append_with_length(
|
|
194
|
+
buffer,
|
|
195
|
+
(const char*) (erb_content_source + node->location.start),
|
|
196
|
+
node->location.length
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
hb_buffer_append_char(buffer, '"');
|
|
203
|
+
|
|
204
|
+
for (const char* cursor = value; *cursor; cursor++) {
|
|
205
|
+
bool escape = *cursor == '\\' || *cursor == '"'
|
|
206
|
+
|| (*cursor == '#' && (cursor[1] == '{' || cursor[1] == '@' || cursor[1] == '$'));
|
|
207
|
+
|
|
208
|
+
if (escape) { hb_buffer_append_char(buffer, '\\'); }
|
|
209
|
+
hb_buffer_append_char(buffer, *cursor);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
hb_buffer_append_char(buffer, '"');
|
|
213
|
+
hb_allocator_dealloc(allocator, value);
|
|
125
214
|
}
|
|
126
215
|
|
|
127
216
|
static token_T* create_token_from_prism_node(
|
|
@@ -137,8 +226,8 @@ static token_T* create_token_from_prism_node(
|
|
|
137
226
|
position_T end = { .line = 1, .column = 1 };
|
|
138
227
|
|
|
139
228
|
if (node && source && erb_content_source) {
|
|
140
|
-
size_t start_offset_in_erb =
|
|
141
|
-
size_t end_offset_in_erb = (
|
|
229
|
+
size_t start_offset_in_erb = node->location.start;
|
|
230
|
+
size_t end_offset_in_erb = herb_prism_location_end(node->location);
|
|
142
231
|
|
|
143
232
|
size_t total_start = erb_content_offset + start_offset_in_erb;
|
|
144
233
|
size_t total_end = erb_content_offset + end_offset_in_erb;
|
|
@@ -160,6 +249,7 @@ static pm_keyword_hash_node_t* find_keyword_hash(pm_arguments_node_t* arguments)
|
|
|
160
249
|
}
|
|
161
250
|
|
|
162
251
|
static keyword_result_T find_keyword_value(
|
|
252
|
+
const uint8_t* erb_content_source,
|
|
163
253
|
pm_keyword_hash_node_t* keyword_hash,
|
|
164
254
|
const char* key,
|
|
165
255
|
hb_allocator_T* allocator
|
|
@@ -184,7 +274,7 @@ static keyword_result_T find_keyword_value(
|
|
|
184
274
|
if (string_value) {
|
|
185
275
|
result.value = string_value;
|
|
186
276
|
} else {
|
|
187
|
-
result.value = extract_source_expression(assoc->value, allocator);
|
|
277
|
+
result.value = extract_source_expression(erb_content_source, assoc->value, allocator);
|
|
188
278
|
}
|
|
189
279
|
|
|
190
280
|
return result;
|
|
@@ -196,6 +286,18 @@ static keyword_result_T find_keyword_value(
|
|
|
196
286
|
return result;
|
|
197
287
|
}
|
|
198
288
|
|
|
289
|
+
static pm_node_t* find_keyword_value_node(
|
|
290
|
+
const uint8_t* erb_content_source,
|
|
291
|
+
pm_keyword_hash_node_t* keyword_hash,
|
|
292
|
+
const char* key,
|
|
293
|
+
hb_allocator_T* allocator
|
|
294
|
+
) {
|
|
295
|
+
keyword_result_T keyword = find_keyword_value(erb_content_source, keyword_hash, key, allocator);
|
|
296
|
+
if (keyword.value) { hb_allocator_dealloc(allocator, keyword.value); }
|
|
297
|
+
|
|
298
|
+
return keyword.value_node;
|
|
299
|
+
}
|
|
300
|
+
|
|
199
301
|
static pm_hash_node_t* find_locals_hash(pm_keyword_hash_node_t* keyword_hash, hb_allocator_T* allocator) {
|
|
200
302
|
if (!keyword_hash) { return NULL; }
|
|
201
303
|
|
|
@@ -228,11 +330,12 @@ static bool extract_assoc_parts(
|
|
|
228
330
|
AST_RUBY_LITERAL_NODE_T** value_node
|
|
229
331
|
) {
|
|
230
332
|
char* name = extract_string_value(assoc->key, allocator);
|
|
231
|
-
if (!name) { name = extract_source_expression(assoc->key, allocator); }
|
|
333
|
+
if (!name) { name = extract_source_expression(erb_content_source, assoc->key, allocator); }
|
|
232
334
|
if (!name) { return false; }
|
|
233
335
|
|
|
234
336
|
bool shorthand = assoc->value && assoc->value->type == PM_IMPLICIT_NODE;
|
|
235
|
-
char* value = shorthand ? hb_allocator_strdup(allocator, name)
|
|
337
|
+
char* value = shorthand ? hb_allocator_strdup(allocator, name)
|
|
338
|
+
: extract_source_expression(erb_content_source, assoc->value, allocator);
|
|
236
339
|
|
|
237
340
|
if (!value) {
|
|
238
341
|
hb_allocator_dealloc(allocator, name);
|
|
@@ -254,8 +357,8 @@ static bool extract_assoc_parts(
|
|
|
254
357
|
pm_node_t* spanned = shorthand ? assoc->key : assoc->value;
|
|
255
358
|
|
|
256
359
|
if (spanned && source && erb_content_source) {
|
|
257
|
-
size_t start_offset =
|
|
258
|
-
size_t end_offset = (
|
|
360
|
+
size_t start_offset = spanned->location.start;
|
|
361
|
+
size_t end_offset = herb_prism_location_end(spanned->location);
|
|
259
362
|
|
|
260
363
|
if (shorthand && end_offset > start_offset && erb_content_source[end_offset - 1] == ':') { end_offset--; }
|
|
261
364
|
|
|
@@ -348,7 +451,7 @@ static token_T* extract_keyword_token(
|
|
|
348
451
|
const uint8_t* erb_content_source,
|
|
349
452
|
hb_allocator_T* allocator
|
|
350
453
|
) {
|
|
351
|
-
keyword_result_T keyword = find_keyword_value(keyword_hash, keyword_name, allocator);
|
|
454
|
+
keyword_result_T keyword = find_keyword_value(erb_content_source, keyword_hash, keyword_name, allocator);
|
|
352
455
|
if (!keyword.value) { return NULL; }
|
|
353
456
|
|
|
354
457
|
token_T* token = create_token_from_prism_node(
|
|
@@ -405,7 +508,7 @@ static void append_unusable_state_entry(
|
|
|
405
508
|
hb_allocator_T* allocator
|
|
406
509
|
) {
|
|
407
510
|
pm_node_t* named = element->type == PM_ASSOC_NODE ? ((pm_assoc_node_t*) element)->key : element;
|
|
408
|
-
char* name = extract_source_expression(named, allocator);
|
|
511
|
+
char* name = extract_source_expression(erb_content_source, named, allocator);
|
|
409
512
|
|
|
410
513
|
if (!name) { return; }
|
|
411
514
|
|
|
@@ -423,8 +526,8 @@ static void append_unusable_state_entry(
|
|
|
423
526
|
position_T end = start;
|
|
424
527
|
|
|
425
528
|
if (source && erb_content_source) {
|
|
426
|
-
size_t start_offset =
|
|
427
|
-
size_t end_offset = (
|
|
529
|
+
size_t start_offset = element->location.start;
|
|
530
|
+
size_t end_offset = herb_prism_location_end(element->location);
|
|
428
531
|
|
|
429
532
|
start = byte_offset_to_position(source, erb_content_offset + start_offset);
|
|
430
533
|
end = byte_offset_to_position(source, erb_content_offset + end_offset);
|
|
@@ -512,8 +615,8 @@ static location_T* prism_node_location(
|
|
|
512
615
|
) {
|
|
513
616
|
if (!node || !source || !erb_content_source) { return NULL; }
|
|
514
617
|
|
|
515
|
-
size_t start_offset =
|
|
516
|
-
size_t end_offset = (
|
|
618
|
+
size_t start_offset = node->location.start;
|
|
619
|
+
size_t end_offset = herb_prism_location_end(node->location);
|
|
517
620
|
|
|
518
621
|
return location_create(
|
|
519
622
|
byte_offset_to_position(source, erb_content_offset + start_offset),
|
|
@@ -576,9 +679,13 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
|
|
|
576
679
|
if (arguments && arguments->arguments.size >= 1) {
|
|
577
680
|
pm_node_t* first_argument = arguments->arguments.nodes[0];
|
|
578
681
|
|
|
579
|
-
if (first_argument->type == PM_STRING_NODE) {
|
|
682
|
+
if (first_argument->type == PM_STRING_NODE || first_argument->type == PM_INTERPOLATED_STRING_NODE) {
|
|
580
683
|
char* partial_string = extract_string_value(first_argument, allocator);
|
|
581
684
|
|
|
685
|
+
if (!partial_string) {
|
|
686
|
+
partial_string = extract_source_expression(erb_content_source, first_argument, allocator);
|
|
687
|
+
}
|
|
688
|
+
|
|
582
689
|
if (partial_string) {
|
|
583
690
|
has_positional_partial = true;
|
|
584
691
|
|
|
@@ -595,7 +702,7 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
|
|
|
595
702
|
hb_allocator_dealloc(allocator, partial_string);
|
|
596
703
|
}
|
|
597
704
|
} else if (first_argument->type != PM_KEYWORD_HASH_NODE) {
|
|
598
|
-
char* object_string = extract_source_expression(first_argument, allocator);
|
|
705
|
+
char* object_string = extract_source_expression(erb_content_source, first_argument, allocator);
|
|
599
706
|
|
|
600
707
|
if (object_string) {
|
|
601
708
|
object = create_token_from_prism_node(
|
|
@@ -614,7 +721,7 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
|
|
|
614
721
|
|
|
615
722
|
if (keyword_hash) {
|
|
616
723
|
if (has_positional_partial) {
|
|
617
|
-
keyword_result_T partial_kw = find_keyword_value(keyword_hash, "partial", allocator);
|
|
724
|
+
keyword_result_T partial_kw = find_keyword_value(erb_content_source, keyword_hash, "partial", allocator);
|
|
618
725
|
if (partial_kw.value) { has_keyword_partial = true; }
|
|
619
726
|
|
|
620
727
|
pm_hash_node_t* locals_hash = find_locals_hash(keyword_hash, allocator);
|
|
@@ -691,13 +798,15 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
|
|
|
691
798
|
hb_array_T* errors = NULL;
|
|
692
799
|
|
|
693
800
|
if (!has_keyword_partial && partial && keyword_hash) {
|
|
694
|
-
keyword_result_T locals_keyword = find_keyword_value(keyword_hash, "locals", allocator);
|
|
801
|
+
keyword_result_T locals_keyword = find_keyword_value(erb_content_source, keyword_hash, "locals", allocator);
|
|
695
802
|
|
|
696
803
|
if (locals_keyword.value) {
|
|
697
|
-
|
|
804
|
+
hb_buffer_T partial_buffer;
|
|
805
|
+
hb_buffer_init(&partial_buffer, 64, allocator);
|
|
806
|
+
append_ruby_string_argument(&partial_buffer, arguments->arguments.nodes[0], erb_content_source, allocator);
|
|
698
807
|
|
|
699
808
|
append_render_ambiguous_locals_error(
|
|
700
|
-
|
|
809
|
+
hb_string_from_data(hb_buffer_value(&partial_buffer), hb_buffer_length(&partial_buffer)),
|
|
701
810
|
erb_node->base.location.start,
|
|
702
811
|
erb_node->base.location.end,
|
|
703
812
|
allocator,
|
|
@@ -705,19 +814,27 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
|
|
|
705
814
|
options
|
|
706
815
|
);
|
|
707
816
|
|
|
817
|
+
hb_buffer_free(&partial_buffer);
|
|
818
|
+
|
|
708
819
|
hb_allocator_dealloc(allocator, locals_keyword.value);
|
|
709
820
|
}
|
|
710
821
|
}
|
|
711
822
|
|
|
712
823
|
if (has_keyword_partial && partial && keyword_hash && hb_array_size(locals) == 0) {
|
|
713
|
-
|
|
714
|
-
|
|
824
|
+
hb_array_T* stray_assocs = hb_array_init(keyword_hash->elements.size, allocator);
|
|
825
|
+
hb_array_T* kept_elements = hb_array_init(keyword_hash->elements.size, allocator);
|
|
715
826
|
|
|
716
827
|
for (size_t index = 0; index < keyword_hash->elements.size; index++) {
|
|
717
828
|
pm_node_t* element = keyword_hash->elements.nodes[index];
|
|
829
|
+
if (element->type == PM_ASSOC_SPLAT_NODE || element == (pm_node_t*) state_assoc) {
|
|
830
|
+
hb_array_append(kept_elements, element);
|
|
831
|
+
continue;
|
|
832
|
+
}
|
|
833
|
+
|
|
718
834
|
if (element->type != PM_ASSOC_NODE) { continue; }
|
|
719
835
|
|
|
720
836
|
pm_assoc_node_t* assoc = (pm_assoc_node_t*) element;
|
|
837
|
+
|
|
721
838
|
char* key = extract_string_value(assoc->key, allocator);
|
|
722
839
|
if (!key) { continue; }
|
|
723
840
|
|
|
@@ -730,50 +847,65 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
|
|
|
730
847
|
}
|
|
731
848
|
}
|
|
732
849
|
|
|
733
|
-
if (!is_known && assoc == state_assoc) { is_known = true; }
|
|
734
|
-
|
|
735
850
|
if (!is_known) {
|
|
736
|
-
|
|
737
|
-
|
|
851
|
+
hb_array_append(stray_assocs, assoc);
|
|
852
|
+
} else if (!string_equals(key, "partial") && !string_equals(key, "locals")) {
|
|
853
|
+
hb_array_append(kept_elements, element);
|
|
738
854
|
}
|
|
739
855
|
|
|
740
856
|
hb_allocator_dealloc(allocator, key);
|
|
741
857
|
}
|
|
742
858
|
|
|
743
|
-
if (
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
859
|
+
if (hb_array_size(stray_assocs) > 0) {
|
|
860
|
+
hb_buffer_T keywords_buffer;
|
|
861
|
+
hb_buffer_T suggestion_buffer;
|
|
862
|
+
hb_buffer_init(&keywords_buffer, 64, allocator);
|
|
863
|
+
hb_buffer_init(&suggestion_buffer, 128, allocator);
|
|
747
864
|
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
865
|
+
hb_buffer_append(&suggestion_buffer, "partial: ");
|
|
866
|
+
append_ruby_string_argument(
|
|
867
|
+
&suggestion_buffer,
|
|
868
|
+
find_keyword_value_node(erb_content_source, keyword_hash, "partial", allocator),
|
|
869
|
+
erb_content_source,
|
|
870
|
+
allocator
|
|
871
|
+
);
|
|
872
|
+
hb_buffer_append(&suggestion_buffer, ", locals: { ");
|
|
751
873
|
|
|
752
|
-
|
|
874
|
+
for (size_t index = 0; index < hb_array_size(stray_assocs); index++) {
|
|
875
|
+
pm_assoc_node_t* assoc = hb_array_get(stray_assocs, index);
|
|
753
876
|
char* key = extract_string_value(assoc->key, allocator);
|
|
754
|
-
if (!key) { continue; }
|
|
755
|
-
|
|
756
|
-
bool is_known = false;
|
|
757
877
|
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
break;
|
|
762
|
-
}
|
|
878
|
+
if (index > 0) {
|
|
879
|
+
hb_buffer_append(&keywords_buffer, ", ");
|
|
880
|
+
hb_buffer_append(&suggestion_buffer, ", ");
|
|
763
881
|
}
|
|
764
882
|
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
883
|
+
hb_buffer_append(&keywords_buffer, key);
|
|
884
|
+
hb_buffer_append_with_length(
|
|
885
|
+
&suggestion_buffer,
|
|
886
|
+
(const char*) (erb_content_source + assoc->base.location.start),
|
|
887
|
+
assoc->base.location.length
|
|
888
|
+
);
|
|
770
889
|
|
|
771
890
|
hb_allocator_dealloc(allocator, key);
|
|
772
891
|
}
|
|
773
892
|
|
|
893
|
+
hb_buffer_append(&suggestion_buffer, " }");
|
|
894
|
+
|
|
895
|
+
for (size_t index = 0; index < hb_array_size(kept_elements); index++) {
|
|
896
|
+
pm_node_t* element = hb_array_get(kept_elements, index);
|
|
897
|
+
|
|
898
|
+
hb_buffer_append(&suggestion_buffer, ", ");
|
|
899
|
+
hb_buffer_append_with_length(
|
|
900
|
+
&suggestion_buffer,
|
|
901
|
+
(const char*) (erb_content_source + element->location.start),
|
|
902
|
+
element->location.length
|
|
903
|
+
);
|
|
904
|
+
}
|
|
905
|
+
|
|
774
906
|
append_render_missing_locals_error(
|
|
775
|
-
|
|
776
|
-
|
|
907
|
+
hb_string_from_data(hb_buffer_value(&keywords_buffer), hb_buffer_length(&keywords_buffer)),
|
|
908
|
+
hb_string_from_data(hb_buffer_value(&suggestion_buffer), hb_buffer_length(&suggestion_buffer)),
|
|
777
909
|
erb_node->base.location.start,
|
|
778
910
|
erb_node->base.location.end,
|
|
779
911
|
allocator,
|
|
@@ -781,8 +913,12 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
|
|
|
781
913
|
options
|
|
782
914
|
);
|
|
783
915
|
|
|
784
|
-
|
|
916
|
+
hb_buffer_free(&keywords_buffer);
|
|
917
|
+
hb_buffer_free(&suggestion_buffer);
|
|
785
918
|
}
|
|
919
|
+
|
|
920
|
+
hb_array_free(&stray_assocs);
|
|
921
|
+
hb_array_free(&kept_elements);
|
|
786
922
|
}
|
|
787
923
|
|
|
788
924
|
if (!partial && !template_path && !layout && !file && !inline_template && !body && !plain && !html && !renderable
|
|
@@ -797,11 +933,22 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
|
|
|
797
933
|
}
|
|
798
934
|
|
|
799
935
|
if (has_positional_partial && has_keyword_partial && keyword_hash) {
|
|
800
|
-
|
|
936
|
+
hb_buffer_T positional_buffer;
|
|
937
|
+
hb_buffer_T keyword_buffer;
|
|
938
|
+
hb_buffer_init(&positional_buffer, 64, allocator);
|
|
939
|
+
hb_buffer_init(&keyword_buffer, 64, allocator);
|
|
940
|
+
|
|
941
|
+
append_ruby_string_argument(&positional_buffer, arguments->arguments.nodes[0], erb_content_source, allocator);
|
|
942
|
+
append_ruby_string_argument(
|
|
943
|
+
&keyword_buffer,
|
|
944
|
+
find_keyword_value_node(erb_content_source, keyword_hash, "partial", allocator),
|
|
945
|
+
erb_content_source,
|
|
946
|
+
allocator
|
|
947
|
+
);
|
|
801
948
|
|
|
802
949
|
append_render_conflicting_partial_error(
|
|
803
|
-
|
|
804
|
-
|
|
950
|
+
hb_string_from_data(hb_buffer_value(&positional_buffer), hb_buffer_length(&positional_buffer)),
|
|
951
|
+
hb_string_from_data(hb_buffer_value(&keyword_buffer), hb_buffer_length(&keyword_buffer)),
|
|
805
952
|
erb_node->base.location.start,
|
|
806
953
|
erb_node->base.location.end,
|
|
807
954
|
allocator,
|
|
@@ -809,7 +956,8 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
|
|
|
809
956
|
options
|
|
810
957
|
);
|
|
811
958
|
|
|
812
|
-
|
|
959
|
+
hb_buffer_free(&positional_buffer);
|
|
960
|
+
hb_buffer_free(&keyword_buffer);
|
|
813
961
|
}
|
|
814
962
|
|
|
815
963
|
if (as_name) {
|
|
@@ -851,14 +999,25 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
|
|
|
851
999
|
}
|
|
852
1000
|
|
|
853
1001
|
if (layout && !partial && !template_path && !(block_fields && block_fields->end_node)) {
|
|
1002
|
+
hb_buffer_T layout_buffer;
|
|
1003
|
+
hb_buffer_init(&layout_buffer, 64, allocator);
|
|
1004
|
+
append_ruby_string_argument(
|
|
1005
|
+
&layout_buffer,
|
|
1006
|
+
find_keyword_value_node(erb_content_source, keyword_hash, "layout", allocator),
|
|
1007
|
+
erb_content_source,
|
|
1008
|
+
allocator
|
|
1009
|
+
);
|
|
1010
|
+
|
|
854
1011
|
append_render_layout_without_block_error(
|
|
855
|
-
|
|
1012
|
+
hb_string_from_data(hb_buffer_value(&layout_buffer), hb_buffer_length(&layout_buffer)),
|
|
856
1013
|
erb_node->base.location.start,
|
|
857
1014
|
erb_node->base.location.end,
|
|
858
1015
|
allocator,
|
|
859
1016
|
&errors,
|
|
860
1017
|
options
|
|
861
1018
|
);
|
|
1019
|
+
|
|
1020
|
+
hb_buffer_free(&layout_buffer);
|
|
862
1021
|
}
|
|
863
1022
|
|
|
864
1023
|
herb_prism_node_T prism_node = erb_node->prism_node;
|
|
@@ -875,7 +1034,7 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
|
|
|
875
1034
|
pm_block_node_t* inline_block = find_block_on_render_call(call_node);
|
|
876
1035
|
|
|
877
1036
|
if (inline_block) {
|
|
878
|
-
const uint8_t* content_source = erb_content_source ? erb_content_source : (
|
|
1037
|
+
const uint8_t* content_source = erb_content_source ? erb_content_source : pm_parser_start(parser);
|
|
879
1038
|
|
|
880
1039
|
if (inline_block->parameters && inline_block->parameters->type == PM_BLOCK_PARAMETERS_NODE) {
|
|
881
1040
|
pm_block_parameters_node_t* block_parameters = (pm_block_parameters_node_t*) inline_block->parameters;
|
|
@@ -893,16 +1052,18 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
|
|
|
893
1052
|
}
|
|
894
1053
|
|
|
895
1054
|
if (inline_block->body) {
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
1055
|
+
char* body_source = hb_allocator_strndup(
|
|
1056
|
+
allocator,
|
|
1057
|
+
(const char*) (content_source + inline_block->body->location.start),
|
|
1058
|
+
inline_block->body->location.length
|
|
1059
|
+
);
|
|
899
1060
|
|
|
900
1061
|
position_T body_start = { .line = 1, .column = 1 };
|
|
901
1062
|
position_T body_end = { .line = 1, .column = 1 };
|
|
902
1063
|
|
|
903
1064
|
if (source && content_source) {
|
|
904
|
-
size_t start_offset =
|
|
905
|
-
size_t end_offset = (
|
|
1065
|
+
size_t start_offset = inline_block->body->location.start;
|
|
1066
|
+
size_t end_offset = herb_prism_location_end(inline_block->body->location);
|
|
906
1067
|
body_start = byte_offset_to_position(source, erb_content_offset + start_offset);
|
|
907
1068
|
body_end = byte_offset_to_position(source, erb_content_offset + end_offset);
|
|
908
1069
|
}
|
|
@@ -1012,7 +1173,7 @@ static AST_ERB_RENDER_NODE_T* try_transform_content_node(
|
|
|
1012
1173
|
if (is_erb_comment_tag(erb_node->tag_opening)) { return NULL; }
|
|
1013
1174
|
if (token_is_escaped_erb_tag_opening(erb_node->tag_opening)) { return NULL; }
|
|
1014
1175
|
|
|
1015
|
-
pm_call_node_t* render_call = find_render_call(erb_node->analyzed_ruby->root,
|
|
1176
|
+
pm_call_node_t* render_call = find_render_call(erb_node->analyzed_ruby->root, erb_node->analyzed_ruby->parser);
|
|
1016
1177
|
if (!render_call) { return NULL; }
|
|
1017
1178
|
|
|
1018
1179
|
size_t erb_content_offset = 0;
|
|
@@ -1021,12 +1182,12 @@ static AST_ERB_RENDER_NODE_T* try_transform_content_node(
|
|
|
1021
1182
|
erb_content_offset = calculate_byte_offset_from_pos(context->source, erb_node->content->location.start);
|
|
1022
1183
|
}
|
|
1023
1184
|
|
|
1024
|
-
const uint8_t* erb_content_source = (
|
|
1185
|
+
const uint8_t* erb_content_source = pm_parser_start(erb_node->analyzed_ruby->parser);
|
|
1025
1186
|
|
|
1026
1187
|
return create_render_node_from_call(
|
|
1027
1188
|
erb_node,
|
|
1028
1189
|
render_call,
|
|
1029
|
-
|
|
1190
|
+
erb_node->analyzed_ruby->parser,
|
|
1030
1191
|
context->source,
|
|
1031
1192
|
erb_content_offset,
|
|
1032
1193
|
erb_content_source,
|
|
@@ -1046,15 +1207,15 @@ static AST_ERB_RENDER_NODE_T* try_transform_block_node(
|
|
|
1046
1207
|
const char* ruby_source = block_node->content->value.data;
|
|
1047
1208
|
size_t ruby_length = block_node->content->value.length;
|
|
1048
1209
|
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
pm_node_t* root = pm_parse(
|
|
1210
|
+
pm_arena_t* arena = pm_arena_new();
|
|
1211
|
+
pm_parser_t* parser = herb_prism_parser_new(arena, (const uint8_t*) ruby_source, ruby_length, context->options);
|
|
1212
|
+
pm_node_t* root = pm_parse(parser);
|
|
1052
1213
|
|
|
1053
|
-
pm_call_node_t* render_call = find_render_call(root,
|
|
1214
|
+
pm_call_node_t* render_call = find_render_call(root, parser);
|
|
1054
1215
|
|
|
1055
1216
|
if (!render_call) {
|
|
1056
|
-
|
|
1057
|
-
|
|
1217
|
+
pm_parser_free(parser);
|
|
1218
|
+
pm_arena_free(arena);
|
|
1058
1219
|
return NULL;
|
|
1059
1220
|
}
|
|
1060
1221
|
|
|
@@ -1075,7 +1236,7 @@ static AST_ERB_RENDER_NODE_T* try_transform_block_node(
|
|
|
1075
1236
|
erb_content_offset = calculate_byte_offset_from_pos(context->source, block_node->content->location.start);
|
|
1076
1237
|
}
|
|
1077
1238
|
|
|
1078
|
-
const uint8_t* erb_content_source = (
|
|
1239
|
+
const uint8_t* erb_content_source = pm_parser_start(parser);
|
|
1079
1240
|
|
|
1080
1241
|
render_block_fields_T block_fields = {
|
|
1081
1242
|
.block_body = block_node->body,
|
|
@@ -1089,7 +1250,7 @@ static AST_ERB_RENDER_NODE_T* try_transform_block_node(
|
|
|
1089
1250
|
AST_ERB_RENDER_NODE_T* render_node = create_render_node_from_call(
|
|
1090
1251
|
&content_view,
|
|
1091
1252
|
render_call,
|
|
1092
|
-
|
|
1253
|
+
parser,
|
|
1093
1254
|
context->source,
|
|
1094
1255
|
erb_content_offset,
|
|
1095
1256
|
erb_content_source,
|
|
@@ -1098,8 +1259,8 @@ static AST_ERB_RENDER_NODE_T* try_transform_block_node(
|
|
|
1098
1259
|
context->options
|
|
1099
1260
|
);
|
|
1100
1261
|
|
|
1101
|
-
|
|
1102
|
-
|
|
1262
|
+
pm_parser_free(parser);
|
|
1263
|
+
pm_arena_free(arena);
|
|
1103
1264
|
|
|
1104
1265
|
return render_node;
|
|
1105
1266
|
}
|
data/src/analyze/strict_locals.c
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
#include "../include/prism/prism_helpers.h"
|
|
17
17
|
|
|
18
18
|
#include <prism.h>
|
|
19
|
+
#include <prism/internal/diagnostic.h>
|
|
19
20
|
#include <stdbool.h>
|
|
20
21
|
#include <string.h>
|
|
21
22
|
|
|
@@ -211,17 +212,16 @@ static AST_ERB_STRICT_LOCALS_NODE_T* create_strict_locals_node(
|
|
|
211
212
|
hb_buffer_T synthetic_buffer;
|
|
212
213
|
if (!build_synthetic_ruby(params_open, params_length, &synthetic_buffer, allocator)) { return NULL; }
|
|
213
214
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
&parser,
|
|
215
|
+
pm_arena_t* arena = pm_arena_new();
|
|
216
|
+
pm_parser_t* parser = herb_prism_parser_new(
|
|
217
|
+
arena,
|
|
218
218
|
(const uint8_t*) hb_buffer_value(&synthetic_buffer),
|
|
219
219
|
hb_buffer_length(&synthetic_buffer),
|
|
220
|
-
|
|
220
|
+
parser_options
|
|
221
221
|
);
|
|
222
|
-
pm_node_t* root = pm_parse(
|
|
222
|
+
pm_node_t* root = pm_parse(parser);
|
|
223
223
|
|
|
224
|
-
const uint8_t* synthetic_start = parser
|
|
224
|
+
const uint8_t* synthetic_start = pm_parser_start(parser);
|
|
225
225
|
|
|
226
226
|
pm_parameters_node_t* params_node = find_parameters_node(root);
|
|
227
227
|
size_t erb_content_byte_offset = calculate_byte_offset_from_position(source, erb_node->content->location.start);
|
|
@@ -230,12 +230,12 @@ static AST_ERB_STRICT_LOCALS_NODE_T* create_strict_locals_node(
|
|
|
230
230
|
size_t params_in_content = (size_t) (params_open - content_bytes);
|
|
231
231
|
size_t prefix_length = strlen(SYNTHETIC_PREFIX);
|
|
232
232
|
|
|
233
|
-
for (const pm_diagnostic_t* error = (
|
|
234
|
-
error = (
|
|
233
|
+
for (const pm_diagnostic_t* error = pm_parser_errors_first(parser); error != NULL;
|
|
234
|
+
error = pm_diagnostic_next(error)) {
|
|
235
235
|
if (error->diag_id == PM_ERR_DEF_TERM) { continue; }
|
|
236
236
|
|
|
237
|
-
size_t error_start_in_synthetic =
|
|
238
|
-
size_t error_end_in_synthetic = (
|
|
237
|
+
size_t error_start_in_synthetic = error->location.start;
|
|
238
|
+
size_t error_end_in_synthetic = herb_prism_location_end(error->location);
|
|
239
239
|
|
|
240
240
|
size_t error_content_start =
|
|
241
241
|
params_in_content + (error_start_in_synthetic > prefix_length ? error_start_in_synthetic - prefix_length : 0);
|
|
@@ -258,7 +258,7 @@ static AST_ERB_STRICT_LOCALS_NODE_T* create_strict_locals_node(
|
|
|
258
258
|
} else {
|
|
259
259
|
locals = extract_strict_locals(
|
|
260
260
|
params_node,
|
|
261
|
-
|
|
261
|
+
parser,
|
|
262
262
|
source,
|
|
263
263
|
erb_content_byte_offset,
|
|
264
264
|
content_bytes,
|
|
@@ -270,9 +270,8 @@ static AST_ERB_STRICT_LOCALS_NODE_T* create_strict_locals_node(
|
|
|
270
270
|
);
|
|
271
271
|
}
|
|
272
272
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
pm_options_free(&options);
|
|
273
|
+
pm_parser_free(parser);
|
|
274
|
+
pm_arena_free(arena);
|
|
276
275
|
hb_buffer_free(&synthetic_buffer);
|
|
277
276
|
|
|
278
277
|
return ast_erb_strict_locals_node_init(
|