prism 0.30.0 → 1.0.0
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/CHANGELOG.md +31 -1
- data/README.md +3 -1
- data/config.yml +185 -126
- data/docs/serialization.md +3 -0
- data/ext/prism/api_node.c +2843 -2085
- data/ext/prism/extconf.rb +1 -1
- data/ext/prism/extension.c +35 -25
- data/ext/prism/extension.h +2 -2
- data/include/prism/ast.h +1048 -69
- data/include/prism/defines.h +9 -0
- data/include/prism/diagnostic.h +11 -3
- data/include/prism/options.h +55 -1
- data/include/prism/parser.h +27 -3
- data/include/prism/regexp.h +2 -1
- data/include/prism/util/pm_integer.h +6 -6
- data/include/prism/util/pm_newline_list.h +11 -0
- data/include/prism/util/pm_string.h +1 -0
- data/include/prism/version.h +3 -3
- data/lib/prism/desugar_compiler.rb +111 -74
- data/lib/prism/dispatcher.rb +2 -1
- data/lib/prism/dot_visitor.rb +21 -31
- data/lib/prism/dsl.rb +656 -471
- data/lib/prism/ffi.rb +3 -0
- data/lib/prism/inspect_visitor.rb +285 -57
- data/lib/prism/mutation_compiler.rb +5 -5
- data/lib/prism/node.rb +2282 -4754
- data/lib/prism/node_ext.rb +72 -11
- data/lib/prism/parse_result/errors.rb +65 -0
- data/lib/prism/parse_result/newlines.rb +28 -28
- data/lib/prism/parse_result.rb +25 -2
- data/lib/prism/reflection.rb +7 -7
- data/lib/prism/serialize.rb +468 -610
- data/lib/prism/translation/parser/compiler.rb +18 -18
- data/lib/prism/translation/parser/lexer.rb +1 -1
- data/lib/prism/translation/parser.rb +3 -3
- data/lib/prism/translation/ripper.rb +14 -14
- data/lib/prism/translation/ruby_parser.rb +43 -7
- data/prism.gemspec +3 -1
- data/rbi/prism/dsl.rbi +521 -0
- data/rbi/prism/node.rbi +1456 -5616
- data/rbi/prism.rbi +16 -16
- data/sig/prism/dsl.rbs +189 -305
- data/sig/prism/node.rbs +702 -603
- data/sig/prism/parse_result.rbs +2 -0
- data/src/diagnostic.c +22 -6
- data/src/node.c +277 -284
- data/src/options.c +18 -0
- data/src/prettyprint.c +99 -108
- data/src/prism.c +1282 -760
- data/src/regexp.c +72 -4
- data/src/serialize.c +165 -50
- data/src/token_type.c +2 -2
- data/src/util/pm_integer.c +14 -14
- data/src/util/pm_newline_list.c +29 -0
- data/src/util/pm_string.c +9 -5
- metadata +4 -2
data/ext/prism/extconf.rb
CHANGED
data/ext/prism/extension.c
CHANGED
@@ -21,6 +21,7 @@ VALUE rb_cPrismParseError;
|
|
21
21
|
VALUE rb_cPrismParseWarning;
|
22
22
|
VALUE rb_cPrismResult;
|
23
23
|
VALUE rb_cPrismParseResult;
|
24
|
+
VALUE rb_cPrismLexResult;
|
24
25
|
VALUE rb_cPrismParseLexResult;
|
25
26
|
|
26
27
|
VALUE rb_cPrismDebugEncoding;
|
@@ -138,7 +139,13 @@ build_options_i(VALUE key, VALUE value, VALUE argument) {
|
|
138
139
|
if (key_id == rb_id_option_filepath) {
|
139
140
|
if (!NIL_P(value)) pm_options_filepath_set(options, check_string(value));
|
140
141
|
} else if (key_id == rb_id_option_encoding) {
|
141
|
-
if (!NIL_P(value))
|
142
|
+
if (!NIL_P(value)) {
|
143
|
+
if (value == Qfalse) {
|
144
|
+
pm_options_encoding_locked_set(options, true);
|
145
|
+
} else {
|
146
|
+
pm_options_encoding_set(options, rb_enc_name(rb_to_encoding(value)));
|
147
|
+
}
|
148
|
+
}
|
142
149
|
} else if (key_id == rb_id_option_line) {
|
143
150
|
if (!NIL_P(value)) pm_options_line_set(options, NUM2INT(value));
|
144
151
|
} else if (key_id == rb_id_option_frozen_string_literal) {
|
@@ -206,6 +213,7 @@ build_options(VALUE argument) {
|
|
206
213
|
static void
|
207
214
|
extract_options(pm_options_t *options, VALUE filepath, VALUE keywords) {
|
208
215
|
options->line = 1; // default
|
216
|
+
|
209
217
|
if (!NIL_P(keywords)) {
|
210
218
|
struct build_options_data data = { .options = options, .keywords = keywords };
|
211
219
|
struct build_options_data *argument = &data;
|
@@ -364,7 +372,7 @@ dump_file(int argc, VALUE *argv, VALUE self) {
|
|
364
372
|
*/
|
365
373
|
static VALUE
|
366
374
|
parser_comments(pm_parser_t *parser, VALUE source) {
|
367
|
-
VALUE comments =
|
375
|
+
VALUE comments = rb_ary_new_capa(parser->comment_list.size);
|
368
376
|
|
369
377
|
for (pm_comment_t *comment = (pm_comment_t *) parser->comment_list.head; comment != NULL; comment = (pm_comment_t *) comment->node.next) {
|
370
378
|
VALUE location_argv[] = {
|
@@ -386,7 +394,7 @@ parser_comments(pm_parser_t *parser, VALUE source) {
|
|
386
394
|
*/
|
387
395
|
static VALUE
|
388
396
|
parser_magic_comments(pm_parser_t *parser, VALUE source) {
|
389
|
-
VALUE magic_comments =
|
397
|
+
VALUE magic_comments = rb_ary_new_capa(parser->magic_comment_list.size);
|
390
398
|
|
391
399
|
for (pm_magic_comment_t *magic_comment = (pm_magic_comment_t *) parser->magic_comment_list.head; magic_comment != NULL; magic_comment = (pm_magic_comment_t *) magic_comment->node.next) {
|
392
400
|
VALUE key_loc_argv[] = {
|
@@ -436,7 +444,7 @@ parser_data_loc(const pm_parser_t *parser, VALUE source) {
|
|
436
444
|
*/
|
437
445
|
static VALUE
|
438
446
|
parser_errors(pm_parser_t *parser, rb_encoding *encoding, VALUE source) {
|
439
|
-
VALUE errors =
|
447
|
+
VALUE errors = rb_ary_new_capa(parser->error_list.size);
|
440
448
|
pm_diagnostic_t *error;
|
441
449
|
|
442
450
|
for (error = (pm_diagnostic_t *) parser->error_list.head; error != NULL; error = (pm_diagnostic_t *) error->node.next) {
|
@@ -479,7 +487,7 @@ parser_errors(pm_parser_t *parser, rb_encoding *encoding, VALUE source) {
|
|
479
487
|
*/
|
480
488
|
static VALUE
|
481
489
|
parser_warnings(pm_parser_t *parser, rb_encoding *encoding, VALUE source) {
|
482
|
-
VALUE warnings =
|
490
|
+
VALUE warnings = rb_ary_new_capa(parser->warning_list.size);
|
483
491
|
pm_diagnostic_t *warning;
|
484
492
|
|
485
493
|
for (warning = (pm_diagnostic_t *) parser->warning_list.head; warning != NULL; warning = (pm_diagnostic_t *) warning->node.next) {
|
@@ -556,9 +564,10 @@ static void
|
|
556
564
|
parse_lex_token(void *data, pm_parser_t *parser, pm_token_t *token) {
|
557
565
|
parse_lex_data_t *parse_lex_data = (parse_lex_data_t *) parser->lex_callback->data;
|
558
566
|
|
559
|
-
VALUE yields =
|
560
|
-
|
561
|
-
|
567
|
+
VALUE yields = rb_assoc_new(
|
568
|
+
pm_token_new(parser, token, parse_lex_data->encoding, parse_lex_data->source),
|
569
|
+
INT2FIX(parser->lex_state)
|
570
|
+
);
|
562
571
|
|
563
572
|
rb_ary_push(parse_lex_data->tokens, yields);
|
564
573
|
}
|
@@ -599,7 +608,7 @@ parse_lex_input(pm_string_t *input, const pm_options_t *options, bool return_nod
|
|
599
608
|
pm_parser_register_encoding_changed_callback(&parser, parse_lex_encoding_changed_callback);
|
600
609
|
|
601
610
|
VALUE source_string = rb_str_new((const char *) pm_string_source(input), pm_string_length(input));
|
602
|
-
VALUE offsets =
|
611
|
+
VALUE offsets = rb_ary_new_capa(parser.newline_list.size);
|
603
612
|
VALUE source = rb_funcall(rb_cPrismSource, rb_id_source_for, 3, source_string, LONG2NUM(parser.start_line), offsets);
|
604
613
|
|
605
614
|
parse_lex_data_t parse_lex_data = {
|
@@ -628,16 +637,16 @@ parse_lex_input(pm_string_t *input, const pm_options_t *options, bool return_nod
|
|
628
637
|
rb_ary_push(offsets, ULONG2NUM(parser.newline_list.offsets[index]));
|
629
638
|
}
|
630
639
|
|
631
|
-
VALUE
|
640
|
+
VALUE result;
|
632
641
|
if (return_nodes) {
|
633
|
-
value = rb_ary_new_capa(2);
|
642
|
+
VALUE value = rb_ary_new_capa(2);
|
634
643
|
rb_ary_push(value, pm_ast_new(&parser, node, parse_lex_data.encoding, source));
|
635
644
|
rb_ary_push(value, parse_lex_data.tokens);
|
645
|
+
result = parse_result_create(rb_cPrismParseLexResult, &parser, value, parse_lex_data.encoding, source);
|
636
646
|
} else {
|
637
|
-
|
647
|
+
result = parse_result_create(rb_cPrismLexResult, &parser, parse_lex_data.tokens, parse_lex_data.encoding, source);
|
638
648
|
}
|
639
649
|
|
640
|
-
VALUE result = parse_result_create(rb_cPrismParseLexResult, &parser, value, parse_lex_data.encoding, source);
|
641
650
|
pm_node_destroy(&parser, node);
|
642
651
|
pm_parser_free(&parser);
|
643
652
|
|
@@ -646,10 +655,10 @@ parse_lex_input(pm_string_t *input, const pm_options_t *options, bool return_nod
|
|
646
655
|
|
647
656
|
/**
|
648
657
|
* call-seq:
|
649
|
-
* Prism::lex(source, **options) ->
|
658
|
+
* Prism::lex(source, **options) -> LexResult
|
650
659
|
*
|
651
|
-
* Return an array of Token instances
|
652
|
-
* supported options, see Prism::parse.
|
660
|
+
* Return a LexResult instance that contains an array of Token instances
|
661
|
+
* corresponding to the given string. For supported options, see Prism::parse.
|
653
662
|
*/
|
654
663
|
static VALUE
|
655
664
|
lex(int argc, VALUE *argv, VALUE self) {
|
@@ -666,10 +675,10 @@ lex(int argc, VALUE *argv, VALUE self) {
|
|
666
675
|
|
667
676
|
/**
|
668
677
|
* call-seq:
|
669
|
-
* Prism::lex_file(filepath, **options) ->
|
678
|
+
* Prism::lex_file(filepath, **options) -> LexResult
|
670
679
|
*
|
671
|
-
* Return an array of Token instances
|
672
|
-
* supported options, see Prism::parse.
|
680
|
+
* Return a LexResult instance that contains an array of Token instances
|
681
|
+
* corresponding to the given file. For supported options, see Prism::parse.
|
673
682
|
*/
|
674
683
|
static VALUE
|
675
684
|
lex_file(int argc, VALUE *argv, VALUE self) {
|
@@ -849,8 +858,8 @@ parse_stream_fgets(char *string, int size, void *stream) {
|
|
849
858
|
return NULL;
|
850
859
|
}
|
851
860
|
|
852
|
-
const char *cstr =
|
853
|
-
|
861
|
+
const char *cstr = RSTRING_PTR(line);
|
862
|
+
long length = RSTRING_LEN(line);
|
854
863
|
|
855
864
|
memcpy(string, cstr, length);
|
856
865
|
string[length] = '\0';
|
@@ -954,9 +963,9 @@ parse_file_comments(int argc, VALUE *argv, VALUE self) {
|
|
954
963
|
|
955
964
|
/**
|
956
965
|
* call-seq:
|
957
|
-
* Prism::parse_lex(source, **options) ->
|
966
|
+
* Prism::parse_lex(source, **options) -> ParseLexResult
|
958
967
|
*
|
959
|
-
* Parse the given string and return a
|
968
|
+
* Parse the given string and return a ParseLexResult instance that contains a
|
960
969
|
* 2-element array, where the first element is the AST and the second element is
|
961
970
|
* an array of Token instances.
|
962
971
|
*
|
@@ -981,9 +990,9 @@ parse_lex(int argc, VALUE *argv, VALUE self) {
|
|
981
990
|
|
982
991
|
/**
|
983
992
|
* call-seq:
|
984
|
-
* Prism::parse_lex_file(filepath, **options) ->
|
993
|
+
* Prism::parse_lex_file(filepath, **options) -> ParseLexResult
|
985
994
|
*
|
986
|
-
* Parse the given file and return a
|
995
|
+
* Parse the given file and return a ParseLexResult instance that contains a
|
987
996
|
* 2-element array, where the first element is the AST and the second element is
|
988
997
|
* an array of Token instances.
|
989
998
|
*
|
@@ -1124,6 +1133,7 @@ Init_prism(void) {
|
|
1124
1133
|
rb_cPrismParseWarning = rb_define_class_under(rb_cPrism, "ParseWarning", rb_cObject);
|
1125
1134
|
rb_cPrismResult = rb_define_class_under(rb_cPrism, "Result", rb_cObject);
|
1126
1135
|
rb_cPrismParseResult = rb_define_class_under(rb_cPrism, "ParseResult", rb_cPrismResult);
|
1136
|
+
rb_cPrismLexResult = rb_define_class_under(rb_cPrism, "LexResult", rb_cPrismResult);
|
1127
1137
|
rb_cPrismParseLexResult = rb_define_class_under(rb_cPrism, "ParseLexResult", rb_cPrismResult);
|
1128
1138
|
|
1129
1139
|
// Intern all of the IDs eagerly that we support so that we don't have to do
|
data/ext/prism/extension.h
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#ifndef PRISM_EXT_NODE_H
|
2
2
|
#define PRISM_EXT_NODE_H
|
3
3
|
|
4
|
-
#define EXPECTED_PRISM_VERSION "0.
|
4
|
+
#define EXPECTED_PRISM_VERSION "1.0.0"
|
5
5
|
|
6
6
|
#include <ruby.h>
|
7
7
|
#include <ruby/encoding.h>
|
@@ -14,6 +14,6 @@ VALUE pm_integer_new(const pm_integer_t *integer);
|
|
14
14
|
|
15
15
|
void Init_prism_api_node(void);
|
16
16
|
void Init_prism_pack(void);
|
17
|
-
|
17
|
+
RUBY_FUNC_EXPORTED void Init_prism(void);
|
18
18
|
|
19
19
|
#endif
|