Skip to content

Commit 2068e3c

Browse files
committed
CLI -x flag
1 parent 1508735 commit 2068e3c

File tree

16 files changed

+377
-316
lines changed

16 files changed

+377
-316
lines changed

config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ errors:
206206
- RESCUE_TERM
207207
- RESCUE_VARIABLE
208208
- RETURN_INVALID
209+
- SCRIPT_NOT_FOUND
209210
- SINGLETON_FOR_LITERALS
210211
- STATEMENT_ALIAS
211212
- STATEMENT_POSTEXE_END
@@ -255,6 +256,7 @@ warnings:
255256
- KEYWORD_EOL
256257
- LITERAL_IN_CONDITION_DEFAULT
257258
- LITERAL_IN_CONDITION_VERBOSE
259+
- SHEBANG_CARRIAGE_RETURN
258260
- UNEXPECTED_CARRIAGE_RETURN
259261
tokens:
260262
- name: EOF

docs/serialization.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ The comment type is one of:
5858
| `1` | type |
5959
| string | error message (ASCII-only characters) |
6060
| location | the location in the source this error applies to |
61-
| `1` | the level of the error: `0` for `fatal` |
61+
| `1` | the level of the error: `0` for `fatal`, `1` for `argument`, `2` for `load` |
6262

6363
### warning
6464

@@ -194,7 +194,6 @@ The final argument to `pm_serialize_parse` is an optional string that controls t
194194
| `4` | the length of the filepath |
195195
| ... | the filepath bytes |
196196
| `4` | the line number |
197-
| `4` | the offset in the source |
198197
| `4` | the length the encoding |
199198
| ... | the encoding bytes |
200199
| `1` | frozen string literal |

ext/prism/extension.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ ID rb_option_id_encoding;
2828
ID rb_option_id_filepath;
2929
ID rb_option_id_frozen_string_literal;
3030
ID rb_option_id_line;
31-
ID rb_option_id_offset;
3231
ID rb_option_id_scopes;
3332
ID rb_option_id_version;
3433

