herb 0.11.0-aarch64-linux-gnu → 0.11.2-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.
- checksums.yaml +4 -4
- data/Rakefile +4 -2
- data/config.yml +9 -0
- data/ext/herb/extconf.rb +8 -31
- data/ext/herb/nodes.c +90 -73
- 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/helpers.rb +1 -1
- data/lib/herb/ast/nodes.rb +32 -6
- data/lib/herb/bootstrap.rb +6 -2
- data/lib/herb/configuration.rb +11 -1
- data/lib/herb/dev/classifier.rb +1 -1
- data/lib/herb/dev/runner.rb +6 -1
- data/lib/herb/engine/compiler.rb +52 -19
- data/lib/herb/engine/slots/dynamics_compiler.rb +63 -14
- data/lib/herb/engine/slots/markers.rb +24 -0
- data/lib/herb/engine/slots/state_compiler.rb +1 -2
- data/lib/herb/engine/slots/subtree_compiler.rb +1 -1
- data/lib/herb/engine/slots/visitor.rb +71 -32
- data/lib/herb/engine/visitors/instrumentation_visitor.rb +18 -6
- data/lib/herb/engine.rb +0 -2
- 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/nodes.rbs +10 -4
- data/sig/herb/bootstrap.rbs +2 -0
- data/sig/herb/configuration.rbs +3 -0
- data/sig/herb/dev/runner.rbs +3 -0
- data/sig/herb/engine/compiler.rbs +14 -3
- data/sig/herb/engine/slots/dynamics_compiler.rbs +27 -7
- data/sig/herb/engine/slots/markers.rbs +14 -0
- data/sig/herb/engine/slots/visitor.rbs +31 -13
- data/sig/herb/engine/visitors/instrumentation_visitor.rbs +5 -1
- data/sig/herb/parser_options.rbs +6 -4
- data/sig/herb.rbs +2 -2
- data/sig/serialized_ast_nodes.rbs +1 -0
- 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 +12 -16
- data/src/analyze/action_view/tag_helpers.c +215 -110
- data/src/analyze/action_view/turbo_frame_tag.c +5 -4
- data/src/analyze/analyze.c +41 -45
- data/src/analyze/analyze_helpers.c +240 -405
- data/src/analyze/analyzed_ruby.c +10 -7
- data/src/analyze/builders.c +1 -0
- data/src/analyze/control_type.c +46 -29
- 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 +56 -32
- data/src/analyze/render_nodes.c +51 -41
- data/src/analyze/strict_locals.c +14 -15
- data/src/analyze/ternary_conditionals.c +14 -10
- data/src/ast/ast_nodes.c +3 -1
- data/src/ast/ast_pretty_print.c +5 -1
- data/src/extract.c +204 -143
- 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 -24
- data/src/include/analyze/analyzed_ruby.h +29 -2
- data/src/include/analyze/helpers.h +7 -27
- data/src/include/ast/ast_nodes.h +2 -1
- data/src/include/herb.h +3 -2
- data/src/include/lexer/lexer.h +1 -0
- data/src/include/parser/parser_options.h +5 -0
- data/src/include/prism/herb_prism_node.h +6 -1
- 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.c +32 -0
- data/src/parser/parser_helpers.c +1 -2
- data/src/parser.c +6 -7
- data/src/parser_options_defaults.c +1 -0
- data/src/prism/prism_helpers.c +167 -42
- 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/core/src/nodes.ts.erb +21 -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/ast/nodes.rs.erb +1 -4
- 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/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 +8 -18
- 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
|
@@ -3,11 +3,36 @@
|
|
|
3
3
|
|
|
4
4
|
#include "../lib/hb_array.h"
|
|
5
5
|
#include "../lib/hb_string.h"
|
|
6
|
+
#include "../parser/parser_options.h"
|
|
6
7
|
|
|
7
8
|
#include <prism.h>
|
|
9
|
+
#include <stdbool.h>
|
|
10
|
+
|
|
11
|
+
typedef enum {
|
|
12
|
+
CONTROL_TYPE_IF,
|
|
13
|
+
CONTROL_TYPE_ELSIF,
|
|
14
|
+
CONTROL_TYPE_ELSE,
|
|
15
|
+
CONTROL_TYPE_END,
|
|
16
|
+
CONTROL_TYPE_CASE,
|
|
17
|
+
CONTROL_TYPE_CASE_MATCH,
|
|
18
|
+
CONTROL_TYPE_WHEN,
|
|
19
|
+
CONTROL_TYPE_IN,
|
|
20
|
+
CONTROL_TYPE_BEGIN,
|
|
21
|
+
CONTROL_TYPE_RESCUE,
|
|
22
|
+
CONTROL_TYPE_ENSURE,
|
|
23
|
+
CONTROL_TYPE_UNLESS,
|
|
24
|
+
CONTROL_TYPE_WHILE,
|
|
25
|
+
CONTROL_TYPE_UNTIL,
|
|
26
|
+
CONTROL_TYPE_FOR,
|
|
27
|
+
CONTROL_TYPE_BLOCK,
|
|
28
|
+
CONTROL_TYPE_BLOCK_CLOSE,
|
|
29
|
+
CONTROL_TYPE_YIELD,
|
|
30
|
+
CONTROL_TYPE_UNKNOWN
|
|
31
|
+
} control_type_t;
|
|
8
32
|
|
|
9
33
|
typedef struct ANALYZED_RUBY_STRUCT {
|
|
10
|
-
|
|
34
|
+
pm_arena_t* arena;
|
|
35
|
+
pm_parser_t* parser;
|
|
11
36
|
pm_node_t* root;
|
|
12
37
|
bool valid;
|
|
13
38
|
bool parsed;
|
|
@@ -31,9 +56,11 @@ typedef struct ANALYZED_RUBY_STRUCT {
|
|
|
31
56
|
int yield_node_count;
|
|
32
57
|
int then_keyword_count;
|
|
33
58
|
int unclosed_control_flow_count;
|
|
59
|
+
control_type_t control_type;
|
|
60
|
+
bool control_type_detected;
|
|
34
61
|
} analyzed_ruby_T;
|
|
35
62
|
|
|
36
|
-
analyzed_ruby_T* init_analyzed_ruby(hb_string_T source);
|
|
63
|
+
analyzed_ruby_T* init_analyzed_ruby(hb_string_T source, const parser_options_T* options);
|
|
37
64
|
void free_analyzed_ruby(analyzed_ruby_T* analyzed);
|
|
38
65
|
hb_string_T erb_keyword_from_analyzed_ruby(const analyzed_ruby_T* analyzed);
|
|
39
66
|
|
|
@@ -37,34 +37,14 @@ bool control_role_split_offset(const analyzed_ruby_T* analyzed, uint32_t* offset
|
|
|
37
37
|
|
|
38
38
|
bool has_error_message(analyzed_ruby_T* anlayzed, const char* message);
|
|
39
39
|
|
|
40
|
-
bool is_do_block(pm_location_t opening_location);
|
|
41
|
-
bool is_brace_block(pm_location_t opening_location);
|
|
42
|
-
bool is_closing_brace(pm_location_t location);
|
|
43
|
-
bool has_valid_block_closing(pm_location_t opening_loc, pm_location_t closing_loc);
|
|
40
|
+
bool is_do_block(const uint8_t* source, pm_location_t opening_location);
|
|
41
|
+
bool is_brace_block(const uint8_t* source, pm_location_t opening_location);
|
|
42
|
+
bool is_closing_brace(const uint8_t* source, pm_location_t location);
|
|
43
|
+
bool has_valid_block_closing(const uint8_t* source, pm_location_t opening_loc, pm_location_t closing_loc);
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
bool search_case_nodes(const pm_node_t* node, void* data);
|
|
49
|
-
bool search_for_nodes(const pm_node_t* node, void* data);
|
|
50
|
-
bool search_if_nodes(const pm_node_t* node, void* data);
|
|
51
|
-
bool search_in_nodes(const pm_node_t* node, void* data);
|
|
52
|
-
bool search_then_keywords(const pm_node_t* node, void* data);
|
|
53
|
-
bool search_unclosed_control_flows(const pm_node_t* node, void* data);
|
|
54
|
-
bool search_unless_nodes(const pm_node_t* node, void* data);
|
|
55
|
-
bool search_until_nodes(const pm_node_t* node, void* data);
|
|
56
|
-
bool search_when_nodes(const pm_node_t* node, void* data);
|
|
57
|
-
bool search_while_nodes(const pm_node_t* node, void* data);
|
|
58
|
-
bool search_yield_nodes(const pm_node_t* node, void* data);
|
|
59
|
-
|
|
60
|
-
bool search_unexpected_block_closing_nodes(analyzed_ruby_T* analyzed);
|
|
61
|
-
bool search_unexpected_else_nodes(analyzed_ruby_T* analyzed);
|
|
62
|
-
bool search_unexpected_elsif_nodes(analyzed_ruby_T* analyzed);
|
|
63
|
-
bool search_unexpected_end_nodes(analyzed_ruby_T* analyzed);
|
|
64
|
-
bool search_unexpected_ensure_nodes(analyzed_ruby_T* analyzed);
|
|
65
|
-
bool search_unexpected_in_nodes(analyzed_ruby_T* analyzed);
|
|
66
|
-
bool search_unexpected_rescue_nodes(analyzed_ruby_T* analyzed);
|
|
67
|
-
bool search_unexpected_when_nodes(analyzed_ruby_T* analyzed);
|
|
45
|
+
pm_visit_result_t search_control_flow_nodes(const pm_node_t* node, void* data);
|
|
46
|
+
pm_visit_result_t search_unclosed_control_flows(const pm_node_t* node, void* data);
|
|
47
|
+
void search_unexpected_keyword_errors(analyzed_ruby_T* analyzed);
|
|
68
48
|
|
|
69
49
|
void check_erb_node_for_missing_end(const AST_NODE_T* node, hb_allocator_T* allocator, const parser_options_T* options);
|
|
70
50
|
|
data/src/include/ast/ast_nodes.h
CHANGED
|
@@ -478,6 +478,7 @@ typedef struct AST_ERB_YIELD_NODE_STRUCT {
|
|
|
478
478
|
token_T* tag_opening;
|
|
479
479
|
token_T* content;
|
|
480
480
|
token_T* tag_closing;
|
|
481
|
+
herb_prism_node_T prism_node;
|
|
481
482
|
} AST_ERB_YIELD_NODE_T;
|
|
482
483
|
|
|
483
484
|
typedef struct AST_ERB_IN_NODE_STRUCT {
|
|
@@ -565,7 +566,7 @@ AST_RUBY_RENDER_KEYWORDS_NODE_T* ast_ruby_render_keywords_node_init(token_T* par
|
|
|
565
566
|
AST_ERB_RENDER_NODE_T* ast_erb_render_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, analyzed_ruby_T* analyzed_ruby, herb_prism_node_T prism_node, struct AST_RUBY_RENDER_KEYWORDS_NODE_STRUCT* keywords, hb_array_T* body, hb_array_T* block_arguments, struct AST_ERB_RESCUE_NODE_STRUCT* rescue_clause, struct AST_ERB_ELSE_NODE_STRUCT* else_clause, struct AST_ERB_ENSURE_NODE_STRUCT* ensure_clause, struct AST_ERB_END_NODE_STRUCT* end_node, position_T start_position, position_T end_position, hb_array_T* errors, hb_allocator_T* allocator);
|
|
566
567
|
AST_RUBY_PARAMETER_NODE_T* ast_ruby_parameter_node_init(token_T* name, struct AST_RUBY_LITERAL_NODE_STRUCT* default_value, hb_string_T kind, bool required, position_T start_position, position_T end_position, hb_array_T* errors, hb_allocator_T* allocator);
|
|
567
568
|
AST_ERB_STRICT_LOCALS_NODE_T* ast_erb_strict_locals_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, analyzed_ruby_T* analyzed_ruby, herb_prism_node_T prism_node, hb_array_T* locals, position_T start_position, position_T end_position, hb_array_T* errors, hb_allocator_T* allocator);
|
|
568
|
-
AST_ERB_YIELD_NODE_T* ast_erb_yield_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, position_T start_position, position_T end_position, hb_array_T* errors, hb_allocator_T* allocator);
|
|
569
|
+
AST_ERB_YIELD_NODE_T* ast_erb_yield_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, herb_prism_node_T prism_node, position_T start_position, position_T end_position, hb_array_T* errors, hb_allocator_T* allocator);
|
|
569
570
|
AST_ERB_IN_NODE_T* ast_erb_in_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, location_T* then_keyword, hb_array_T* statements, position_T start_position, position_T end_position, hb_array_T* errors, hb_allocator_T* allocator);
|
|
570
571
|
AST_HERB_DIRECTIVE_NODE_T* ast_herb_directive_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, token_T* key, token_T* arguments, position_T start_position, position_T end_position, hb_array_T* errors, hb_allocator_T* allocator);
|
|
571
572
|
AST_HERB_STATE_DECLARATION_NODE_T* ast_herb_state_declaration_node_init(token_T* name, struct AST_RUBY_LITERAL_NODE_STRUCT* default_value, hb_string_T kind, position_T start_position, position_T end_position, hb_array_T* errors, hb_allocator_T* allocator);
|
data/src/include/herb.h
CHANGED
|
@@ -36,9 +36,10 @@ HERB_EXPORTED_FUNCTION const char* herb_version(void);
|
|
|
36
36
|
HERB_EXPORTED_FUNCTION const char* herb_prism_version(void);
|
|
37
37
|
|
|
38
38
|
typedef struct {
|
|
39
|
-
|
|
39
|
+
pm_arena_t* arena;
|
|
40
|
+
pm_parser_t* parser;
|
|
40
41
|
pm_node_t* root;
|
|
41
|
-
pm_options_t options;
|
|
42
|
+
pm_options_t* options;
|
|
42
43
|
} herb_ruby_parse_result_T;
|
|
43
44
|
|
|
44
45
|
HERB_EXPORTED_FUNCTION herb_ruby_parse_result_T* herb_parse_ruby(const char* source, size_t length);
|
data/src/include/lexer/lexer.h
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
#include <stddef.h>
|
|
11
11
|
#include <stdint.h>
|
|
12
12
|
|
|
13
|
+
#define HERB_PARSER_OPTIONS_STRING_CAPACITY 16
|
|
14
|
+
|
|
13
15
|
typedef struct PARSER_OPTIONS_STRUCT {
|
|
14
16
|
bool action_view_helpers;
|
|
15
17
|
bool analyze;
|
|
@@ -24,6 +26,7 @@ typedef struct PARSER_OPTIONS_STRUCT {
|
|
|
24
26
|
bool prism_nodes_deep;
|
|
25
27
|
bool prism_program;
|
|
26
28
|
bool render_nodes;
|
|
29
|
+
char ruby_version[HERB_PARSER_OPTIONS_STRING_CAPACITY];
|
|
27
30
|
bool strict;
|
|
28
31
|
bool strict_locals;
|
|
29
32
|
uint32_t timeout_ms;
|
|
@@ -38,4 +41,6 @@ typedef struct PARSER_OPTIONS_STRUCT {
|
|
|
38
41
|
|
|
39
42
|
extern const parser_options_T HERB_DEFAULT_PARSER_OPTIONS;
|
|
40
43
|
|
|
44
|
+
bool herb_ruby_version_supported(const char* value, size_t length);
|
|
45
|
+
|
|
41
46
|
#endif
|
|
@@ -2,12 +2,17 @@
|
|
|
2
2
|
#define HERB_PRISM_NODE_H
|
|
3
3
|
|
|
4
4
|
#include <prism.h>
|
|
5
|
+
#include <stdint.h>
|
|
5
6
|
|
|
6
7
|
typedef struct {
|
|
7
8
|
pm_node_t* node;
|
|
8
9
|
pm_parser_t* parser;
|
|
10
|
+
uint32_t source_start;
|
|
11
|
+
uint32_t source_end;
|
|
9
12
|
} herb_prism_node_T;
|
|
10
13
|
|
|
11
|
-
#define HERB_PRISM_NODE_EMPTY ((herb_prism_node_T) { .node = NULL, .parser = NULL })
|
|
14
|
+
#define HERB_PRISM_NODE_EMPTY ((herb_prism_node_T) { .node = NULL, .parser = NULL, .source_start = 0, .source_end = 0 })
|
|
15
|
+
|
|
16
|
+
void herb_prism_node_serialize(herb_prism_node_T prism_node, pm_buffer_t* buffer);
|
|
12
17
|
|
|
13
18
|
#endif
|
|
@@ -7,14 +7,16 @@
|
|
|
7
7
|
#include <stdbool.h>
|
|
8
8
|
|
|
9
9
|
typedef struct {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
pm_arena_t* arena;
|
|
11
|
+
pm_parser_t* parser;
|
|
12
|
+
pm_options_t* pm_opts;
|
|
12
13
|
pm_node_t* root;
|
|
13
14
|
hb_buffer_T ruby_buf;
|
|
14
15
|
|
|
15
16
|
bool has_structural;
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
pm_arena_t* structural_arena;
|
|
18
|
+
pm_parser_t* structural_parser;
|
|
19
|
+
pm_options_t* structural_pm_opts;
|
|
18
20
|
pm_node_t* structural_root;
|
|
19
21
|
hb_buffer_T structural_buf;
|
|
20
22
|
|
|
@@ -24,17 +26,15 @@ typedef struct {
|
|
|
24
26
|
static inline void herb_prism_context_free(herb_prism_context_T* context) {
|
|
25
27
|
if (!context) { return; }
|
|
26
28
|
|
|
27
|
-
if (context->
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
pm_options_free(&context->pm_opts);
|
|
29
|
+
if (context->parser) { pm_parser_free(context->parser); }
|
|
30
|
+
if (context->arena) { pm_arena_free(context->arena); }
|
|
31
|
+
if (context->pm_opts) { pm_options_free(context->pm_opts); }
|
|
31
32
|
hb_buffer_free(&context->ruby_buf);
|
|
32
33
|
|
|
33
34
|
if (context->has_structural) {
|
|
34
|
-
if (context->
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
pm_options_free(&context->structural_pm_opts);
|
|
35
|
+
if (context->structural_parser) { pm_parser_free(context->structural_parser); }
|
|
36
|
+
if (context->structural_arena) { pm_arena_free(context->structural_arena); }
|
|
37
|
+
if (context->structural_pm_opts) { pm_options_free(context->structural_pm_opts); }
|
|
38
38
|
|
|
39
39
|
if (context->structural_buf.value) { hb_buffer_free(&context->structural_buf); }
|
|
40
40
|
}
|
|
@@ -7,9 +7,39 @@
|
|
|
7
7
|
#include "../lib/hb_allocator.h"
|
|
8
8
|
#include "../location/location.h"
|
|
9
9
|
#include "../location/position.h"
|
|
10
|
+
#include "../parser/parser_options.h"
|
|
10
11
|
|
|
11
12
|
#include <prism.h>
|
|
12
13
|
|
|
14
|
+
static inline bool herb_prism_location_present(pm_location_t location) {
|
|
15
|
+
return location.length > 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static inline bool herb_prism_location_assigned(pm_location_t location) {
|
|
19
|
+
return location.start != 0 || location.length != 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static inline uint32_t herb_prism_location_end(pm_location_t location) {
|
|
23
|
+
return location.start + location.length;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static inline const uint8_t* herb_prism_location_start_pointer(const uint8_t* base, pm_location_t location) {
|
|
27
|
+
return base + location.start;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static inline const uint8_t* herb_prism_location_end_pointer(const uint8_t* base, pm_location_t location) {
|
|
31
|
+
return base + location.start + location.length;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
void herb_prism_options_set_ruby_version(pm_options_t* options, const parser_options_T* parser_options);
|
|
35
|
+
|
|
36
|
+
pm_parser_t* herb_prism_parser_new(
|
|
37
|
+
pm_arena_t* arena,
|
|
38
|
+
const uint8_t* source,
|
|
39
|
+
size_t length,
|
|
40
|
+
const parser_options_T* parser_options
|
|
41
|
+
);
|
|
42
|
+
|
|
13
43
|
hb_string_T pm_error_level_to_string(pm_error_level_t level);
|
|
14
44
|
|
|
15
45
|
RUBY_PARSE_ERROR_T* ruby_parse_error_from_prism_error(
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
2
|
+
// be modified manually. See templates/src/include/prism_version.h.erb
|
|
3
|
+
|
|
4
|
+
#ifndef HERB_PRISM_VERSION_H
|
|
5
|
+
#define HERB_PRISM_VERSION_H
|
|
6
|
+
|
|
7
|
+
#include <prism/version.h>
|
|
8
|
+
|
|
9
|
+
#define HERB_PRISM_VERSION PRISM_VERSION "+4691667"
|
|
10
|
+
|
|
11
|
+
#endif
|
data/src/include/version.h
CHANGED
data/src/lexer.c
CHANGED
|
@@ -430,6 +430,38 @@ static token_T* lexer_parse_erb_close(lexer_T* lexer) {
|
|
|
430
430
|
return lexer_advance_with(lexer, hb_string("%>"), TOKEN_ERB_END);
|
|
431
431
|
}
|
|
432
432
|
|
|
433
|
+
void lexer_skip_data_to(lexer_T* lexer, uint32_t position) {
|
|
434
|
+
if (position > lexer->source.length) { position = lexer->source.length; }
|
|
435
|
+
|
|
436
|
+
while (lexer->current_position < position && !lexer_eof(lexer)) {
|
|
437
|
+
char character = lexer->current_character;
|
|
438
|
+
|
|
439
|
+
if (character == '\r' && lexer_peek(lexer, 1) == '\n') {
|
|
440
|
+
lexer->current_position += 2;
|
|
441
|
+
lexer->current_line++;
|
|
442
|
+
lexer->current_column = 0;
|
|
443
|
+
} else if (is_newline(character)) {
|
|
444
|
+
lexer->current_position++;
|
|
445
|
+
lexer->current_line++;
|
|
446
|
+
lexer->current_column = 0;
|
|
447
|
+
} else if ((unsigned char) character < 0x80) {
|
|
448
|
+
lexer->current_position++;
|
|
449
|
+
lexer->current_column++;
|
|
450
|
+
} else {
|
|
451
|
+
uint32_t length = utf8_sequence_length(hb_string_slice(lexer->source, lexer->current_position));
|
|
452
|
+
|
|
453
|
+
lexer->current_position += length > 0 ? length : 1;
|
|
454
|
+
lexer->current_column++;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
lexer->current_character = lexer->source.data[lexer->current_position];
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
lexer->previous_line = lexer->current_line;
|
|
461
|
+
lexer->previous_column = lexer->current_column;
|
|
462
|
+
lexer->previous_position = lexer->current_position;
|
|
463
|
+
}
|
|
464
|
+
|
|
433
465
|
// ===== Tokenizing Function
|
|
434
466
|
|
|
435
467
|
token_T* lexer_next_token(lexer_T* lexer) {
|
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
|
|
|
@@ -816,7 +816,7 @@ static AST_HTML_ATTRIBUTE_NODE_T* parser_parse_html_attribute(parser_T* parser)
|
|
|
816
816
|
|
|
817
817
|
if (has_equals) {
|
|
818
818
|
hb_buffer_T equals_buffer;
|
|
819
|
-
hb_buffer_init(&equals_buffer,
|
|
819
|
+
hb_buffer_init(&equals_buffer, 16, parser->allocator);
|
|
820
820
|
position_T equals_start = { 0 };
|
|
821
821
|
position_T equals_end = { 0 };
|
|
822
822
|
uint32_t range_start = 0;
|
|
@@ -1640,13 +1640,12 @@ static void parser_append_foreign_content_from_buffer(
|
|
|
1640
1640
|
ast_html_text_node_init(content, start, parser->current_token->location.start, NULL, parser->allocator)
|
|
1641
1641
|
);
|
|
1642
1642
|
|
|
1643
|
-
|
|
1644
|
-
hb_buffer_init(buffer, 128, parser->allocator);
|
|
1643
|
+
hb_buffer_clear(buffer);
|
|
1645
1644
|
}
|
|
1646
1645
|
|
|
1647
1646
|
static void parser_parse_foreign_content(parser_T* parser, hb_array_T* children, hb_array_T** errors) {
|
|
1648
1647
|
hb_buffer_T content;
|
|
1649
|
-
hb_buffer_init(&content,
|
|
1648
|
+
hb_buffer_init(&content, 64, parser->allocator);
|
|
1650
1649
|
position_T start = parser->current_token->location.start;
|
|
1651
1650
|
bool has_closing_tag = !hb_string_is_empty(parser->foreign_content_tag_name);
|
|
1652
1651
|
|