prism 0.26.0 → 0.28.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -8,8 +8,7 @@
|
|
8
8
|
|
9
9
|
#include "prism/defines.h"
|
10
10
|
#include "prism/ast.h"
|
11
|
-
#include "prism/
|
12
|
-
#include "prism/parser.h"
|
11
|
+
#include "prism/util/pm_newline_list.h"
|
13
12
|
|
14
13
|
#include <assert.h>
|
15
14
|
#include <stdbool.h>
|
@@ -92,12 +91,13 @@ typedef struct {
|
|
92
91
|
/**
|
93
92
|
* Add a node to the set of static literals.
|
94
93
|
*
|
95
|
-
* @param
|
94
|
+
* @param newline_list The list of newline offsets to use to calculate lines.
|
95
|
+
* @param start_line The line number that the parser starts on.
|
96
96
|
* @param literals The set of static literals to add the node to.
|
97
97
|
* @param node The node to add to the set.
|
98
98
|
* @return A pointer to the node that is being overwritten, if there is one.
|
99
99
|
*/
|
100
|
-
pm_node_t * pm_static_literals_add(const
|
100
|
+
pm_node_t * pm_static_literals_add(const pm_newline_list_t *newline_list, int32_t start_line, pm_static_literals_t *literals, pm_node_t *node);
|
101
101
|
|
102
102
|
/**
|
103
103
|
* Free the internal memory associated with the given static literals set.
|
@@ -110,9 +110,11 @@ void pm_static_literals_free(pm_static_literals_t *literals);
|
|
110
110
|
* Create a string-based representation of the given static literal.
|
111
111
|
*
|
112
112
|
* @param buffer The buffer to write the string to.
|
113
|
-
* @param
|
113
|
+
* @param newline_list The list of newline offsets to use to calculate lines.
|
114
|
+
* @param start_line The line number that the parser starts on.
|
115
|
+
* @param encoding_name The name of the encoding of the source being parsed.
|
114
116
|
* @param node The node to create a string representation of.
|
115
117
|
*/
|
116
|
-
PRISM_EXPORTED_FUNCTION void pm_static_literal_inspect(pm_buffer_t *buffer, const
|
118
|
+
PRISM_EXPORTED_FUNCTION void pm_static_literal_inspect(pm_buffer_t *buffer, const pm_newline_list_t *newline_list, int32_t start_line, const char *encoding_name, const pm_node_t *node);
|
117
119
|
|
118
120
|
#endif
|
data/include/prism/version.h
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
/**
|
15
15
|
* The minor version of the Prism library as an int.
|
16
16
|
*/
|
17
|
-
#define PRISM_VERSION_MINOR
|
17
|
+
#define PRISM_VERSION_MINOR 28
|
18
18
|
|
19
19
|
/**
|
20
20
|
* The patch version of the Prism library as an int.
|
@@ -24,6 +24,6 @@
|
|
24
24
|
/**
|
25
25
|
* The version of the Prism library as a constant string.
|
26
26
|
*/
|
27
|
-
#define PRISM_VERSION "0.
|
27
|
+
#define PRISM_VERSION "0.28.0"
|
28
28
|
|
29
29
|
#endif
|
data/lib/prism/dot_visitor.rb
CHANGED
@@ -1287,13 +1287,15 @@ module Prism
|
|
1287
1287
|
digraph.edge("#{id}:parent -> #{node_id(parent)};")
|
1288
1288
|
end
|
1289
1289
|
|
1290
|
-
#
|
1291
|
-
table.field("
|
1292
|
-
digraph.edge("#{id}:child -> #{node_id(node.child)};")
|
1290
|
+
# name
|
1291
|
+
table.field("name", node.name.inspect)
|
1293
1292
|
|
1294
1293
|
# delimiter_loc
|
1295
1294
|
table.field("delimiter_loc", location_inspect(node.delimiter_loc))
|
1296
1295
|
|
1296
|
+
# name_loc
|
1297
|
+
table.field("name_loc", location_inspect(node.name_loc))
|
1298
|
+
|
1297
1299
|
digraph.nodes << <<~DOT
|
1298
1300
|
#{id} [
|
1299
1301
|
label=<#{table.to_dot.gsub(/\n/, "\n ")}>
|
@@ -1367,13 +1369,15 @@ module Prism
|
|
1367
1369
|
digraph.edge("#{id}:parent -> #{node_id(parent)};")
|
1368
1370
|
end
|
1369
1371
|
|
1370
|
-
#
|
1371
|
-
table.field("
|
1372
|
-
digraph.edge("#{id}:child -> #{node_id(node.child)};")
|
1372
|
+
# name
|
1373
|
+
table.field("name", node.name.inspect)
|
1373
1374
|
|
1374
1375
|
# delimiter_loc
|
1375
1376
|
table.field("delimiter_loc", location_inspect(node.delimiter_loc))
|
1376
1377
|
|
1378
|
+
# name_loc
|
1379
|
+
table.field("name_loc", location_inspect(node.name_loc))
|
1380
|
+
|
1377
1381
|
digraph.nodes << <<~DOT
|
1378
1382
|
#{id} [
|
1379
1383
|
label=<#{table.to_dot.gsub(/\n/, "\n ")}>
|
@@ -3999,6 +4003,9 @@ module Prism
|
|
3999
4003
|
table = Table.new("ReturnNode")
|
4000
4004
|
id = node_id(node)
|
4001
4005
|
|
4006
|
+
# flags
|
4007
|
+
table.field("flags", return_node_flags_inspect(node))
|
4008
|
+
|
4002
4009
|
# keyword_loc
|
4003
4010
|
table.field("keyword_loc", location_inspect(node.keyword_loc))
|
4004
4011
|
|
@@ -4569,6 +4576,7 @@ module Prism
|
|
4569
4576
|
# comma-separated list.
|
4570
4577
|
def arguments_node_flags_inspect(node)
|
4571
4578
|
flags = [] #: Array[String]
|
4579
|
+
flags << "contains_keywords" if node.contains_keywords?
|
4572
4580
|
flags << "contains_keyword_splat" if node.contains_keyword_splat?
|
4573
4581
|
flags.join(", ")
|
4574
4582
|
end
|
@@ -4671,6 +4679,14 @@ module Prism
|
|
4671
4679
|
flags.join(", ")
|
4672
4680
|
end
|
4673
4681
|
|
4682
|
+
# Inspect a node that has return_node_flags flags to display the flags as a
|
4683
|
+
# comma-separated list.
|
4684
|
+
def return_node_flags_inspect(node)
|
4685
|
+
flags = [] #: Array[String]
|
4686
|
+
flags << "redundant" if node.redundant?
|
4687
|
+
flags.join(", ")
|
4688
|
+
end
|
4689
|
+
|
4674
4690
|
# Inspect a node that has shareable_constant_node_flags flags to display the flags as a
|
4675
4691
|
# comma-separated list.
|
4676
4692
|
def shareable_constant_node_flags_inspect(node)
|
data/lib/prism/dsl.rb
CHANGED
@@ -10,7 +10,7 @@ module Prism
|
|
10
10
|
# The DSL module provides a set of methods that can be used to create prism
|
11
11
|
# nodes in a more concise manner. For example, instead of writing:
|
12
12
|
#
|
13
|
-
# source = Prism::Source.
|
13
|
+
# source = Prism::Source.for("[1]")
|
14
14
|
#
|
15
15
|
# Prism::ArrayNode.new(
|
16
16
|
# [
|
@@ -28,7 +28,7 @@ module Prism
|
|
28
28
|
#
|
29
29
|
# you could instead write:
|
30
30
|
#
|
31
|
-
# source = Prism::Source.
|
31
|
+
# source = Prism::Source.for("[1]")
|
32
32
|
#
|
33
33
|
# ArrayNode(
|
34
34
|
# IntegerNode(Prism::IntegerBaseFlags::DECIMAL, 1, Location(source, 1, 1)), source),
|
@@ -228,8 +228,8 @@ module Prism
|
|
228
228
|
end
|
229
229
|
|
230
230
|
# Create a new ConstantPathNode node
|
231
|
-
def ConstantPathNode(parent,
|
232
|
-
ConstantPathNode.new(source, parent,
|
231
|
+
def ConstantPathNode(parent, name, delimiter_loc, name_loc, source = nil, location = Location())
|
232
|
+
ConstantPathNode.new(source, parent, name, delimiter_loc, name_loc, location)
|
233
233
|
end
|
234
234
|
|
235
235
|
# Create a new ConstantPathOperatorWriteNode node
|
@@ -243,8 +243,8 @@ module Prism
|
|
243
243
|
end
|
244
244
|
|
245
245
|
# Create a new ConstantPathTargetNode node
|
246
|
-
def ConstantPathTargetNode(parent,
|
247
|
-
ConstantPathTargetNode.new(source, parent,
|
246
|
+
def ConstantPathTargetNode(parent, name, delimiter_loc, name_loc, source = nil, location = Location())
|
247
|
+
ConstantPathTargetNode.new(source, parent, name, delimiter_loc, name_loc, location)
|
248
248
|
end
|
249
249
|
|
250
250
|
# Create a new ConstantPathWriteNode node
|
@@ -698,8 +698,8 @@ module Prism
|
|
698
698
|
end
|
699
699
|
|
700
700
|
# Create a new ReturnNode node
|
701
|
-
def ReturnNode(keyword_loc, arguments, source = nil, location = Location())
|
702
|
-
ReturnNode.new(source, keyword_loc, arguments, location)
|
701
|
+
def ReturnNode(flags, keyword_loc, arguments, source = nil, location = Location())
|
702
|
+
ReturnNode.new(source, flags, keyword_loc, arguments, location)
|
703
703
|
end
|
704
704
|
|
705
705
|
# Create a new SelfNode node
|
data/lib/prism/ffi.rb
CHANGED
@@ -317,7 +317,7 @@ module Prism
|
|
317
317
|
buffer.read
|
318
318
|
end
|
319
319
|
|
320
|
-
Serialize.load_tokens(Source.
|
320
|
+
Serialize.load_tokens(Source.for(code), serialized)
|
321
321
|
end
|
322
322
|
|
323
323
|
def parse_common(string, code, options) # :nodoc:
|
@@ -329,7 +329,7 @@ module Prism
|
|
329
329
|
LibRubyParser::PrismBuffer.with do |buffer|
|
330
330
|
LibRubyParser.pm_serialize_parse_comments(buffer.pointer, string.pointer, string.length, dump_options(options))
|
331
331
|
|
332
|
-
source = Source.
|
332
|
+
source = Source.for(code)
|
333
333
|
loader = Serialize::Loader.new(source, buffer.read)
|
334
334
|
|
335
335
|
loader.load_header
|
@@ -343,14 +343,14 @@ module Prism
|
|
343
343
|
LibRubyParser::PrismBuffer.with do |buffer|
|
344
344
|
LibRubyParser.pm_serialize_parse_lex(buffer.pointer, string.pointer, string.length, dump_options(options))
|
345
345
|
|
346
|
-
source = Source.
|
346
|
+
source = Source.for(code)
|
347
347
|
loader = Serialize::Loader.new(source, buffer.read)
|
348
348
|
|
349
349
|
tokens = loader.load_tokens
|
350
350
|
node, comments, magic_comments, data_loc, errors, warnings = loader.load_nodes
|
351
351
|
tokens.each { |token,| token.value.force_encoding(loader.encoding) }
|
352
352
|
|
353
|
-
|
353
|
+
ParseLexResult.new([node, tokens], comments, magic_comments, data_loc, errors, warnings, source)
|
354
354
|
end
|
355
355
|
end
|
356
356
|
|