summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <[email protected]>2024-03-11 10:09:10 -0400
committergit <[email protected]>2024-03-11 14:49:23 +0000
commit2ab75bc44486b3afcd7ccb060120e12c2fa17217 ()
treeb2cbbe00f385cc8e8ec154655b29fbe4c74bee21
parenta295eeba9d013ab3863a3e5e339e170332e9be9f (diff)
[ruby/prism] Support offset
https://.com/ruby/prism/commit/665f533373
-rw-r--r--lib/prism/ffi.rb3
-rw-r--r--prism/extension.c20
-rw-r--r--prism/options.c11
-rw-r--r--prism/options.h15
-rw-r--r--prism/prism.c16
-rw-r--r--test/prism/ruby_api_test.rb15
6 files changed, 72 insertions, 8 deletions
@@ -383,6 +383,9 @@ module Prism
values << options.fetch(:line, 1)
template << "L"
if (encoding = options[:encoding])
name = encoding.name
values.push(name.bytesize, name.b)
@@ -23,13 +23,14 @@ VALUE rb_cPrismParseResult;
VALUE rb_cPrismDebugEncoding;
-ID rb_option_id_filepath;
ID rb_option_id_encoding;
-ID rb_option_id_line;
ID rb_option_id_frozen_string_literal;
-ID rb_option_id_version;
ID rb_option_id_scopes;
-ID rb_option_id_command_line;
/******************************************************************************/
/* IO of Ruby code */
@@ -138,6 +139,8 @@ build_options_i(VALUE key, VALUE value, VALUE argument) {
if (!NIL_P(value)) pm_options_encoding_set(options, rb_enc_name(rb_to_encoding(value)));
} else if (key_id == rb_option_id_line) {
if (!NIL_P(value)) pm_options_line_set(options, NUM2INT(value));
} else if (key_id == rb_option_id_frozen_string_literal) {
if (!NIL_P(value)) pm_options_frozen_string_literal_set(options, value == Qtrue);
} else if (key_id == rb_option_id_version) {
@@ -1297,13 +1300,14 @@ Init_prism(void) {
// Intern all of the options that we support so that we don't have to do it
// every time we parse.
- rb_option_id_filepath = rb_intern_const("filepath");
rb_option_id_encoding = rb_intern_const("encoding");
- rb_option_id_line = rb_intern_const("line");
rb_option_id_frozen_string_literal = rb_intern_const("frozen_string_literal");
- rb_option_id_version = rb_intern_const("version");
rb_option_id_scopes = rb_intern_const("scopes");
- rb_option_id_command_line = rb_intern_const("command_line");
/**
* The version of the prism library.
@@ -25,6 +25,14 @@ pm_options_line_set(pm_options_t *options, int32_t line) {
}
/**
* Set the frozen string literal option on the given options struct.
*/
PRISM_EXPORTED_FUNCTION void
@@ -193,6 +201,9 @@ pm_options_read(pm_options_t *options, const char *data) {
options->line = pm_options_read_s32(data);
data += 4;
uint32_t encoding_length = pm_options_read_u32(data);
data += 4;
@@ -51,6 +51,12 @@ typedef struct {
int32_t line;
/**
* The name of the encoding that the source file is in. Note that this must
* correspond to a name that can be found with Encoding.find in Ruby.
*/
@@ -137,6 +143,14 @@ PRISM_EXPORTED_FUNCTION void pm_options_filepath_set(pm_options_t *options, cons
PRISM_EXPORTED_FUNCTION void pm_options_line_set(pm_options_t *options, int32_t line);
/**
* Set the encoding option on the given options struct.
*
* @param options The options struct to set the encoding on.
@@ -231,6 +245,7 @@ PRISM_EXPORTED_FUNCTION void pm_options_free(pm_options_t *options);
* | `4` | the length of the filepath |
* | ... | the filepath bytes |
* | `4` | the line number |
* | `4` | the length the encoding |
* | ... | the encoding bytes |
* | `1` | frozen string literal |
@@ -18781,6 +18781,22 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm
// line option
parser->start_line = options->line;
// encoding option
size_t encoding_length = pm_string_length(&options->encoding);
if (encoding_length > 0) {
@@ -231,6 +231,21 @@ module Prism
assert_equal 16, base[parse_expression("0x1")]
end
private
def parse_expression(source)