herb 0.11.1 → 0.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +4 -2
- data/config.yml +6 -0
- 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/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/configuration.rb +11 -1
- data/lib/herb/dev/classifier.rb +1 -1
- data/lib/herb/engine/compiler.rb +5 -8
- data/lib/herb/engine/slots/dynamics_compiler.rb +53 -14
- data/lib/herb/engine/slots/subtree_compiler.rb +1 -1
- data/lib/herb/engine/slots/visitor.rb +32 -4
- data/lib/herb/engine/visitors/instrumentation_visitor.rb +18 -6
- 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/configuration.rbs +3 -0
- data/sig/herb/engine/slots/dynamics_compiler.rbs +24 -7
- data/sig/herb/engine/slots/visitor.rbs +14 -0
- 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/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 +139 -90
- data/src/analyze/action_view/turbo_frame_tag.c +5 -4
- data/src/analyze/analyze.c +35 -19
- 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 +51 -41
- data/src/analyze/strict_locals.c +14 -15
- data/src/analyze/ternary_conditionals.c +14 -10
- 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/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/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 +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/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
|
@@ -6,16 +6,31 @@
|
|
|
6
6
|
#ifndef PRISM_OPTIONS_H
|
|
7
7
|
#define PRISM_OPTIONS_H
|
|
8
8
|
|
|
9
|
-
#include "prism/
|
|
10
|
-
#include "prism/
|
|
11
|
-
#include "prism/
|
|
9
|
+
#include "prism/compiler/exported.h"
|
|
10
|
+
#include "prism/compiler/nodiscard.h"
|
|
11
|
+
#include "prism/compiler/nonnull.h"
|
|
12
|
+
|
|
13
|
+
#include "prism/stringy.h"
|
|
12
14
|
|
|
13
15
|
#include <stdbool.h>
|
|
14
16
|
#include <stddef.h>
|
|
15
|
-
|
|
17
|
+
|
|
18
|
+
#ifdef __cplusplus
|
|
19
|
+
extern "C" {
|
|
20
|
+
#endif
|
|
16
21
|
|
|
17
22
|
/**
|
|
18
|
-
*
|
|
23
|
+
* A scope of locals surrounding the code that is being parsed.
|
|
24
|
+
*/
|
|
25
|
+
typedef struct pm_options_scope_t pm_options_scope_t;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The options that can be passed to the parser.
|
|
29
|
+
*/
|
|
30
|
+
typedef struct pm_options_t pm_options_t;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* String literals should not be frozen.
|
|
19
34
|
*/
|
|
20
35
|
#define PM_OPTIONS_FROZEN_STRING_LITERAL_DISABLED ((int8_t) -1)
|
|
21
36
|
|
|
@@ -26,42 +41,25 @@
|
|
|
26
41
|
#define PM_OPTIONS_FROZEN_STRING_LITERAL_UNSET ((int8_t) 0)
|
|
27
42
|
|
|
28
43
|
/**
|
|
29
|
-
* String literals should be made
|
|
44
|
+
* String literals should be made frozen.
|
|
30
45
|
*/
|
|
31
46
|
#define PM_OPTIONS_FROZEN_STRING_LITERAL_ENABLED ((int8_t) 1)
|
|
32
47
|
|
|
33
|
-
/**
|
|
34
|
-
* A scope of locals surrounding the code that is being parsed.
|
|
35
|
-
*/
|
|
36
|
-
typedef struct pm_options_scope {
|
|
37
|
-
/** The number of locals in the scope. */
|
|
38
|
-
size_t locals_count;
|
|
39
|
-
|
|
40
|
-
/** The names of the locals in the scope. */
|
|
41
|
-
pm_string_t *locals;
|
|
42
|
-
|
|
43
|
-
/** Flags for the set of forwarding parameters in this scope. */
|
|
44
|
-
uint8_t forwarding;
|
|
45
|
-
} pm_options_scope_t;
|
|
46
|
-
|
|
47
48
|
/** The default value for parameters. */
|
|
48
49
|
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_NONE = 0x0;
|
|
49
50
|
|
|
50
|
-
/** When the scope is
|
|
51
|
+
/** When the scope is forwarding with the * parameter. */
|
|
51
52
|
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_POSITIONALS = 0x1;
|
|
52
53
|
|
|
53
|
-
/** When the scope is
|
|
54
|
+
/** When the scope is forwarding with the ** parameter. */
|
|
54
55
|
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_KEYWORDS = 0x2;
|
|
55
56
|
|
|
56
|
-
/** When the scope is
|
|
57
|
+
/** When the scope is forwarding with the & parameter. */
|
|
57
58
|
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_BLOCK = 0x4;
|
|
58
59
|
|
|
59
|
-
/** When the scope is
|
|
60
|
+
/** When the scope is forwarding with the ... parameter. */
|
|
60
61
|
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_ALL = 0x8;
|
|
61
62
|
|
|
62
|
-
// Forward declaration needed by the callback typedef.
|
|
63
|
-
struct pm_options;
|
|
64
|
-
|
|
65
63
|
/**
|
|
66
64
|
* The callback called when additional switches are found in a shebang comment
|
|
67
65
|
* that need to be processed by the runtime.
|
|
@@ -74,130 +72,7 @@ struct pm_options;
|
|
|
74
72
|
* @param shebang_callback_data Any additional data that should be passed along
|
|
75
73
|
* to the callback.
|
|
76
74
|
*/
|
|
77
|
-
typedef void (*pm_options_shebang_callback_t)(
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* The version of Ruby syntax that we should be parsing with. This is used to
|
|
81
|
-
* allow consumers to specify which behavior they want in case they need to
|
|
82
|
-
* parse in the same way as a specific version of CRuby would have.
|
|
83
|
-
*/
|
|
84
|
-
typedef enum {
|
|
85
|
-
/** If an explicit version is not provided, the current version of prism will be used. */
|
|
86
|
-
PM_OPTIONS_VERSION_UNSET = 0,
|
|
87
|
-
|
|
88
|
-
/** The vendored version of prism in CRuby 3.3.x. */
|
|
89
|
-
PM_OPTIONS_VERSION_CRUBY_3_3 = 1,
|
|
90
|
-
|
|
91
|
-
/** The vendored version of prism in CRuby 3.4.x. */
|
|
92
|
-
PM_OPTIONS_VERSION_CRUBY_3_4 = 2,
|
|
93
|
-
|
|
94
|
-
/** The vendored version of prism in CRuby 4.0.x. */
|
|
95
|
-
PM_OPTIONS_VERSION_CRUBY_3_5 = 3,
|
|
96
|
-
|
|
97
|
-
/** The vendored version of prism in CRuby 4.0.x. */
|
|
98
|
-
PM_OPTIONS_VERSION_CRUBY_4_0 = 3,
|
|
99
|
-
|
|
100
|
-
/** The vendored version of prism in CRuby 4.1.x. */
|
|
101
|
-
PM_OPTIONS_VERSION_CRUBY_4_1 = 4,
|
|
102
|
-
|
|
103
|
-
/** The current version of prism. */
|
|
104
|
-
PM_OPTIONS_VERSION_LATEST = PM_OPTIONS_VERSION_CRUBY_4_1
|
|
105
|
-
} pm_options_version_t;
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* The options that can be passed to the parser.
|
|
109
|
-
*/
|
|
110
|
-
typedef struct pm_options {
|
|
111
|
-
/**
|
|
112
|
-
* The callback to call when additional switches are found in a shebang
|
|
113
|
-
* comment.
|
|
114
|
-
*/
|
|
115
|
-
pm_options_shebang_callback_t shebang_callback;
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Any additional data that should be passed along to the shebang callback
|
|
119
|
-
* if one was set.
|
|
120
|
-
*/
|
|
121
|
-
void *shebang_callback_data;
|
|
122
|
-
|
|
123
|
-
/** The name of the file that is currently being parsed. */
|
|
124
|
-
pm_string_t filepath;
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* The line within the file that the parse starts on. This value is
|
|
128
|
-
* 1-indexed.
|
|
129
|
-
*/
|
|
130
|
-
int32_t line;
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* The name of the encoding that the source file is in. Note that this must
|
|
134
|
-
* correspond to a name that can be found with Encoding.find in Ruby.
|
|
135
|
-
*/
|
|
136
|
-
pm_string_t encoding;
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* The number of scopes surrounding the code that is being parsed.
|
|
140
|
-
*/
|
|
141
|
-
size_t scopes_count;
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* The scopes surrounding the code that is being parsed. For most parses
|
|
145
|
-
* this will be NULL, but for evals it will be the locals that are in scope
|
|
146
|
-
* surrounding the eval. Scopes are ordered from the outermost scope to the
|
|
147
|
-
* innermost one.
|
|
148
|
-
*/
|
|
149
|
-
pm_options_scope_t *scopes;
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* The version of prism that we should be parsing with. This is used to
|
|
153
|
-
* allow consumers to specify which behavior they want in case they need to
|
|
154
|
-
* parse exactly as a specific version of CRuby.
|
|
155
|
-
*/
|
|
156
|
-
pm_options_version_t version;
|
|
157
|
-
|
|
158
|
-
/** A bitset of the various options that were set on the command line. */
|
|
159
|
-
uint8_t command_line;
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Whether or not the frozen string literal option has been set.
|
|
163
|
-
* May be:
|
|
164
|
-
* - PM_OPTIONS_FROZEN_STRING_LITERAL_DISABLED
|
|
165
|
-
* - PM_OPTIONS_FROZEN_STRING_LITERAL_ENABLED
|
|
166
|
-
* - PM_OPTIONS_FROZEN_STRING_LITERAL_UNSET
|
|
167
|
-
*/
|
|
168
|
-
int8_t frozen_string_literal;
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Whether or not the encoding magic comments should be respected. This is a
|
|
172
|
-
* niche use-case where you want to parse a file with a specific encoding
|
|
173
|
-
* but ignore any encoding magic comments at the top of the file.
|
|
174
|
-
*/
|
|
175
|
-
bool encoding_locked;
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* When the file being parsed is the main script, the shebang will be
|
|
179
|
-
* considered for command-line flags (or for implicit -x). The caller needs
|
|
180
|
-
* to pass this information to the parser so that it can behave correctly.
|
|
181
|
-
*/
|
|
182
|
-
bool main_script;
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* When the file being parsed is considered a "partial" script, jumps will
|
|
186
|
-
* not be marked as errors if they are not contained within loops/blocks.
|
|
187
|
-
* This is used in the case that you're parsing a script that you know will
|
|
188
|
-
* be embedded inside another script later, but you do not have that context
|
|
189
|
-
* yet. For example, when parsing an ERB template that will be evaluated
|
|
190
|
-
* inside another script.
|
|
191
|
-
*/
|
|
192
|
-
bool partial_script;
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Whether or not the parser should freeze the nodes that it creates. This
|
|
196
|
-
* makes it possible to have a deeply frozen AST that is safe to share
|
|
197
|
-
* between concurrency primitives.
|
|
198
|
-
*/
|
|
199
|
-
bool freeze;
|
|
200
|
-
} pm_options_t;
|
|
75
|
+
typedef void (*pm_options_shebang_callback_t)(pm_options_t *options, const uint8_t *source, size_t length, void *shebang_callback_data);
|
|
201
76
|
|
|
202
77
|
/**
|
|
203
78
|
* A bit representing whether or not the command line -a option was set. -a
|
|
@@ -232,10 +107,26 @@ static const uint8_t PM_OPTIONS_COMMAND_LINE_P = 0x10;
|
|
|
232
107
|
|
|
233
108
|
/**
|
|
234
109
|
* A bit representing whether or not the command line -x option was set. -x
|
|
235
|
-
* searches the input file for a shebang that
|
|
110
|
+
* searches the input file for a shebang that includes "ruby".
|
|
236
111
|
*/
|
|
237
112
|
static const uint8_t PM_OPTIONS_COMMAND_LINE_X = 0x20;
|
|
238
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Allocate a new options struct. If the options struct cannot be allocated,
|
|
116
|
+
* this function aborts the process.
|
|
117
|
+
*
|
|
118
|
+
* @returns A new options struct with default values. It is the responsibility
|
|
119
|
+
* of the caller to free this struct using pm_options_free().
|
|
120
|
+
*/
|
|
121
|
+
PRISM_NODISCARD PRISM_EXPORTED_FUNCTION pm_options_t * pm_options_new(void);
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Free both the held memory of the given options struct and the struct itself.
|
|
125
|
+
*
|
|
126
|
+
* @param options The options struct to free.
|
|
127
|
+
*/
|
|
128
|
+
PRISM_EXPORTED_FUNCTION void pm_options_free(pm_options_t *options) PRISM_NONNULL(1);
|
|
129
|
+
|
|
239
130
|
/**
|
|
240
131
|
* Set the shebang callback option on the given options struct.
|
|
241
132
|
*
|
|
@@ -243,70 +134,64 @@ static const uint8_t PM_OPTIONS_COMMAND_LINE_X = 0x20;
|
|
|
243
134
|
* @param shebang_callback The shebang callback to set.
|
|
244
135
|
* @param shebang_callback_data Any additional data that should be passed along
|
|
245
136
|
* to the callback.
|
|
137
|
+
*/
|
|
138
|
+
PRISM_EXPORTED_FUNCTION void pm_options_shebang_callback_set(pm_options_t *options, pm_options_shebang_callback_t shebang_callback, void *shebang_callback_data) PRISM_NONNULL(1);
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Get the filepath option on the given options struct.
|
|
246
142
|
*
|
|
247
|
-
*
|
|
143
|
+
* @param options The options struct to get the filepath from.
|
|
144
|
+
* @returns The filepath.
|
|
248
145
|
*/
|
|
249
|
-
PRISM_EXPORTED_FUNCTION
|
|
146
|
+
PRISM_EXPORTED_FUNCTION const pm_string_t * pm_options_filepath(const pm_options_t *options) PRISM_NONNULL(1);
|
|
250
147
|
|
|
251
148
|
/**
|
|
252
149
|
* Set the filepath option on the given options struct.
|
|
253
150
|
*
|
|
254
151
|
* @param options The options struct to set the filepath on.
|
|
255
152
|
* @param filepath The filepath to set.
|
|
256
|
-
*
|
|
257
|
-
* \public \memberof pm_options
|
|
258
153
|
*/
|
|
259
|
-
PRISM_EXPORTED_FUNCTION void pm_options_filepath_set(pm_options_t *options, const char *filepath);
|
|
154
|
+
PRISM_EXPORTED_FUNCTION void pm_options_filepath_set(pm_options_t *options, const char *filepath) PRISM_NONNULL(1);
|
|
260
155
|
|
|
261
156
|
/**
|
|
262
157
|
* Set the line option on the given options struct.
|
|
263
158
|
*
|
|
264
159
|
* @param options The options struct to set the line on.
|
|
265
160
|
* @param line The line to set.
|
|
266
|
-
*
|
|
267
|
-
* \public \memberof pm_options
|
|
268
161
|
*/
|
|
269
|
-
PRISM_EXPORTED_FUNCTION void pm_options_line_set(pm_options_t *options, int32_t line);
|
|
162
|
+
PRISM_EXPORTED_FUNCTION void pm_options_line_set(pm_options_t *options, int32_t line) PRISM_NONNULL(1);
|
|
270
163
|
|
|
271
164
|
/**
|
|
272
165
|
* Set the encoding option on the given options struct.
|
|
273
166
|
*
|
|
274
167
|
* @param options The options struct to set the encoding on.
|
|
275
168
|
* @param encoding The encoding to set.
|
|
276
|
-
*
|
|
277
|
-
* \public \memberof pm_options
|
|
278
169
|
*/
|
|
279
|
-
PRISM_EXPORTED_FUNCTION void pm_options_encoding_set(pm_options_t *options, const char *encoding);
|
|
170
|
+
PRISM_EXPORTED_FUNCTION void pm_options_encoding_set(pm_options_t *options, const char *encoding) PRISM_NONNULL(1);
|
|
280
171
|
|
|
281
172
|
/**
|
|
282
173
|
* Set the encoding_locked option on the given options struct.
|
|
283
174
|
*
|
|
284
175
|
* @param options The options struct to set the encoding_locked value on.
|
|
285
176
|
* @param encoding_locked The encoding_locked value to set.
|
|
286
|
-
*
|
|
287
|
-
* \public \memberof pm_options
|
|
288
177
|
*/
|
|
289
|
-
PRISM_EXPORTED_FUNCTION void pm_options_encoding_locked_set(pm_options_t *options, bool encoding_locked);
|
|
178
|
+
PRISM_EXPORTED_FUNCTION void pm_options_encoding_locked_set(pm_options_t *options, bool encoding_locked) PRISM_NONNULL(1);
|
|
290
179
|
|
|
291
180
|
/**
|
|
292
181
|
* Set the frozen string literal option on the given options struct.
|
|
293
182
|
*
|
|
294
183
|
* @param options The options struct to set the frozen string literal value on.
|
|
295
184
|
* @param frozen_string_literal The frozen string literal value to set.
|
|
296
|
-
*
|
|
297
|
-
* \public \memberof pm_options
|
|
298
185
|
*/
|
|
299
|
-
PRISM_EXPORTED_FUNCTION void pm_options_frozen_string_literal_set(pm_options_t *options, bool frozen_string_literal);
|
|
186
|
+
PRISM_EXPORTED_FUNCTION void pm_options_frozen_string_literal_set(pm_options_t *options, bool frozen_string_literal) PRISM_NONNULL(1);
|
|
300
187
|
|
|
301
188
|
/**
|
|
302
189
|
* Sets the command line option on the given options struct.
|
|
303
190
|
*
|
|
304
191
|
* @param options The options struct to set the command line option on.
|
|
305
192
|
* @param command_line The command_line value to set.
|
|
306
|
-
*
|
|
307
|
-
* \public \memberof pm_options
|
|
308
193
|
*/
|
|
309
|
-
PRISM_EXPORTED_FUNCTION void pm_options_command_line_set(pm_options_t *options, uint8_t command_line);
|
|
194
|
+
PRISM_EXPORTED_FUNCTION void pm_options_command_line_set(pm_options_t *options, uint8_t command_line) PRISM_NONNULL(1);
|
|
310
195
|
|
|
311
196
|
/**
|
|
312
197
|
* Set the version option on the given options struct by parsing the given
|
|
@@ -316,173 +201,163 @@ PRISM_EXPORTED_FUNCTION void pm_options_command_line_set(pm_options_t *options,
|
|
|
316
201
|
* @param options The options struct to set the version on.
|
|
317
202
|
* @param version The version to set.
|
|
318
203
|
* @param length The length of the version string.
|
|
319
|
-
* @
|
|
204
|
+
* @returns Whether or not the version was parsed successfully.
|
|
205
|
+
*/
|
|
206
|
+
PRISM_EXPORTED_FUNCTION bool pm_options_version_set(pm_options_t *options, const char *version, size_t length) PRISM_NONNULL(1);
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Set the version option on the given options struct to the lowest version of
|
|
210
|
+
* Ruby that prism supports.
|
|
211
|
+
*
|
|
212
|
+
* @param options The options struct to set the version on.
|
|
213
|
+
*/
|
|
214
|
+
PRISM_EXPORTED_FUNCTION void pm_options_version_set_lowest(pm_options_t *options) PRISM_NONNULL(1);
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Set the version option on the given options struct to the highest version of
|
|
218
|
+
* Ruby that prism supports.
|
|
320
219
|
*
|
|
321
|
-
*
|
|
220
|
+
* @param options The options struct to set the version on.
|
|
322
221
|
*/
|
|
323
|
-
PRISM_EXPORTED_FUNCTION
|
|
222
|
+
PRISM_EXPORTED_FUNCTION void pm_options_version_set_highest(pm_options_t *options) PRISM_NONNULL(1);
|
|
324
223
|
|
|
325
224
|
/**
|
|
326
225
|
* Set the main script option on the given options struct.
|
|
327
226
|
*
|
|
328
227
|
* @param options The options struct to set the main script value on.
|
|
329
228
|
* @param main_script The main script value to set.
|
|
330
|
-
*
|
|
331
|
-
* \public \memberof pm_options
|
|
332
229
|
*/
|
|
333
|
-
PRISM_EXPORTED_FUNCTION void pm_options_main_script_set(pm_options_t *options, bool main_script);
|
|
230
|
+
PRISM_EXPORTED_FUNCTION void pm_options_main_script_set(pm_options_t *options, bool main_script) PRISM_NONNULL(1);
|
|
334
231
|
|
|
335
232
|
/**
|
|
336
233
|
* Set the partial script option on the given options struct.
|
|
337
234
|
*
|
|
338
235
|
* @param options The options struct to set the partial script value on.
|
|
339
236
|
* @param partial_script The partial script value to set.
|
|
237
|
+
*/
|
|
238
|
+
PRISM_EXPORTED_FUNCTION void pm_options_partial_script_set(pm_options_t *options, bool partial_script) PRISM_NONNULL(1);
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Get the freeze option on the given options struct.
|
|
340
242
|
*
|
|
341
|
-
*
|
|
243
|
+
* @param options The options struct to get the freeze value from.
|
|
244
|
+
* @returns The freeze value.
|
|
342
245
|
*/
|
|
343
|
-
PRISM_EXPORTED_FUNCTION
|
|
246
|
+
PRISM_EXPORTED_FUNCTION bool pm_options_freeze(const pm_options_t *options) PRISM_NONNULL(1);
|
|
344
247
|
|
|
345
248
|
/**
|
|
346
249
|
* Set the freeze option on the given options struct.
|
|
347
250
|
*
|
|
348
251
|
* @param options The options struct to set the freeze value on.
|
|
349
252
|
* @param freeze The freeze value to set.
|
|
253
|
+
*/
|
|
254
|
+
PRISM_EXPORTED_FUNCTION void pm_options_freeze_set(pm_options_t *options, bool freeze) PRISM_NONNULL(1);
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Get the attach_comments option on the given options struct.
|
|
258
|
+
*
|
|
259
|
+
* @param options The options struct to get the attach_comments value from.
|
|
260
|
+
* @returns The attach_comments value.
|
|
261
|
+
*/
|
|
262
|
+
PRISM_EXPORTED_FUNCTION bool pm_options_attach_comments(const pm_options_t *options) PRISM_NONNULL(1);
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Set the attach_comments option on the given options struct. When this is
|
|
266
|
+
* set, the parser's comment list is sorted by start offset after parsing and
|
|
267
|
+
* every comment is assigned an owning node. Without it, comments are left in
|
|
268
|
+
* the order they were lexed and no nodes own any comments.
|
|
269
|
+
*
|
|
270
|
+
* @param options The options struct to set the attach_comments value on.
|
|
271
|
+
* @param attach_comments The attach_comments value to set.
|
|
272
|
+
*/
|
|
273
|
+
PRISM_EXPORTED_FUNCTION void pm_options_attach_comments_set(pm_options_t *options, bool attach_comments) PRISM_NONNULL(1);
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Get the raise_error option on the given options struct.
|
|
277
|
+
*
|
|
278
|
+
* @param options The options struct to get the raise_error value from.
|
|
279
|
+
* @returns The raise_error value.
|
|
280
|
+
*/
|
|
281
|
+
PRISM_EXPORTED_FUNCTION uint8_t pm_options_raise_error(const pm_options_t *options) PRISM_NONNULL(1);
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Set the raise_error option on the given options struct.
|
|
350
285
|
*
|
|
351
|
-
*
|
|
286
|
+
* @param options The options struct to set the raise_error value on.
|
|
287
|
+
* @param raise_error The raise_error value to set.
|
|
352
288
|
*/
|
|
353
|
-
PRISM_EXPORTED_FUNCTION void
|
|
289
|
+
PRISM_EXPORTED_FUNCTION void pm_options_raise_error_set(pm_options_t *options, uint8_t raise_error) PRISM_NONNULL(1);
|
|
354
290
|
|
|
355
291
|
/**
|
|
356
292
|
* Allocate and zero out the scopes array on the given options struct.
|
|
357
293
|
*
|
|
358
294
|
* @param options The options struct to initialize the scopes array on.
|
|
359
295
|
* @param scopes_count The number of scopes to allocate.
|
|
360
|
-
* @
|
|
361
|
-
*
|
|
362
|
-
* \public \memberof pm_options
|
|
296
|
+
* @returns Whether or not the scopes array was initialized successfully.
|
|
363
297
|
*/
|
|
364
|
-
PRISM_EXPORTED_FUNCTION bool pm_options_scopes_init(pm_options_t *options, size_t scopes_count);
|
|
298
|
+
PRISM_EXPORTED_FUNCTION bool pm_options_scopes_init(pm_options_t *options, size_t scopes_count) PRISM_NONNULL(1);
|
|
365
299
|
|
|
366
300
|
/**
|
|
367
|
-
* Return a pointer to the scope at the given index within the given
|
|
301
|
+
* Return a constant pointer to the scope at the given index within the given
|
|
302
|
+
* options.
|
|
368
303
|
*
|
|
369
304
|
* @param options The options struct to get the scope from.
|
|
370
305
|
* @param index The index of the scope to get.
|
|
371
|
-
* @
|
|
306
|
+
* @returns A constant pointer to the scope at the given index.
|
|
307
|
+
*/
|
|
308
|
+
PRISM_EXPORTED_FUNCTION const pm_options_scope_t * pm_options_scope(const pm_options_t *options, size_t index) PRISM_NONNULL(1);
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Return a mutable pointer to the scope at the given index within the given
|
|
312
|
+
* options.
|
|
372
313
|
*
|
|
373
|
-
*
|
|
314
|
+
* @param options The options struct to get the scope from.
|
|
315
|
+
* @param index The index of the scope to get.
|
|
316
|
+
* @returns A mutable pointer to the scope at the given index.
|
|
374
317
|
*/
|
|
375
|
-
PRISM_EXPORTED_FUNCTION
|
|
318
|
+
PRISM_EXPORTED_FUNCTION pm_options_scope_t * pm_options_scope_mut(pm_options_t *options, size_t index) PRISM_NONNULL(1);
|
|
376
319
|
|
|
377
320
|
/**
|
|
378
321
|
* Create a new options scope struct. This will hold a set of locals that are in
|
|
379
|
-
* scope surrounding the code that is being parsed.
|
|
322
|
+
* scope surrounding the code that is being parsed. If the scope was unable to
|
|
323
|
+
* allocate its locals, this function will abort the process.
|
|
380
324
|
*
|
|
381
325
|
* @param scope The scope struct to initialize.
|
|
382
326
|
* @param locals_count The number of locals to allocate.
|
|
383
|
-
* @return Whether or not the scope was initialized successfully.
|
|
384
|
-
*
|
|
385
|
-
* \public \memberof pm_options
|
|
386
327
|
*/
|
|
387
|
-
PRISM_EXPORTED_FUNCTION
|
|
328
|
+
PRISM_EXPORTED_FUNCTION void pm_options_scope_init(pm_options_scope_t *scope, size_t locals_count) PRISM_NONNULL(1);
|
|
388
329
|
|
|
389
330
|
/**
|
|
390
|
-
* Return a pointer to the local at the given index within the given
|
|
331
|
+
* Return a constant pointer to the local at the given index within the given
|
|
332
|
+
* scope.
|
|
391
333
|
*
|
|
392
334
|
* @param scope The scope struct to get the local from.
|
|
393
335
|
* @param index The index of the local to get.
|
|
394
|
-
* @
|
|
395
|
-
*
|
|
396
|
-
* \public \memberof pm_options
|
|
336
|
+
* @returns A constant pointer to the local at the given index.
|
|
397
337
|
*/
|
|
398
|
-
PRISM_EXPORTED_FUNCTION const pm_string_t *
|
|
338
|
+
PRISM_EXPORTED_FUNCTION const pm_string_t * pm_options_scope_local(const pm_options_scope_t *scope, size_t index) PRISM_NONNULL(1);
|
|
399
339
|
|
|
400
340
|
/**
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
* @param forwarding The forwarding value to set.
|
|
341
|
+
* Return a mutable pointer to the local at the given index within the given
|
|
342
|
+
* scope, for setting the local's name with pm_string_init. The parser copies
|
|
343
|
+
* the name when it is created, so its bytes must remain valid until then.
|
|
405
344
|
*
|
|
406
|
-
*
|
|
345
|
+
* @param scope The scope struct to get the local from.
|
|
346
|
+
* @param index The index of the local to get.
|
|
347
|
+
* @returns A mutable pointer to the local at the given index.
|
|
407
348
|
*/
|
|
408
|
-
PRISM_EXPORTED_FUNCTION
|
|
349
|
+
PRISM_EXPORTED_FUNCTION pm_string_t * pm_options_scope_local_mut(pm_options_scope_t *scope, size_t index) PRISM_NONNULL(1);
|
|
409
350
|
|
|
410
351
|
/**
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
* @param options The options struct whose internal memory should be freed.
|
|
352
|
+
* Set the forwarding option on the given scope struct.
|
|
414
353
|
*
|
|
415
|
-
*
|
|
354
|
+
* @param scope The scope struct to set the forwarding on.
|
|
355
|
+
* @param forwarding The forwarding value to set.
|
|
416
356
|
*/
|
|
417
|
-
PRISM_EXPORTED_FUNCTION void
|
|
357
|
+
PRISM_EXPORTED_FUNCTION void pm_options_scope_forwarding_set(pm_options_scope_t *scope, uint8_t forwarding) PRISM_NONNULL(1);
|
|
418
358
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
* from an FFI perspective don't have to worry about the structure of our
|
|
423
|
-
* options structs. Since the source of these calls will be from Ruby
|
|
424
|
-
* implementation internals we assume it is from a trusted source.
|
|
425
|
-
*
|
|
426
|
-
* `data` is assumed to be a valid pointer pointing to well-formed data. The
|
|
427
|
-
* layout of this data should be the same every time, and is described below:
|
|
428
|
-
*
|
|
429
|
-
* | # bytes | field |
|
|
430
|
-
* | ------- | -------------------------- |
|
|
431
|
-
* | `4` | the length of the filepath |
|
|
432
|
-
* | ... | the filepath bytes |
|
|
433
|
-
* | `4` | the line number |
|
|
434
|
-
* | `4` | the length the encoding |
|
|
435
|
-
* | ... | the encoding bytes |
|
|
436
|
-
* | `1` | frozen string literal |
|
|
437
|
-
* | `1` | -p command line option |
|
|
438
|
-
* | `1` | -n command line option |
|
|
439
|
-
* | `1` | -l command line option |
|
|
440
|
-
* | `1` | -a command line option |
|
|
441
|
-
* | `1` | the version |
|
|
442
|
-
* | `1` | encoding locked |
|
|
443
|
-
* | `1` | main script |
|
|
444
|
-
* | `1` | partial script |
|
|
445
|
-
* | `1` | freeze |
|
|
446
|
-
* | `4` | the number of scopes |
|
|
447
|
-
* | ... | the scopes |
|
|
448
|
-
*
|
|
449
|
-
* The version field is an enum, so it should be one of the following values:
|
|
450
|
-
*
|
|
451
|
-
* | value | version |
|
|
452
|
-
* | ----- | ------------------------- |
|
|
453
|
-
* | `0` | use the latest version of prism |
|
|
454
|
-
* | `1` | use the version of prism that is vendored in CRuby 3.3.0 |
|
|
455
|
-
*
|
|
456
|
-
* Each scope is laid out as follows:
|
|
457
|
-
*
|
|
458
|
-
* | # bytes | field |
|
|
459
|
-
* | ------- | -------------------------- |
|
|
460
|
-
* | `4` | the number of locals |
|
|
461
|
-
* | `1` | the forwarding flags |
|
|
462
|
-
* | ... | the locals |
|
|
463
|
-
*
|
|
464
|
-
* Each local is laid out as follows:
|
|
465
|
-
*
|
|
466
|
-
* | # bytes | field |
|
|
467
|
-
* | ------- | -------------------------- |
|
|
468
|
-
* | `4` | the length of the local |
|
|
469
|
-
* | ... | the local bytes |
|
|
470
|
-
*
|
|
471
|
-
* Some additional things to note about this layout:
|
|
472
|
-
*
|
|
473
|
-
* * The filepath can have a length of 0, in which case we'll consider it an
|
|
474
|
-
* empty string.
|
|
475
|
-
* * The line number should be 0-indexed.
|
|
476
|
-
* * The encoding can have a length of 0, in which case we'll use the default
|
|
477
|
-
* encoding (UTF-8). If it's not 0, it should correspond to a name of an
|
|
478
|
-
* encoding that can be passed to `Encoding.find` in Ruby.
|
|
479
|
-
* * The frozen string literal, encoding locked, main script, and partial script
|
|
480
|
-
* fields are booleans, so their values should be either 0 or 1.
|
|
481
|
-
* * The number of scopes can be 0.
|
|
482
|
-
*
|
|
483
|
-
* @param options The options struct to deserialize into.
|
|
484
|
-
* @param data The binary string to deserialize from.
|
|
485
|
-
*/
|
|
486
|
-
void pm_options_read(pm_options_t *options, const char *data);
|
|
359
|
+
#ifdef __cplusplus
|
|
360
|
+
}
|
|
361
|
+
#endif
|
|
487
362
|
|
|
488
363
|
#endif
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file options.hpp
|
|
3
|
+
*
|
|
4
|
+
* Ownership of parse options from C++.
|
|
5
|
+
*/
|
|
6
|
+
#ifndef PRISM_OPTIONS_HPP
|
|
7
|
+
#define PRISM_OPTIONS_HPP
|
|
8
|
+
|
|
9
|
+
#include "prism/compiler/cplusplus.hpp"
|
|
10
|
+
|
|
11
|
+
#include "prism/options.h"
|
|
12
|
+
|
|
13
|
+
#include <memory>
|
|
14
|
+
|
|
15
|
+
namespace prism {
|
|
16
|
+
|
|
17
|
+
/** Frees options with pm_options_free. */
|
|
18
|
+
struct options_deleter {
|
|
19
|
+
/**
|
|
20
|
+
* Free the given options.
|
|
21
|
+
*
|
|
22
|
+
* @param options The options to free.
|
|
23
|
+
*/
|
|
24
|
+
void operator()(pm_options_t *options) const noexcept { pm_options_free(options); }
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** An owned set of options. */
|
|
28
|
+
using unique_options = std::unique_ptr<pm_options_t, options_deleter>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Allocate a new set of options with every option at its default. Allocation
|
|
32
|
+
* failure aborts, so this never throws.
|
|
33
|
+
*
|
|
34
|
+
* @return A unique_options owning the newly allocated options.
|
|
35
|
+
*/
|
|
36
|
+
[[nodiscard]] inline unique_options
|
|
37
|
+
make_options() noexcept {
|
|
38
|
+
return unique_options(pm_options_new());
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
#endif
|