diff options
| author | Kevin Newton <kddnewton@gmail.com> | 2024-02-08 13:56:05 -0500 |
|---|---|---|
| committer | Kevin Newton <kddnewton@gmail.com> | 2024-02-08 14:36:29 -0500 |
| commit | 3ecfc3e33ef7db8e9f855490910077ac7ed13434 (patch) | |
| tree | 247da8ee2c21d7e9cd859fec9f9167a772676fc9 /ruby.c | |
| parent | 1936278461cf9aec1495596bf25a2963721f21ee (diff) | |
[PRISM] Support the DATA constant
Diffstat (limited to 'ruby.c')
| -rw-r--r-- | ruby.c | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -2423,6 +2423,21 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) } else { error = pm_parse_file(&result, opt->script_name); + + // If we found an __END__ marker, then we're going to define a + // global DATA constant that is a file object that can be read + // to read the contents after the marker. + if (error == Qnil && result.parser.data_loc.start != NULL) { + int xflag = opt->xflag; + VALUE file = open_load_file(opt->script_name, &xflag); + + size_t offset = result.parser.data_loc.start - result.parser.start + 7; + if ((result.parser.start + offset < result.parser.end) && result.parser.start[offset] == '\r') offset++; + if ((result.parser.start + offset < result.parser.end) && result.parser.start[offset] == '\n') offset++; + + rb_funcall(file, rb_intern("seek"), 2, LONG2NUM(offset), INT2FIX(SEEK_SET)); + rb_define_global_const("DATA", file); + } } if (error == Qnil) { |
