summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <[email protected]>2024-09-13 15:00:03 -0400
committergit <[email protected]>2024-09-13 19:13:21 +0000
commitf85efc9748b193bceaefd2e94293927404ac951f (patch)
treeff4b190b90f1611fc64909193651c9e9ca0c20c1
parent77521afac1687602fde4046ab20f016c61089003 (diff)
[ruby/prism] Expose main_script in serialization API
https://github.com/ruby/prism/commit/0b527ca93f
-rw-r--r--lib/prism/ffi.rb3
-rw-r--r--prism/extension.c5
-rw-r--r--prism/options.c1
3 files changed, 9 insertions, 0 deletions
diff --git a/lib/prism/ffi.rb b/lib/prism/ffi.rb
index b972520be1..40a4b32621 100644
--- a/lib/prism/ffi.rb
+++ b/lib/prism/ffi.rb
@@ -448,6 +448,9 @@ module Prism
template << "C"
values << (options[:encoding] == false ? 1 : 0)
+ template << "C"
+ values << (options.fetch(:main_script, false) ? 1 : 0)
+
template << "L"
if (scopes = options[:scopes])
values << scopes.length
diff --git a/prism/extension.c b/prism/extension.c
index 94fc5a104b..f08682e0f3 100644
--- a/prism/extension.c
+++ b/prism/extension.c
@@ -756,6 +756,11 @@ parse_input(pm_string_t *input, const pm_options_t *options) {
* has been set. This should be a boolean or nil.
* * `line` - the line number that the parse starts on. This should be an
* integer or nil. Note that this is 1-indexed.
+ * * `main_script` - a boolean indicating whether or not the source being parsed
+ * is the main script being run by the interpreter. This controls whether
+ * or not shebangs are parsed for additional flags and whether or not the
+ * parser will attempt to find a matching shebang if the first one does
+ * not contain the word "ruby".
* * `scopes` - the locals that are in scope surrounding the code that is being
* parsed. This should be an array of arrays of symbols or nil. Scopes are
* ordered from the outermost scope to the innermost one.
diff --git a/prism/options.c b/prism/options.c
index e0b4735e4a..67b257138c 100644
--- a/prism/options.c
+++ b/prism/options.c
@@ -241,6 +241,7 @@ pm_options_read(pm_options_t *options, const char *data) {
options->command_line = (uint8_t) *data++;
options->version = (pm_options_version_t) *data++;
options->encoding_locked = ((uint8_t) *data++) > 0;
+ options->main_script = ((uint8_t) *data++) > 0;
uint32_t scopes_count = pm_options_read_u32(data);
data += 4;