prism 0.26.0 → 0.28.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 +45 -1
- data/Makefile +3 -2
- data/config.yml +305 -20
- data/docs/configuration.md +1 -0
- data/ext/prism/api_node.c +884 -879
- data/ext/prism/extconf.rb +23 -4
- data/ext/prism/extension.c +16 -9
- data/ext/prism/extension.h +1 -1
- data/include/prism/ast.h +298 -9
- data/include/prism/diagnostic.h +15 -5
- data/include/prism/options.h +2 -2
- data/include/prism/parser.h +10 -0
- data/include/prism/static_literals.h +8 -6
- data/include/prism/version.h +2 -2
- data/lib/prism/dot_visitor.rb +22 -6
- data/lib/prism/dsl.rb +8 -8
- data/lib/prism/ffi.rb +4 -4
- data/lib/prism/inspect_visitor.rb +2156 -0
- data/lib/prism/lex_compat.rb +18 -1
- data/lib/prism/mutation_compiler.rb +2 -2
- data/lib/prism/node.rb +2345 -1964
- data/lib/prism/node_ext.rb +34 -5
- data/lib/prism/parse_result/newlines.rb +0 -2
- data/lib/prism/parse_result.rb +137 -13
- data/lib/prism/pattern.rb +12 -6
- data/lib/prism/polyfill/byteindex.rb +13 -0
- data/lib/prism/polyfill/unpack1.rb +14 -0
- data/lib/prism/reflection.rb +21 -31
- data/lib/prism/serialize.rb +27 -17
- data/lib/prism/translation/parser/compiler.rb +34 -15
- data/lib/prism/translation/parser.rb +6 -6
- data/lib/prism/translation/ripper.rb +72 -68
- data/lib/prism/translation/ruby_parser.rb +69 -31
- data/lib/prism.rb +3 -2
- data/prism.gemspec +36 -38
- data/rbi/prism/compiler.rbi +3 -5
- data/rbi/prism/inspect_visitor.rbi +12 -0
- data/rbi/prism/node.rbi +359 -321
- data/rbi/prism/parse_result.rbi +85 -34
- data/rbi/prism/reflection.rbi +7 -13
- data/rbi/prism/translation/ripper.rbi +1 -11
- data/rbi/prism.rbi +9 -9
- data/sig/prism/dsl.rbs +3 -3
- data/sig/prism/inspect_visitor.rbs +22 -0
- data/sig/prism/node.rbs +68 -48
- data/sig/prism/parse_result.rbs +42 -10
- data/sig/prism/reflection.rbs +2 -8
- data/sig/prism/serialize.rbs +2 -3
- data/sig/prism.rbs +9 -9
- data/src/diagnostic.c +44 -24
- data/src/node.c +41 -16
- data/src/options.c +2 -2
- data/src/prettyprint.c +61 -18
- data/src/prism.c +623 -188
- data/src/serialize.c +5 -2
- data/src/static_literals.c +120 -34
- data/src/token_type.c +4 -4
- data/src/util/pm_integer.c +9 -2
- metadata +7 -9
- data/lib/prism/node_inspector.rb +0 -68
- data/lib/prism/polyfill/string.rb +0 -12
- data/rbi/prism/desugar_compiler.rbi +0 -5
- data/rbi/prism/mutation_compiler.rbi +0 -5
- data/rbi/prism/translation/parser/compiler.rbi +0 -13
- data/rbi/prism/translation/ripper/ripper_compiler.rbi +0 -5
- data/rbi/prism/translation/ruby_parser.rbi +0 -11
data/ext/prism/extconf.rb
CHANGED
@@ -40,15 +40,34 @@ def generate_templates
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
# We're going to need to run `make` using prism's `Makefile`. We want to match
|
44
|
+
# up as much of the configuration to the configuration that built the current
|
45
|
+
# version of Ruby as possible.
|
43
46
|
require "rbconfig"
|
47
|
+
env = RbConfig::CONFIG.slice("SOEXT", "CPPFLAGS", "CFLAGS", "CC", "AR", "ARFLAGS", "MAKEDIRS", "RMALL")
|
48
|
+
|
49
|
+
# It's possible that the Ruby that is being run wasn't actually compiled on this
|
50
|
+
# machine, in which case the configuration might be incorrect. In this case
|
51
|
+
# we'll need to do some additional checks and potentially fall back to defaults.
|
52
|
+
if env.key?("CC") && !File.exist?(env["CC"])
|
53
|
+
env.delete("CC")
|
54
|
+
env.delete("CFLAGS")
|
55
|
+
env.delete("CPPFLAGS")
|
56
|
+
end
|
57
|
+
|
58
|
+
if env.key?("AR") && !File.exist?(env["AR"])
|
59
|
+
env.delete("AR")
|
60
|
+
env.delete("ARFLAGS")
|
61
|
+
end
|
44
62
|
|
45
63
|
# Runs `make` in the root directory of the project. Note that this is the
|
46
64
|
# `Makefile` for the overall project, not the `Makefile` that is being generated
|
47
65
|
# by this script.`
|
48
|
-
def make(target)
|
66
|
+
def make(env, target)
|
67
|
+
puts "Running make #{target} with #{env.inspect}"
|
49
68
|
Dir.chdir(File.expand_path("../..", __dir__)) do
|
50
69
|
system(
|
51
|
-
|
70
|
+
env,
|
52
71
|
RUBY_PLATFORM.include?("openbsd") ? "gmake" : "make",
|
53
72
|
target,
|
54
73
|
exception: true
|
@@ -62,7 +81,7 @@ end
|
|
62
81
|
# but we want to use the native toolchain here since libprism is run natively.
|
63
82
|
if RUBY_ENGINE != "ruby"
|
64
83
|
generate_templates
|
65
|
-
make("build/libprism.#{RbConfig::CONFIG["SOEXT"]}")
|
84
|
+
make(env, "build/libprism.#{RbConfig::CONFIG["SOEXT"]}")
|
66
85
|
File.write("Makefile", "all install clean:\n\t@#{RbConfig::CONFIG["NULLCMD"]}\n")
|
67
86
|
return
|
68
87
|
end
|
@@ -110,7 +129,7 @@ append_cflags("-fvisibility=hidden")
|
|
110
129
|
archive_target = "build/libprism.a"
|
111
130
|
archive_path = File.expand_path("../../#{archive_target}", __dir__)
|
112
131
|
|
113
|
-
make(archive_target) unless File.exist?(archive_path)
|
132
|
+
make(env, archive_target) unless File.exist?(archive_path)
|
114
133
|
$LOCAL_LIBS << " #{archive_path}"
|
115
134
|
|
116
135
|
# Finally, we'll create the `Makefile` that is going to be used to configure and
|
data/ext/prism/extension.c
CHANGED
@@ -19,7 +19,9 @@ VALUE rb_cPrismEmbDocComment;
|
|
19
19
|
VALUE rb_cPrismMagicComment;
|
20
20
|
VALUE rb_cPrismParseError;
|
21
21
|
VALUE rb_cPrismParseWarning;
|
22
|
+
VALUE rb_cPrismResult;
|
22
23
|
VALUE rb_cPrismParseResult;
|
24
|
+
VALUE rb_cPrismParseLexResult;
|
23
25
|
|
24
26
|
VALUE rb_cPrismDebugEncoding;
|
25
27
|
|
@@ -30,6 +32,7 @@ ID rb_option_id_frozen_string_literal;
|
|
30
32
|
ID rb_option_id_line;
|
31
33
|
ID rb_option_id_scopes;
|
32
34
|
ID rb_option_id_version;
|
35
|
+
ID rb_prism_source_id_for;
|
33
36
|
|
34
37
|
/******************************************************************************/
|
35
38
|
/* IO of Ruby code */
|
@@ -515,7 +518,7 @@ parser_warnings(pm_parser_t *parser, rb_encoding *encoding, VALUE source) {
|
|
515
518
|
* Create a new parse result from the given parser, value, encoding, and source.
|
516
519
|
*/
|
517
520
|
static VALUE
|
518
|
-
parse_result_create(pm_parser_t *parser, VALUE value, rb_encoding *encoding, VALUE source) {
|
521
|
+
parse_result_create(VALUE class, pm_parser_t *parser, VALUE value, rb_encoding *encoding, VALUE source) {
|
519
522
|
VALUE result_argv[] = {
|
520
523
|
value,
|
521
524
|
parser_comments(parser, source),
|
@@ -526,7 +529,7 @@ parse_result_create(pm_parser_t *parser, VALUE value, rb_encoding *encoding, VAL
|
|
526
529
|
source
|
527
530
|
};
|
528
531
|
|
529
|
-
return rb_class_new_instance(7, result_argv,
|
532
|
+
return rb_class_new_instance(7, result_argv, class);
|
530
533
|
}
|
531
534
|
|
532
535
|
/******************************************************************************/
|
@@ -597,8 +600,7 @@ parse_lex_input(pm_string_t *input, const pm_options_t *options, bool return_nod
|
|
597
600
|
|
598
601
|
VALUE source_string = rb_str_new((const char *) pm_string_source(input), pm_string_length(input));
|
599
602
|
VALUE offsets = rb_ary_new();
|
600
|
-
VALUE
|
601
|
-
VALUE source = rb_class_new_instance(3, source_argv, rb_cPrismSource);
|
603
|
+
VALUE source = rb_funcall(rb_cPrismSource, rb_prism_source_id_for, 3, source_string, LONG2NUM(parser.start_line), offsets);
|
602
604
|
|
603
605
|
parse_lex_data_t parse_lex_data = {
|
604
606
|
.source = source,
|
@@ -635,7 +637,7 @@ parse_lex_input(pm_string_t *input, const pm_options_t *options, bool return_nod
|
|
635
637
|
value = parse_lex_data.tokens;
|
636
638
|
}
|
637
639
|
|
638
|
-
VALUE result = parse_result_create(&parser, value, parse_lex_data.encoding, source);
|
640
|
+
VALUE result = parse_result_create(rb_cPrismParseLexResult, &parser, value, parse_lex_data.encoding, source);
|
639
641
|
pm_node_destroy(&parser, node);
|
640
642
|
pm_parser_free(&parser);
|
641
643
|
|
@@ -700,7 +702,7 @@ parse_input(pm_string_t *input, const pm_options_t *options) {
|
|
700
702
|
|
701
703
|
VALUE source = pm_source_new(&parser, encoding);
|
702
704
|
VALUE value = pm_ast_new(&parser, node, encoding, source);
|
703
|
-
VALUE result = parse_result_create(&parser, value, encoding, source) ;
|
705
|
+
VALUE result = parse_result_create(rb_cPrismParseResult, &parser, value, encoding, source) ;
|
704
706
|
|
705
707
|
pm_node_destroy(&parser, node);
|
706
708
|
pm_parser_free(&parser);
|
@@ -804,7 +806,7 @@ parse_stream(int argc, VALUE *argv, VALUE self) {
|
|
804
806
|
|
805
807
|
VALUE source = pm_source_new(&parser, encoding);
|
806
808
|
VALUE value = pm_ast_new(&parser, node, encoding, source);
|
807
|
-
VALUE result = parse_result_create(&parser, value, encoding, source);
|
809
|
+
VALUE result = parse_result_create(rb_cPrismParseResult, &parser, value, encoding, source);
|
808
810
|
|
809
811
|
pm_node_destroy(&parser, node);
|
810
812
|
pm_buffer_free(&buffer);
|
@@ -1241,7 +1243,7 @@ static_inspect(int argc, VALUE *argv, VALUE self) {
|
|
1241
1243
|
pm_node_t *node = ((pm_program_node_t *) program)->statements->body.nodes[0];
|
1242
1244
|
|
1243
1245
|
pm_buffer_t buffer = { 0 };
|
1244
|
-
pm_static_literal_inspect(&buffer, &parser, node);
|
1246
|
+
pm_static_literal_inspect(&buffer, &parser.newline_list, parser.start_line, parser.encoding->name, node);
|
1245
1247
|
|
1246
1248
|
rb_encoding *encoding = rb_enc_find(parser.encoding->name);
|
1247
1249
|
VALUE result = rb_enc_str_new(pm_buffer_value(&buffer), pm_buffer_length(&buffer), encoding);
|
@@ -1362,7 +1364,10 @@ Init_prism(void) {
|
|
1362
1364
|
rb_cPrismMagicComment = rb_define_class_under(rb_cPrism, "MagicComment", rb_cObject);
|
1363
1365
|
rb_cPrismParseError = rb_define_class_under(rb_cPrism, "ParseError", rb_cObject);
|
1364
1366
|
rb_cPrismParseWarning = rb_define_class_under(rb_cPrism, "ParseWarning", rb_cObject);
|
1365
|
-
|
1367
|
+
|
1368
|
+
rb_cPrismResult = rb_define_class_under(rb_cPrism, "Result", rb_cObject);
|
1369
|
+
rb_cPrismParseResult = rb_define_class_under(rb_cPrism, "ParseResult", rb_cPrismResult);
|
1370
|
+
rb_cPrismParseLexResult = rb_define_class_under(rb_cPrism, "ParseLexResult", rb_cPrismResult);
|
1366
1371
|
|
1367
1372
|
// Intern all of the options that we support so that we don't have to do it
|
1368
1373
|
// every time we parse.
|
@@ -1374,6 +1379,8 @@ Init_prism(void) {
|
|
1374
1379
|
rb_option_id_scopes = rb_intern_const("scopes");
|
1375
1380
|
rb_option_id_version = rb_intern_const("version");
|
1376
1381
|
|
1382
|
+
rb_prism_source_id_for = rb_intern("for");
|
1383
|
+
|
1377
1384
|
/**
|
1378
1385
|
* The version of the prism library.
|
1379
1386
|
*/
|