herb 0.11.1-x86_64-linux-gnu → 0.11.3-x86_64-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/lexer/token.c
CHANGED
|
@@ -220,7 +220,7 @@ token_T* token_copy(token_T* token, hb_allocator_T* allocator) {
|
|
|
220
220
|
if (!new_token) { return NULL; }
|
|
221
221
|
|
|
222
222
|
new_token->value = token->owns_value ? hb_string_copy(token->value, allocator) : token->value;
|
|
223
|
-
new_token->owns_value = token->owns_value;
|
|
223
|
+
new_token->owns_value = token->owns_value && !hb_string_is_empty(new_token->value);
|
|
224
224
|
|
|
225
225
|
new_token->type = token->type;
|
|
226
226
|
new_token->range = token->range;
|
|
@@ -261,7 +261,7 @@ static token_T* token_from_slice(
|
|
|
261
261
|
if (!slice) { return NULL; }
|
|
262
262
|
|
|
263
263
|
slice->value = token->owns_value ? hb_string_copy(value, allocator) : value;
|
|
264
|
-
slice->owns_value = token->owns_value;
|
|
264
|
+
slice->owns_value = token->owns_value && !hb_string_is_empty(slice->value);
|
|
265
265
|
|
|
266
266
|
slice->type = token->type;
|
|
267
267
|
slice->range = (range_T) { .from = token->range.from + offset, .to = token->range.from + offset + value.length };
|
data/src/parser/dot_notation.c
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
#include "../include/errors.h"
|
|
3
3
|
#include "../include/lexer/lexer.h"
|
|
4
4
|
#include "../include/lexer/token.h"
|
|
5
|
+
#include "../include/lexer/token_matchers.h"
|
|
5
6
|
#include "../include/parser/parser_helpers.h"
|
|
6
7
|
|
|
7
8
|
#include <ctype.h>
|
|
@@ -17,16 +18,25 @@ static bool current_token_is_dot(parser_T* parser) {
|
|
|
17
18
|
static void consume_dot_notation_loop(parser_T* parser, token_T* tag_name, hb_array_T** errors) {
|
|
18
19
|
while (current_token_is_dot(parser)) {
|
|
19
20
|
token_T* dot = parser_advance(parser);
|
|
20
|
-
token_T* segment = parser_consume_expected(parser, TOKEN_IDENTIFIER, errors);
|
|
21
21
|
|
|
22
|
-
if (
|
|
23
|
-
|
|
22
|
+
if (!token_is(parser, TOKEN_IDENTIFIER) || parser->current_token->value.length == 0) {
|
|
23
|
+
append_unexpected_token_error(
|
|
24
|
+
TOKEN_IDENTIFIER,
|
|
25
|
+
parser->current_token,
|
|
26
|
+
parser->current_token->location.start,
|
|
27
|
+
parser->current_token->location.end,
|
|
28
|
+
parser->allocator,
|
|
29
|
+
errors,
|
|
30
|
+
&parser->options
|
|
31
|
+
);
|
|
32
|
+
|
|
24
33
|
token_free(dot, parser->allocator);
|
|
25
34
|
break;
|
|
26
35
|
}
|
|
27
36
|
|
|
28
|
-
|
|
29
|
-
|
|
37
|
+
token_T* segment = parser_advance(parser);
|
|
38
|
+
|
|
39
|
+
tag_name->value.length = segment->range.to - tag_name->range.from;
|
|
30
40
|
tag_name->location.end = segment->location.end;
|
|
31
41
|
tag_name->range.to = segment->range.to;
|
|
32
42
|
|
data/src/parser/parser_helpers.c
CHANGED
|
@@ -195,8 +195,7 @@ void parser_append_literal_node_from_buffer(
|
|
|
195
195
|
|
|
196
196
|
if (children != NULL) { hb_array_append(children, literal); }
|
|
197
197
|
|
|
198
|
-
|
|
199
|
-
hb_buffer_init(buffer, 128, parser->allocator);
|
|
198
|
+
hb_buffer_clear(buffer);
|
|
200
199
|
}
|
|
201
200
|
|
|
202
201
|
token_T* parser_advance(parser_T* parser) {
|
data/src/parser.c
CHANGED
|
@@ -139,7 +139,7 @@ static AST_HTML_COMMENT_NODE_T* parser_parse_html_comment(parser_T* parser) {
|
|
|
139
139
|
position_T start = parser->current_token->location.start;
|
|
140
140
|
|
|
141
141
|
hb_buffer_T comment;
|
|
142
|
-
hb_buffer_init(&comment,
|
|
142
|
+
hb_buffer_init(&comment, 64, parser->allocator);
|
|
143
143
|
|
|
144
144
|
token_T* comment_end = NULL;
|
|
145
145
|
|
|
@@ -376,7 +376,7 @@ static AST_HTML_TEXT_NODE_T* parser_parse_text_content(parser_T* parser, hb_arra
|
|
|
376
376
|
position_T start = parser->current_token->location.start;
|
|
377
377
|
|
|
378
378
|
hb_buffer_T content;
|
|
379
|
-
hb_buffer_init(&content,
|
|
379
|
+
hb_buffer_init(&content, 64, parser->allocator);
|
|
380
380
|
|
|
381
381
|
while (token_is_none_of(
|
|
382
382
|
parser,
|
|
@@ -553,7 +553,7 @@ static AST_HTML_ATTRIBUTE_VALUE_NODE_T* parser_parse_quoted_html_attribute_value
|
|
|
553
553
|
hb_array_T** errors
|
|
554
554
|
) {
|
|
555
555
|
hb_buffer_T buffer;
|
|
556
|
-
hb_buffer_init(&buffer,
|
|
556
|
+
hb_buffer_init(&buffer, 64, parser->allocator);
|
|
557
557
|
token_T* opening_quote = parser_consume_expected(parser, TOKEN_QUOTE, errors);
|
|
558
558
|
position_T start = parser->current_token->location.start;
|
|
559
559
|
|
|
@@ -773,7 +773,9 @@ static AST_HTML_ATTRIBUTE_NODE_T* parser_parse_html_attribute_missing_value(
|
|
|
773
773
|
if (hb_array_size(attribute_name->children) > 0) {
|
|
774
774
|
AST_LITERAL_NODE_T* first_child = (AST_LITERAL_NODE_T*) hb_array_get(attribute_name->children, 0);
|
|
775
775
|
|
|
776
|
-
if (first_child && !hb_string_is_empty(first_child->content)) {
|
|
776
|
+
if (first_child && first_child->base.type == AST_LITERAL_NODE && !hb_string_is_empty(first_child->content)) {
|
|
777
|
+
attribute_name_string = first_child->content;
|
|
778
|
+
}
|
|
777
779
|
}
|
|
778
780
|
|
|
779
781
|
append_missing_attribute_value_error(
|
|
@@ -816,7 +818,7 @@ static AST_HTML_ATTRIBUTE_NODE_T* parser_parse_html_attribute(parser_T* parser)
|
|
|
816
818
|
|
|
817
819
|
if (has_equals) {
|
|
818
820
|
hb_buffer_T equals_buffer;
|
|
819
|
-
hb_buffer_init(&equals_buffer,
|
|
821
|
+
hb_buffer_init(&equals_buffer, 16, parser->allocator);
|
|
820
822
|
position_T equals_start = { 0 };
|
|
821
823
|
position_T equals_end = { 0 };
|
|
822
824
|
uint32_t range_start = 0;
|
|
@@ -1640,13 +1642,12 @@ static void parser_append_foreign_content_from_buffer(
|
|
|
1640
1642
|
ast_html_text_node_init(content, start, parser->current_token->location.start, NULL, parser->allocator)
|
|
1641
1643
|
);
|
|
1642
1644
|
|
|
1643
|
-
|
|
1644
|
-
hb_buffer_init(buffer, 128, parser->allocator);
|
|
1645
|
+
hb_buffer_clear(buffer);
|
|
1645
1646
|
}
|
|
1646
1647
|
|
|
1647
1648
|
static void parser_parse_foreign_content(parser_T* parser, hb_array_T* children, hb_array_T** errors) {
|
|
1648
1649
|
hb_buffer_T content;
|
|
1649
|
-
hb_buffer_init(&content,
|
|
1650
|
+
hb_buffer_init(&content, 64, parser->allocator);
|
|
1650
1651
|
position_T start = parser->current_token->location.start;
|
|
1651
1652
|
bool has_closing_tag = !hb_string_is_empty(parser->foreign_content_tag_name);
|
|
1652
1653
|
|
data/src/prism/prism_helpers.c
CHANGED
|
@@ -7,9 +7,47 @@
|
|
|
7
7
|
#include "../include/location/position.h"
|
|
8
8
|
|
|
9
9
|
#include <prism.h>
|
|
10
|
+
#include <prism/internal/comments.h>
|
|
11
|
+
#include <prism/internal/parser.h>
|
|
10
12
|
#include <stdlib.h>
|
|
11
13
|
#include <string.h>
|
|
12
14
|
|
|
15
|
+
bool herb_ruby_version_supported(const char* value, size_t length) {
|
|
16
|
+
if (value == NULL || length == 0 || length >= HERB_PARSER_OPTIONS_STRING_CAPACITY) { return false; }
|
|
17
|
+
|
|
18
|
+
pm_options_t* options = pm_options_new();
|
|
19
|
+
bool supported = pm_options_version_set(options, value, length);
|
|
20
|
+
pm_options_free(options);
|
|
21
|
+
|
|
22
|
+
return supported;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
void herb_prism_options_set_ruby_version(pm_options_t* options, const parser_options_T* parser_options) {
|
|
26
|
+
if (options == NULL || parser_options == NULL || parser_options->ruby_version[0] == '\0') { return; }
|
|
27
|
+
|
|
28
|
+
const char* version = parser_options->ruby_version;
|
|
29
|
+
pm_options_version_set(options, version, strnlen(version, HERB_PARSER_OPTIONS_STRING_CAPACITY));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
pm_parser_t* herb_prism_parser_new(
|
|
33
|
+
pm_arena_t* arena,
|
|
34
|
+
const uint8_t* source,
|
|
35
|
+
size_t length,
|
|
36
|
+
const parser_options_T* parser_options
|
|
37
|
+
) {
|
|
38
|
+
if (parser_options == NULL || parser_options->ruby_version[0] == '\0') {
|
|
39
|
+
return pm_parser_new(arena, source, length, NULL);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
pm_options_t* options = pm_options_new();
|
|
43
|
+
herb_prism_options_set_ruby_version(options, parser_options);
|
|
44
|
+
|
|
45
|
+
pm_parser_t* parser = pm_parser_new(arena, source, length, options);
|
|
46
|
+
pm_options_free(options);
|
|
47
|
+
|
|
48
|
+
return parser;
|
|
49
|
+
}
|
|
50
|
+
|
|
13
51
|
hb_string_T pm_error_level_to_string(pm_error_level_t level) {
|
|
14
52
|
switch (level) {
|
|
15
53
|
case PM_ERROR_LEVEL_SYNTAX: return hb_string("syntax");
|
|
@@ -25,16 +63,17 @@ RUBY_PARSE_ERROR_T* ruby_parse_error_from_prism_error(
|
|
|
25
63
|
pm_parser_t* parser,
|
|
26
64
|
hb_allocator_T* allocator
|
|
27
65
|
) {
|
|
28
|
-
|
|
29
|
-
size_t end_offset = (size_t) (error->location.end - parser->start);
|
|
66
|
+
(void) parser;
|
|
30
67
|
|
|
31
|
-
|
|
32
|
-
|
|
68
|
+
pm_location_t location = pm_diagnostic_location(error);
|
|
69
|
+
|
|
70
|
+
position_T start = position_from_source_with_offset(source, location.start);
|
|
71
|
+
position_T end = position_from_source_with_offset(source, herb_prism_location_end(location));
|
|
33
72
|
|
|
34
73
|
return ruby_parse_error_init(
|
|
35
|
-
hb_string(error
|
|
36
|
-
hb_string(
|
|
37
|
-
pm_error_level_to_string(error
|
|
74
|
+
hb_string(pm_diagnostic_message(error)),
|
|
75
|
+
hb_string(pm_diagnostic_type(error)),
|
|
76
|
+
pm_error_level_to_string(pm_diagnostic_error_level(error)),
|
|
38
77
|
start,
|
|
39
78
|
end,
|
|
40
79
|
allocator
|
|
@@ -48,9 +87,9 @@ RUBY_PARSE_ERROR_T* ruby_parse_error_from_prism_error_with_positions(
|
|
|
48
87
|
hb_allocator_T* allocator
|
|
49
88
|
) {
|
|
50
89
|
return ruby_parse_error_init(
|
|
51
|
-
hb_string(error
|
|
52
|
-
hb_string(
|
|
53
|
-
pm_error_level_to_string(error
|
|
90
|
+
hb_string(pm_diagnostic_message(error)),
|
|
91
|
+
hb_string(pm_diagnostic_type(error)),
|
|
92
|
+
pm_error_level_to_string(pm_diagnostic_error_level(error)),
|
|
54
93
|
start,
|
|
55
94
|
end,
|
|
56
95
|
allocator
|
|
@@ -62,55 +101,51 @@ typedef struct {
|
|
|
62
101
|
bool found;
|
|
63
102
|
} then_keyword_search_context_T;
|
|
64
103
|
|
|
65
|
-
static
|
|
66
|
-
return location.start != NULL && location.end != NULL && (location.end - location.start) > 0;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
static bool search_then_keyword_location(const pm_node_t* node, void* data) {
|
|
104
|
+
static pm_visit_result_t search_then_keyword_location(const pm_node_t* node, void* data) {
|
|
70
105
|
then_keyword_search_context_T* context = (then_keyword_search_context_T*) data;
|
|
71
106
|
|
|
72
|
-
if (context->found) { return
|
|
107
|
+
if (context->found) { return PM_VISIT_SKIP; }
|
|
73
108
|
|
|
74
109
|
switch (node->type) {
|
|
75
110
|
case PM_IF_NODE: {
|
|
76
111
|
const pm_if_node_t* if_node = (const pm_if_node_t*) node;
|
|
77
112
|
|
|
78
|
-
if (!
|
|
113
|
+
if (!herb_prism_location_present(if_node->if_keyword_loc)) { break; }
|
|
79
114
|
|
|
80
|
-
if (
|
|
115
|
+
if (herb_prism_location_present(if_node->then_keyword_loc)) {
|
|
81
116
|
context->then_keyword_loc = if_node->then_keyword_loc;
|
|
82
117
|
context->found = true;
|
|
83
|
-
return
|
|
118
|
+
return PM_VISIT_SKIP;
|
|
84
119
|
}
|
|
85
120
|
break;
|
|
86
121
|
}
|
|
87
122
|
|
|
88
123
|
case PM_UNLESS_NODE: {
|
|
89
124
|
const pm_unless_node_t* unless_node = (const pm_unless_node_t*) node;
|
|
90
|
-
if (
|
|
125
|
+
if (herb_prism_location_present(unless_node->then_keyword_loc)) {
|
|
91
126
|
context->then_keyword_loc = unless_node->then_keyword_loc;
|
|
92
127
|
context->found = true;
|
|
93
|
-
return
|
|
128
|
+
return PM_VISIT_SKIP;
|
|
94
129
|
}
|
|
95
130
|
break;
|
|
96
131
|
}
|
|
97
132
|
|
|
98
133
|
case PM_WHEN_NODE: {
|
|
99
134
|
const pm_when_node_t* when_node = (const pm_when_node_t*) node;
|
|
100
|
-
if (
|
|
135
|
+
if (herb_prism_location_present(when_node->then_keyword_loc)) {
|
|
101
136
|
context->then_keyword_loc = when_node->then_keyword_loc;
|
|
102
137
|
context->found = true;
|
|
103
|
-
return
|
|
138
|
+
return PM_VISIT_SKIP;
|
|
104
139
|
}
|
|
105
140
|
break;
|
|
106
141
|
}
|
|
107
142
|
|
|
108
143
|
case PM_IN_NODE: {
|
|
109
144
|
const pm_in_node_t* in_node = (const pm_in_node_t*) node;
|
|
110
|
-
if (
|
|
111
|
-
context->then_keyword_loc = in_node->
|
|
145
|
+
if (herb_prism_location_present(in_node->then_keyword_loc)) {
|
|
146
|
+
context->then_keyword_loc = in_node->then_keyword_loc;
|
|
112
147
|
context->found = true;
|
|
113
|
-
return
|
|
148
|
+
return PM_VISIT_SKIP;
|
|
114
149
|
}
|
|
115
150
|
break;
|
|
116
151
|
}
|
|
@@ -120,23 +155,20 @@ static bool search_then_keyword_location(const pm_node_t* node, void* data) {
|
|
|
120
155
|
|
|
121
156
|
pm_visit_child_nodes(node, search_then_keyword_location, context);
|
|
122
157
|
|
|
123
|
-
return
|
|
158
|
+
return PM_VISIT_SKIP;
|
|
124
159
|
}
|
|
125
160
|
|
|
126
161
|
location_T* get_then_keyword_location(analyzed_ruby_T* analyzed, const char* source, hb_allocator_T* allocator) {
|
|
127
162
|
if (analyzed == NULL || analyzed->root == NULL || source == NULL) { return NULL; }
|
|
128
163
|
|
|
129
|
-
then_keyword_search_context_T context = { .then_keyword_loc = { .start =
|
|
164
|
+
then_keyword_search_context_T context = { .then_keyword_loc = { .start = 0, .length = 0 }, .found = false };
|
|
130
165
|
|
|
131
166
|
pm_visit_child_nodes(analyzed->root, search_then_keyword_location, &context);
|
|
132
167
|
|
|
133
168
|
if (!context.found) { return NULL; }
|
|
134
169
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
position_T start_position = position_from_source_with_offset(source, start_offset);
|
|
139
|
-
position_T end_position = position_from_source_with_offset(source, end_offset);
|
|
170
|
+
position_T start_position = position_from_source_with_offset(source, context.then_keyword_loc.start);
|
|
171
|
+
position_T end_position = position_from_source_with_offset(source, herb_prism_location_end(context.then_keyword_loc));
|
|
140
172
|
|
|
141
173
|
return location_create(start_position, end_position, allocator);
|
|
142
174
|
}
|
|
@@ -150,25 +182,26 @@ static location_T* parse_wrapped_and_find_then_keyword(
|
|
|
150
182
|
size_t adjustment_amount,
|
|
151
183
|
hb_allocator_T* allocator
|
|
152
184
|
) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
pm_node_t* root = pm_parse(
|
|
185
|
+
pm_arena_t* arena = pm_arena_new();
|
|
186
|
+
pm_parser_t* parser = pm_parser_new(arena, (const uint8_t*) hb_buffer_value(buffer), hb_buffer_length(buffer), NULL);
|
|
187
|
+
pm_node_t* root = pm_parse(parser);
|
|
156
188
|
|
|
157
189
|
if (root == NULL) {
|
|
158
|
-
pm_parser_free(
|
|
190
|
+
pm_parser_free(parser);
|
|
191
|
+
pm_arena_free(arena);
|
|
159
192
|
|
|
160
193
|
return NULL;
|
|
161
194
|
}
|
|
162
195
|
|
|
163
|
-
then_keyword_search_context_T context = { .then_keyword_loc = { .start =
|
|
196
|
+
then_keyword_search_context_T context = { .then_keyword_loc = { .start = 0, .length = 0 }, .found = false };
|
|
164
197
|
|
|
165
198
|
pm_visit_child_nodes(root, search_then_keyword_location, &context);
|
|
166
199
|
|
|
167
200
|
location_T* location = NULL;
|
|
168
201
|
|
|
169
202
|
if (context.found) {
|
|
170
|
-
size_t start_offset =
|
|
171
|
-
size_t end_offset = (
|
|
203
|
+
size_t start_offset = context.then_keyword_loc.start;
|
|
204
|
+
size_t end_offset = herb_prism_location_end(context.then_keyword_loc);
|
|
172
205
|
|
|
173
206
|
if (start_offset >= prefix_length && end_offset >= prefix_length) {
|
|
174
207
|
start_offset -= prefix_length;
|
|
@@ -188,8 +221,8 @@ static location_T* parse_wrapped_and_find_then_keyword(
|
|
|
188
221
|
}
|
|
189
222
|
}
|
|
190
223
|
|
|
191
|
-
|
|
192
|
-
|
|
224
|
+
pm_parser_free(parser);
|
|
225
|
+
pm_arena_free(arena);
|
|
193
226
|
|
|
194
227
|
return location;
|
|
195
228
|
}
|
|
@@ -245,7 +278,7 @@ location_T* get_then_keyword_location_elsif_wrapped(const char* source, hb_alloc
|
|
|
245
278
|
return location;
|
|
246
279
|
}
|
|
247
280
|
|
|
248
|
-
static size_t newline_index_for_offset(const
|
|
281
|
+
static size_t newline_index_for_offset(const pm_line_offset_list_t* newlines, size_t offset) {
|
|
249
282
|
size_t low = 0;
|
|
250
283
|
size_t high = newlines->size;
|
|
251
284
|
|
|
@@ -267,12 +300,12 @@ void herb_prism_node_serialize(herb_prism_node_T prism_node, pm_buffer_t* buffer
|
|
|
267
300
|
|
|
268
301
|
pm_parser_t* parser = prism_node.parser;
|
|
269
302
|
|
|
270
|
-
if (prism_node.source_end == 0 || parser->
|
|
303
|
+
if (prism_node.source_end == 0 || parser->line_offsets.size == 0) {
|
|
271
304
|
pm_serialize(parser, prism_node.node, buffer);
|
|
272
305
|
return;
|
|
273
306
|
}
|
|
274
307
|
|
|
275
|
-
const
|
|
308
|
+
const pm_line_offset_list_t* newlines = &parser->line_offsets;
|
|
276
309
|
size_t first_line = newline_index_for_offset(newlines, prism_node.source_start);
|
|
277
310
|
size_t last_line = newline_index_for_offset(newlines, prism_node.source_end);
|
|
278
311
|
size_t line_count = last_line - first_line + 1;
|
|
@@ -281,21 +314,22 @@ void herb_prism_node_serialize(herb_prism_node_T prism_node, pm_buffer_t* buffer
|
|
|
281
314
|
|
|
282
315
|
pm_parser_t view = *parser;
|
|
283
316
|
|
|
284
|
-
view.
|
|
285
|
-
view.
|
|
286
|
-
view.
|
|
317
|
+
view.line_offsets.offsets = newlines->offsets + first_line;
|
|
318
|
+
view.line_offsets.size = line_count;
|
|
319
|
+
view.line_offsets.capacity = line_count;
|
|
287
320
|
view.start_line = parser->start_line + (int32_t) first_line;
|
|
288
321
|
|
|
289
322
|
memset(&view.magic_comment_list, 0, sizeof(pm_list_t));
|
|
290
323
|
memset(&view.error_list, 0, sizeof(pm_list_t));
|
|
291
324
|
memset(&view.warning_list, 0, sizeof(pm_list_t));
|
|
292
325
|
memset(&view.comment_list, 0, sizeof(pm_list_t));
|
|
326
|
+
memset(&view.comment_attachments, 0, sizeof(view.comment_attachments));
|
|
293
327
|
|
|
294
328
|
size_t comment_count = 0;
|
|
295
329
|
|
|
296
330
|
for (pm_list_node_t* entry = parser->comment_list.head; entry; entry = entry->next) {
|
|
297
331
|
pm_comment_t* comment = (pm_comment_t*) entry;
|
|
298
|
-
size_t start =
|
|
332
|
+
size_t start = comment->location.start;
|
|
299
333
|
|
|
300
334
|
if (start >= prism_node.source_start && start < prism_node.source_end) { comment_count++; }
|
|
301
335
|
}
|
|
@@ -314,7 +348,7 @@ void herb_prism_node_serialize(herb_prism_node_T prism_node, pm_buffer_t* buffer
|
|
|
314
348
|
|
|
315
349
|
for (pm_list_node_t* entry = parser->comment_list.head; entry; entry = entry->next) {
|
|
316
350
|
pm_comment_t* comment = (pm_comment_t*) entry;
|
|
317
|
-
size_t start =
|
|
351
|
+
size_t start = comment->location.start;
|
|
318
352
|
|
|
319
353
|
if (start < prism_node.source_start || start >= prism_node.source_end) { continue; }
|
|
320
354
|
|
data/src/prism/ruby_parser.c
CHANGED
|
@@ -2,51 +2,51 @@
|
|
|
2
2
|
|
|
3
3
|
#include <prism.h>
|
|
4
4
|
#include <stdbool.h>
|
|
5
|
+
#include <stdio.h>
|
|
5
6
|
#include <stdlib.h>
|
|
6
7
|
#include <string.h>
|
|
7
8
|
|
|
8
|
-
static
|
|
9
|
+
static pm_visit_result_t herb_prism_visit(const pm_node_t* node, void* data) {
|
|
9
10
|
const size_t* indent = (size_t*) data;
|
|
10
11
|
|
|
11
12
|
for (size_t i = 0; i < *indent * 2; i++) {
|
|
12
13
|
putc(' ', stdout);
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
printf("%s\n",
|
|
16
|
+
printf("%s\n", pm_node_type(node->type));
|
|
16
17
|
|
|
17
18
|
size_t next_indent = *indent + 1;
|
|
18
19
|
size_t* next_data = &next_indent;
|
|
19
20
|
pm_visit_child_nodes(node, herb_prism_visit, next_data);
|
|
20
21
|
|
|
21
|
-
return
|
|
22
|
+
return PM_VISIT_SKIP;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
void herb_parse_ruby_to_stdout(char* source) {
|
|
25
26
|
size_t length = strlen(source);
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
pm_arena_t* arena = pm_arena_new();
|
|
29
|
+
pm_parser_t* parser = pm_parser_new(arena, (const uint8_t*) source, length, NULL);
|
|
29
30
|
|
|
30
|
-
pm_buffer_t buffer;
|
|
31
|
-
pm_buffer_init(&buffer);
|
|
31
|
+
pm_buffer_t* buffer = pm_buffer_new();
|
|
32
32
|
|
|
33
33
|
size_t indent = 0;
|
|
34
|
-
pm_node_t* root = pm_parse(
|
|
34
|
+
pm_node_t* root = pm_parse(parser);
|
|
35
35
|
size_t* data = &indent;
|
|
36
36
|
|
|
37
|
-
const char* root_type =
|
|
37
|
+
const char* root_type = pm_node_type(root->type);
|
|
38
38
|
printf("Root Type: %s\n", root_type);
|
|
39
39
|
|
|
40
40
|
pm_visit_node(root, herb_prism_visit, data);
|
|
41
41
|
|
|
42
42
|
#ifndef PRISM_EXCLUDE_PRETTYPRINT
|
|
43
|
-
pm_prettyprint(
|
|
44
|
-
printf("
|
|
43
|
+
pm_prettyprint(buffer, parser, root);
|
|
44
|
+
printf("%.*s\n", (int) pm_buffer_length(buffer), pm_buffer_value(buffer));
|
|
45
45
|
#endif
|
|
46
46
|
|
|
47
|
-
pm_buffer_free(
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
pm_buffer_free(buffer);
|
|
48
|
+
pm_parser_free(parser);
|
|
49
|
+
pm_arena_free(arena);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
static const char* const RUBY_FRAGMENT_PREFIXES[] = {
|
|
@@ -56,14 +56,14 @@ static const char* const RUBY_FRAGMENT_PREFIXES[] = {
|
|
|
56
56
|
static const char* const RUBY_FRAGMENT_SUFFIXES[] = { "", "\nend", "", "\nend", "\nend", "\nend" };
|
|
57
57
|
|
|
58
58
|
static bool ruby_source_parses(const char* source, size_t length) {
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
pm_arena_t* arena = pm_arena_new();
|
|
60
|
+
pm_parser_t* parser = pm_parser_new(arena, (const uint8_t*) source, length, NULL);
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
bool parses = (parser
|
|
62
|
+
pm_parse(parser);
|
|
63
|
+
bool parses = (pm_parser_errors_size(parser) == 0);
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
pm_parser_free(parser);
|
|
66
|
+
pm_arena_free(arena);
|
|
67
67
|
|
|
68
68
|
return parses;
|
|
69
69
|
}
|
|
@@ -69,17 +69,17 @@ static VALUE rb_<%= node.human %>_from_c_struct(<%= node.struct_type %>* <%= nod
|
|
|
69
69
|
<%- when Herb::Template::PrismNodeField -%>
|
|
70
70
|
VALUE <%= node.human %>_<%= field.name %>;
|
|
71
71
|
if (<%= node.human %>-><%= field.name %>.node != NULL && <%= node.human %>-><%= field.name %>.parser != NULL) {
|
|
72
|
-
pm_buffer_t pm_buffer =
|
|
73
|
-
herb_prism_node_serialize(<%= node.human %>-><%= field.name %>,
|
|
72
|
+
pm_buffer_t* pm_buffer = pm_buffer_new();
|
|
73
|
+
herb_prism_node_serialize(<%= node.human %>-><%= field.name %>, pm_buffer);
|
|
74
74
|
|
|
75
|
-
if (pm_buffer
|
|
76
|
-
<%= node.human %>_<%= field.name %> = rb_str_new(pm_buffer
|
|
75
|
+
if (pm_buffer_length(pm_buffer) > 0) {
|
|
76
|
+
<%= node.human %>_<%= field.name %> = rb_str_new(pm_buffer_value(pm_buffer), pm_buffer_length(pm_buffer));
|
|
77
77
|
rb_enc_associate(<%= node.human %>_<%= field.name %>, rb_ascii8bit_encoding());
|
|
78
78
|
OBJ_FREEZE(<%= node.human %>_<%= field.name %>);
|
|
79
79
|
} else {
|
|
80
80
|
<%= node.human %>_<%= field.name %> = Qnil;
|
|
81
81
|
}
|
|
82
|
-
pm_buffer_free(
|
|
82
|
+
pm_buffer_free(pm_buffer);
|
|
83
83
|
} else {
|
|
84
84
|
<%= node.human %>_<%= field.name %> = Qnil;
|
|
85
85
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#include "parser_options_helpers.h"
|
|
2
2
|
|
|
3
|
+
#include <string.h>
|
|
4
|
+
|
|
3
5
|
void herb_extract_parser_options(VALUE options, parser_options_T* parser_options) {
|
|
4
6
|
if (NIL_P(options)) { return; }
|
|
5
7
|
<%- parser_options.extractable_fields_for(:ruby).each do |field| -%>
|
|
@@ -10,6 +12,31 @@ void herb_extract_parser_options(VALUE options, parser_options_T* parser_options
|
|
|
10
12
|
if (NIL_P(value)) { value = rb_hash_lookup(options, ID2SYM(rb_intern("<%= field.snake_case %>"))); }
|
|
11
13
|
if (!NIL_P(value)) { parser_options-><%= field.c_name %> = RTEST(value); }
|
|
12
14
|
}
|
|
15
|
+
<%- elsif field.string? -%>
|
|
16
|
+
{
|
|
17
|
+
VALUE value = rb_hash_lookup(options, rb_utf8_str_new_cstr("<%= field.snake_case %>"));
|
|
18
|
+
if (NIL_P(value)) { value = rb_hash_lookup(options, ID2SYM(rb_intern("<%= field.snake_case %>"))); }
|
|
19
|
+
|
|
20
|
+
if (!NIL_P(value)) {
|
|
21
|
+
Check_Type(value, T_STRING);
|
|
22
|
+
|
|
23
|
+
const char* data = RSTRING_PTR(value);
|
|
24
|
+
size_t length = (size_t) RSTRING_LEN(value);
|
|
25
|
+
|
|
26
|
+
<%- if field.validator -%>
|
|
27
|
+
if (!<%= field.validator %>(data, length)) {
|
|
28
|
+
rb_raise(rb_eArgError, "<%= field.snake_case %> %+" PRIsVALUE " is not supported", value);
|
|
29
|
+
}
|
|
30
|
+
<%- else -%>
|
|
31
|
+
if (length >= HERB_PARSER_OPTIONS_STRING_CAPACITY) {
|
|
32
|
+
rb_raise(rb_eArgError, "<%= field.snake_case %> must be shorter than %d bytes", HERB_PARSER_OPTIONS_STRING_CAPACITY);
|
|
33
|
+
}
|
|
34
|
+
<%- end -%>
|
|
35
|
+
|
|
36
|
+
memcpy(parser_options-><%= field.c_name %>, data, length);
|
|
37
|
+
parser_options-><%= field.c_name %>[length] = '\0';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
13
40
|
<%- elsif field.ruby_unit == "seconds" -%>
|
|
14
41
|
{
|
|
15
42
|
VALUE value = rb_hash_lookup(options, rb_utf8_str_new_cstr("<%= field.snake_case %>"));
|
|
@@ -52,6 +79,12 @@ VALUE herb_build_parser_options_hash(const parser_options_T* options) {
|
|
|
52
79
|
|
|
53
80
|
rb_hash_aset(kwargs, ID2SYM(rb_intern("<%= field.snake_case %>")), <%= field.snake_case %>);
|
|
54
81
|
}
|
|
82
|
+
<%- elsif field.string? -%>
|
|
83
|
+
rb_hash_aset(
|
|
84
|
+
kwargs,
|
|
85
|
+
ID2SYM(rb_intern("<%= field.snake_case %>")),
|
|
86
|
+
options-><%= field.c_name %>[0] == '\0' ? Qnil : rb_utf8_str_new_cstr(options-><%= field.c_name %>)
|
|
87
|
+
);
|
|
55
88
|
<%- elsif field.ruby_unit == "seconds" -%>
|
|
56
89
|
rb_hash_aset(kwargs, ID2SYM(rb_intern("<%= field.snake_case %>")), DBL2NUM((double) options-><%= field.c_name %> / 1000.0));
|
|
57
90
|
<%- elsif field.nullable? -%>
|
data/templates/java/nodes.c.erb
CHANGED
|
@@ -49,15 +49,15 @@ jobject <%= node.name %>FromCStruct(JNIEnv* env, <%= node.struct_type %>* <%= no
|
|
|
49
49
|
<%- elsif field.is_a?(Herb::Template::PrismNodeField) -%>
|
|
50
50
|
jbyteArray <%= field.name %>;
|
|
51
51
|
if (<%= node.human %>-><%= field.name %>.node != NULL && <%= node.human %>-><%= field.name %>.parser != NULL) {
|
|
52
|
-
pm_buffer_t pm_buffer =
|
|
53
|
-
herb_prism_node_serialize(<%= node.human %>-><%= field.name %>,
|
|
54
|
-
if (pm_buffer
|
|
55
|
-
<%= field.name %> = (*env)->NewByteArray(env, (jsize)pm_buffer
|
|
56
|
-
(*env)->SetByteArrayRegion(env, <%= field.name %>, 0, (jsize)pm_buffer
|
|
52
|
+
pm_buffer_t* pm_buffer = pm_buffer_new();
|
|
53
|
+
herb_prism_node_serialize(<%= node.human %>-><%= field.name %>, pm_buffer);
|
|
54
|
+
if (pm_buffer_length(pm_buffer) > 0) {
|
|
55
|
+
<%= field.name %> = (*env)->NewByteArray(env, (jsize)pm_buffer_length(pm_buffer));
|
|
56
|
+
(*env)->SetByteArrayRegion(env, <%= field.name %>, 0, (jsize)pm_buffer_length(pm_buffer), (const jbyte*)pm_buffer_value(pm_buffer));
|
|
57
57
|
} else {
|
|
58
58
|
<%= field.name %> = NULL;
|
|
59
59
|
}
|
|
60
|
-
pm_buffer_free(
|
|
60
|
+
pm_buffer_free(pm_buffer);
|
|
61
61
|
} else {
|
|
62
62
|
<%= field.name %> = NULL;
|
|
63
63
|
}
|