@@ -139,8 +138,6 @@ build_options_i(VALUE key, VALUE value, VALUE argument) {
139138
if (!NIL_P(value)) pm_options_encoding_set(options, rb_enc_name(rb_to_encoding(value)));
140139
} else if (key_id == rb_option_id_line) {
141140
if (!NIL_P(value)) pm_options_line_set(options, NUM2INT(value));
142-
} else if (key_id == rb_option_id_offset) {
143-
if (!NIL_P(value)) pm_options_offset_set(options, NUM2UINT(value));
144141
} else if (key_id == rb_option_id_frozen_string_literal) {
145142
if (!NIL_P(value)) pm_options_frozen_string_literal_set(options, RTEST(value));
146143
} else if (key_id == rb_option_id_version) {
@@ -448,8 +445,8 @@ parser_errors(pm_parser_t *parser, rb_encoding *encoding, VALUE source) {
448445

449446
VALUE level = Qnil;
450447
switch (error->level) {
451-
case PM_ERROR_LEVEL_FATAL:
452-
level = ID2SYM(rb_intern("fatal"));
448+
case PM_ERROR_LEVEL_SYNTAX:
449+
level = ID2SYM(rb_intern("syntax"));
453450
break;
454451
case PM_ERROR_LEVEL_ARGUMENT:
455452
level = ID2SYM(rb_intern("argument"));
@@ -1347,7 +1344,6 @@ Init_prism(void) {
13471344
rb_option_id_filepath = rb_intern_const("filepath");
13481345
rb_option_id_frozen_string_literal = rb_intern_const("frozen_string_literal");
13491346
rb_option_id_line = rb_intern_const("line");
1350-
rb_option_id_offset = rb_intern_const("offset");
13511347
rb_option_id_scopes = rb_intern_const("scopes");
13521348
rb_option_id_version = rb_intern_const("version");
13531349

include/prism/options.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,6 @@ typedef struct {
6666
*/
6767
int32_t line;
6868

69-
/**
70-
* The offset within the file that the parse starts on. This value is
71-
* 0-indexed.
72-
*/
73-
uint32_t offset;
74-
7569
/**
7670
* The name of the encoding that the source file is in. Note that this must
7771
* correspond to a name that can be found with Encoding.find in Ruby.
@@ -164,14 +158,6 @@ PRISM_EXPORTED_FUNCTION void pm_options_filepath_set(pm_options_t *options, cons
164158
*/
165159
PRISM_EXPORTED_FUNCTION void pm_options_line_set(pm_options_t *options, int32_t line);
166160

167-
/**
168-
* Set the offset option on the given options struct.
169-
*
170-
* @param options The options struct to set the offset on.
171-
* @param offset The offset to set.
172-
*/
173-
PRISM_EXPORTED_FUNCTION void pm_options_offset_set(pm_options_t *options, uint32_t offset);
174-
175161
/**
176162
* Set the encoding option on the given options struct.
177163
*
@@ -267,7 +253,6 @@ PRISM_EXPORTED_FUNCTION void pm_options_free(pm_options_t *options);
267253
* | `4` | the length of the filepath |
268254
* | ... | the filepath bytes |
269255
* | `4` | the line number |
270-
* | `4` | the offset |
271256
* | `4` | the length the encoding |
272257
* | ... | the encoding bytes |
273258
* | `1` | frozen string literal |

include/prism/util/pm_newline_list.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ typedef struct {
6161
*/
6262
bool pm_newline_list_init(pm_newline_list_t *list, const uint8_t *start, size_t capacity);
6363

64+
/**
65+
* Clear out the newlines that have been appended to the list.
66+
*/
67+
void
68+
pm_newline_list_clear(pm_newline_list_t *list);
69+
6470
/**
6571
* Append a new offset to the newline list. Returns true if the reallocation of
6672
* the offsets succeeds (if one was necessary), otherwise returns false.

java-wasm/src/test/java/org/prism/DummyTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public void test1() {
3636
var packedOptions = ParsingOptions.serialize(
3737
new byte[] {},
3838
1,
39-
0,
4039
new byte[] {},
4140
false,
4241
EnumSet.noneOf(ParsingOptions.CommandLine.class),
@@ -88,7 +87,6 @@ public void test2() {
8887
var packedOptions = ParsingOptions.serialize(
8988
new byte[] {},
9089
1,
91-
0,
9290
new byte[] {},
9391
false,
9492
EnumSet.noneOf(ParsingOptions.CommandLine.class),

java/org/prism/ParsingOptions.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,14 @@ public enum CommandLine { A, E, L, N, P, X };
3939
*
4040
* @param filepath the name of the file that is currently being parsed
4141
* @param line the line within the file that the parser starts on. This value is 1-indexed
42-
* @param offset the offset within the file that the parser starts on. This value is 0-indexed
4342
* @param encoding the name of the encoding that the source file is in
4443
* @param frozenStringLiteral whether the frozen string literal option has been set
4544
* @param commandLine the set of flags that were set on the command line
4645
* @param version code of Ruby version which syntax will be used to parse
4746
* @param scopes scopes surrounding the code that is being parsed with local variable names defined in every scope
4847
* ordered from the outermost scope to the innermost one
4948
*/
50-
public static byte[] serialize(byte[] filepath, int line, int offset, byte[] encoding, boolean frozenStringLiteral, EnumSet<CommandLine> commandLine, SyntaxVersion version, byte[][][] scopes) {
49+
public static byte[] serialize(byte[] filepath, int line, byte[] encoding, boolean frozenStringLiteral, EnumSet<CommandLine> commandLine, SyntaxVersion version, byte[][][] scopes) {
5150
final ByteArrayOutputStream output = new ByteArrayOutputStream();
5251

5352
// filepath
@@ -57,9 +56,6 @@ public static byte[] serialize(byte[] filepath, int line, int offset, byte[] enc
5756
// line
5857
write(output, serializeInt(line));
5958

60-
// offset
61-
write(output, serializeInt(offset));
62-
6359
// encoding
6460
write(output, serializeInt(encoding.length));
6561
write(output, encoding);

javascript/src/parsePrism.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ function dumpOptions(options) {
8181
template.push("l");
8282
values.push(options.line || 1);
8383

84-
template.push("L");
85-
values.push(options.offset || 0);
86-
8784
template.push("L");
8885
if (options.encoding) {
8986
const encoding = encoder.encode(options.encoding);

lib/prism/ffi.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,6 @@ def dump_options(options)
382382
template << "l"
383383
values << options.fetch(:line, 1)
384384

385-
template << "L"
386-
values << options.fetch(:offset, 0)
387-
388385
template << "L"
389386
if (encoding = options[:encoding])
390387
name = encoding.name

src/options.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ pm_options_line_set(pm_options_t *options, int32_t line) {
2424
options->line = line;
2525
}
2626

27-
/**
28-
* Set the offset option on the given options struct.
29-
*/
30-
PRISM_EXPORTED_FUNCTION void
31-
pm_options_offset_set(pm_options_t *options, uint32_t offset) {
32-
options->offset = offset;
33-
}
34-
3527
/**
3628
* Set the frozen string literal option on the given options struct.
3729
*/
@@ -201,9 +193,6 @@ pm_options_read(pm_options_t *options, const char *data) {
201193
options->line = pm_options_read_s32(data);
202194
data += 4;
203195

204-
options->offset = pm_options_read_u32(data);
205-
data += 4;
206-
207196
uint32_t encoding_length = pm_options_read_u32(data);
208197
data += 4;
209198

0 commit comments

Comments
 (0)