prism 0.28.0 → 0.30.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 +41 -1
- data/CONTRIBUTING.md +0 -4
- data/README.md +1 -0
- data/config.yml +95 -26
- data/docs/fuzzing.md +1 -1
- data/docs/ripper_translation.md +22 -0
- data/ext/prism/api_node.c +70 -52
- data/ext/prism/extconf.rb +27 -23
- data/ext/prism/extension.c +107 -372
- data/ext/prism/extension.h +1 -1
- data/include/prism/ast.h +170 -102
- data/include/prism/diagnostic.h +18 -3
- data/include/prism/node.h +0 -21
- data/include/prism/parser.h +23 -25
- data/include/prism/regexp.h +17 -8
- data/include/prism/static_literals.h +3 -2
- data/include/prism/util/pm_char.h +1 -2
- data/include/prism/util/pm_constant_pool.h +0 -8
- data/include/prism/util/pm_integer.h +16 -9
- data/include/prism/util/pm_string.h +0 -8
- data/include/prism/version.h +2 -2
- data/include/prism.h +0 -11
- data/lib/prism/compiler.rb +3 -0
- data/lib/prism/desugar_compiler.rb +4 -4
- data/lib/prism/dispatcher.rb +14 -0
- data/lib/prism/dot_visitor.rb +54 -35
- data/lib/prism/dsl.rb +23 -18
- data/lib/prism/ffi.rb +25 -4
- data/lib/prism/inspect_visitor.rb +26 -24
- data/lib/prism/mutation_compiler.rb +6 -1
- data/lib/prism/node.rb +314 -389
- data/lib/prism/node_ext.rb +175 -17
- data/lib/prism/parse_result/comments.rb +1 -8
- data/lib/prism/parse_result/newlines.rb +102 -12
- data/lib/prism/parse_result.rb +17 -0
- data/lib/prism/reflection.rb +11 -9
- data/lib/prism/serialize.rb +91 -68
- data/lib/prism/translation/parser/compiler.rb +288 -138
- data/lib/prism/translation/parser.rb +7 -2
- data/lib/prism/translation/ripper.rb +24 -22
- data/lib/prism/translation/ruby_parser.rb +32 -14
- data/lib/prism/visitor.rb +3 -0
- data/lib/prism.rb +0 -4
- data/prism.gemspec +2 -4
- data/rbi/prism/node.rbi +114 -57
- data/rbi/prism/node_ext.rbi +5 -0
- data/rbi/prism/parse_result.rbi +1 -1
- data/rbi/prism/visitor.rbi +3 -0
- data/rbi/prism.rbi +6 -0
- data/sig/prism/dsl.rbs +13 -10
- data/sig/prism/lex_compat.rbs +10 -0
- data/sig/prism/mutation_compiler.rbs +1 -0
- data/sig/prism/node.rbs +72 -48
- data/sig/prism/node_ext.rbs +4 -0
- data/sig/prism/visitor.rbs +1 -0
- data/sig/prism.rbs +21 -0
- data/src/diagnostic.c +56 -27
- data/src/node.c +432 -1690
- data/src/prettyprint.c +97 -54
- data/src/prism.c +1286 -1196
- data/src/regexp.c +133 -68
- data/src/serialize.c +22 -17
- data/src/static_literals.c +63 -84
- data/src/token_type.c +4 -4
- data/src/util/pm_constant_pool.c +0 -8
- data/src/util/pm_integer.c +39 -11
- data/src/util/pm_string.c +0 -12
- data/src/util/pm_strpbrk.c +32 -6
- metadata +3 -5
- data/include/prism/util/pm_string_list.h +0 -44
- data/lib/prism/debug.rb +0 -249
- data/src/util/pm_string_list.c +0 -28
data/lib/prism/ffi.rb
CHANGED
@@ -200,8 +200,8 @@ module Prism
|
|
200
200
|
|
201
201
|
class << self
|
202
202
|
# Mirror the Prism.dump API by using the serialization API.
|
203
|
-
def dump(
|
204
|
-
LibRubyParser::PrismString.with_string(
|
203
|
+
def dump(source, **options)
|
204
|
+
LibRubyParser::PrismString.with_string(source) { |string| dump_common(string, options) }
|
205
205
|
end
|
206
206
|
|
207
207
|
# Mirror the Prism.dump_file API by using the serialization API.
|
@@ -302,6 +302,27 @@ module Prism
|
|
302
302
|
!parse_file_success?(filepath, **options)
|
303
303
|
end
|
304
304
|
|
305
|
+
# Mirror the Prism.profile API by using the serialization API.
|
306
|
+
def profile(source, **options)
|
307
|
+
LibRubyParser::PrismString.with_string(source) do |string|
|
308
|
+
LibRubyParser::PrismBuffer.with do |buffer|
|
309
|
+
LibRubyParser.pm_serialize_parse(buffer.pointer, string.pointer, string.length, dump_options(options))
|
310
|
+
nil
|
311
|
+
end
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
# Mirror the Prism.profile_file API by using the serialization API.
|
316
|
+
def profile_file(filepath, **options)
|
317
|
+
LibRubyParser::PrismString.with_file(filepath) do |string|
|
318
|
+
LibRubyParser::PrismBuffer.with do |buffer|
|
319
|
+
options[:filepath] = filepath
|
320
|
+
LibRubyParser.pm_serialize_parse(buffer.pointer, string.pointer, string.length, dump_options(options))
|
321
|
+
nil
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
305
326
|
private
|
306
327
|
|
307
328
|
def dump_common(string, options) # :nodoc:
|
@@ -394,7 +415,7 @@ module Prism
|
|
394
415
|
|
395
416
|
template << "L"
|
396
417
|
if (encoding = options[:encoding])
|
397
|
-
name = encoding.name
|
418
|
+
name = encoding.is_a?(Encoding) ? encoding.name : encoding
|
398
419
|
values.push(name.bytesize, name.b)
|
399
420
|
template << "A*"
|
400
421
|
else
|
@@ -408,7 +429,7 @@ module Prism
|
|
408
429
|
values << dump_options_command_line(options)
|
409
430
|
|
410
431
|
template << "C"
|
411
|
-
values << { nil => 0, "3.3.0" => 1, "3.4.0" => 0, "latest" => 0 }.fetch(options[:version])
|
432
|
+
values << { nil => 0, "3.3.0" => 1, "3.3.1" => 1, "3.4.0" => 0, "latest" => 0 }.fetch(options[:version])
|
412
433
|
|
413
434
|
template << "L"
|
414
435
|
if (scopes = options[:scopes])
|
@@ -396,8 +396,8 @@ module Prism
|
|
396
396
|
commands << ["├── message_loc: #{inspect_location(node.message_loc)}\n", indent]
|
397
397
|
commands << ["├── read_name: #{node.read_name.inspect}\n", indent]
|
398
398
|
commands << ["├── write_name: #{node.write_name.inspect}\n", indent]
|
399
|
-
commands << ["├──
|
400
|
-
commands << ["├──
|
399
|
+
commands << ["├── binary_operator: #{node.binary_operator.inspect}\n", indent]
|
400
|
+
commands << ["├── binary_operator_loc: #{inspect_location(node.binary_operator_loc)}\n", indent]
|
401
401
|
commands << ["└── value:\n", indent]
|
402
402
|
commands << [node.value, "#{indent} "]
|
403
403
|
end
|
@@ -539,10 +539,10 @@ module Prism
|
|
539
539
|
commands << [inspect_node("ClassVariableOperatorWriteNode", node), indent]
|
540
540
|
commands << ["├── name: #{node.name.inspect}\n", indent]
|
541
541
|
commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
|
542
|
-
commands << ["├──
|
542
|
+
commands << ["├── binary_operator_loc: #{inspect_location(node.binary_operator_loc)}\n", indent]
|
543
543
|
commands << ["├── value:\n", indent]
|
544
544
|
commands << [node.value, "#{indent}│ "]
|
545
|
-
commands << ["└──
|
545
|
+
commands << ["└── binary_operator: #{node.binary_operator.inspect}\n", indent]
|
546
546
|
end
|
547
547
|
|
548
548
|
# Inspect a ClassVariableOrWriteNode node.
|
@@ -592,10 +592,10 @@ module Prism
|
|
592
592
|
commands << [inspect_node("ConstantOperatorWriteNode", node), indent]
|
593
593
|
commands << ["├── name: #{node.name.inspect}\n", indent]
|
594
594
|
commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
|
595
|
-
commands << ["├──
|
595
|
+
commands << ["├── binary_operator_loc: #{inspect_location(node.binary_operator_loc)}\n", indent]
|
596
596
|
commands << ["├── value:\n", indent]
|
597
597
|
commands << [node.value, "#{indent}│ "]
|
598
|
-
commands << ["└──
|
598
|
+
commands << ["└── binary_operator: #{node.binary_operator.inspect}\n", indent]
|
599
599
|
end
|
600
600
|
|
601
601
|
# Inspect a ConstantOrWriteNode node.
|
@@ -641,10 +641,10 @@ module Prism
|
|
641
641
|
commands << [inspect_node("ConstantPathOperatorWriteNode", node), indent]
|
642
642
|
commands << ["├── target:\n", indent]
|
643
643
|
commands << [node.target, "#{indent}│ "]
|
644
|
-
commands << ["├──
|
644
|
+
commands << ["├── binary_operator_loc: #{inspect_location(node.binary_operator_loc)}\n", indent]
|
645
645
|
commands << ["├── value:\n", indent]
|
646
646
|
commands << [node.value, "#{indent}│ "]
|
647
|
-
commands << ["└──
|
647
|
+
commands << ["└── binary_operator: #{node.binary_operator.inspect}\n", indent]
|
648
648
|
end
|
649
649
|
|
650
650
|
# Inspect a ConstantPathOrWriteNode node.
|
@@ -908,10 +908,10 @@ module Prism
|
|
908
908
|
commands << [inspect_node("GlobalVariableOperatorWriteNode", node), indent]
|
909
909
|
commands << ["├── name: #{node.name.inspect}\n", indent]
|
910
910
|
commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
|
911
|
-
commands << ["├──
|
911
|
+
commands << ["├── binary_operator_loc: #{inspect_location(node.binary_operator_loc)}\n", indent]
|
912
912
|
commands << ["├── value:\n", indent]
|
913
913
|
commands << [node.value, "#{indent}│ "]
|
914
|
-
commands << ["└──
|
914
|
+
commands << ["└── binary_operator: #{node.binary_operator.inspect}\n", indent]
|
915
915
|
end
|
916
916
|
|
917
917
|
# Inspect a GlobalVariableOrWriteNode node.
|
@@ -1103,8 +1103,8 @@ module Prism
|
|
1103
1103
|
commands << ["├── block:\n", indent]
|
1104
1104
|
commands << [block, "#{indent}│ "]
|
1105
1105
|
end
|
1106
|
-
commands << ["├──
|
1107
|
-
commands << ["├──
|
1106
|
+
commands << ["├── binary_operator: #{node.binary_operator.inspect}\n", indent]
|
1107
|
+
commands << ["├── binary_operator_loc: #{inspect_location(node.binary_operator_loc)}\n", indent]
|
1108
1108
|
commands << ["└── value:\n", indent]
|
1109
1109
|
commands << [node.value, "#{indent} "]
|
1110
1110
|
end
|
@@ -1178,10 +1178,10 @@ module Prism
|
|
1178
1178
|
commands << [inspect_node("InstanceVariableOperatorWriteNode", node), indent]
|
1179
1179
|
commands << ["├── name: #{node.name.inspect}\n", indent]
|
1180
1180
|
commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
|
1181
|
-
commands << ["├──
|
1181
|
+
commands << ["├── binary_operator_loc: #{inspect_location(node.binary_operator_loc)}\n", indent]
|
1182
1182
|
commands << ["├── value:\n", indent]
|
1183
1183
|
commands << [node.value, "#{indent}│ "]
|
1184
|
-
commands << ["└──
|
1184
|
+
commands << ["└── binary_operator: #{node.binary_operator.inspect}\n", indent]
|
1185
1185
|
end
|
1186
1186
|
|
1187
1187
|
# Inspect a InstanceVariableOrWriteNode node.
|
@@ -1310,6 +1310,11 @@ module Prism
|
|
1310
1310
|
commands << ["└── closing_loc: #{inspect_location(node.closing_loc)}\n", indent]
|
1311
1311
|
end
|
1312
1312
|
|
1313
|
+
# Inspect a ItLocalVariableReadNode node.
|
1314
|
+
def visit_it_local_variable_read_node(node)
|
1315
|
+
commands << [inspect_node("ItLocalVariableReadNode", node), indent]
|
1316
|
+
end
|
1317
|
+
|
1313
1318
|
# Inspect a ItParametersNode node.
|
1314
1319
|
def visit_it_parameters_node(node)
|
1315
1320
|
commands << [inspect_node("ItParametersNode", node), indent]
|
@@ -1381,11 +1386,11 @@ module Prism
|
|
1381
1386
|
def visit_local_variable_operator_write_node(node)
|
1382
1387
|
commands << [inspect_node("LocalVariableOperatorWriteNode", node), indent]
|
1383
1388
|
commands << ["├── name_loc: #{inspect_location(node.name_loc)}\n", indent]
|
1384
|
-
commands << ["├──
|
1389
|
+
commands << ["├── binary_operator_loc: #{inspect_location(node.binary_operator_loc)}\n", indent]
|
1385
1390
|
commands << ["├── value:\n", indent]
|
1386
1391
|
commands << [node.value, "#{indent}│ "]
|
1387
1392
|
commands << ["├── name: #{node.name.inspect}\n", indent]
|
1388
|
-
commands << ["├──
|
1393
|
+
commands << ["├── binary_operator: #{node.binary_operator.inspect}\n", indent]
|
1389
1394
|
commands << ["└── depth: #{node.depth.inspect}\n", indent]
|
1390
1395
|
end
|
1391
1396
|
|
@@ -1777,8 +1782,10 @@ module Prism
|
|
1777
1782
|
# Inspect a RationalNode node.
|
1778
1783
|
def visit_rational_node(node)
|
1779
1784
|
commands << [inspect_node("RationalNode", node), indent]
|
1780
|
-
|
1781
|
-
commands << [
|
1785
|
+
flags = [("binary" if node.binary?), ("decimal" if node.decimal?), ("octal" if node.octal?), ("hexadecimal" if node.hexadecimal?)].compact
|
1786
|
+
commands << ["├── flags: #{flags.empty? ? "∅" : flags.join(", ")}\n", indent]
|
1787
|
+
commands << ["├── numerator: #{node.numerator.inspect}\n", indent]
|
1788
|
+
commands << ["└── denominator: #{node.denominator.inspect}\n", indent]
|
1782
1789
|
end
|
1783
1790
|
|
1784
1791
|
# Inspect a RedoNode node.
|
@@ -2135,13 +2142,8 @@ module Prism
|
|
2135
2142
|
|
2136
2143
|
# Compose a header for the given node.
|
2137
2144
|
def inspect_node(name, node)
|
2138
|
-
result = +"@ #{name} ("
|
2139
|
-
|
2140
2145
|
location = node.location
|
2141
|
-
|
2142
|
-
result << ", newline: true" if node.newline?
|
2143
|
-
|
2144
|
-
result << ")\n"
|
2146
|
+
"@ #{name} (location: (#{location.start_line},#{location.start_column})-(#{location.end_line},#{location.end_column}))\n"
|
2145
2147
|
end
|
2146
2148
|
|
2147
2149
|
# Compose a string representing the given inner location field.
|
@@ -446,6 +446,11 @@ module Prism
|
|
446
446
|
node.copy(parts: visit_all(node.parts))
|
447
447
|
end
|
448
448
|
|
449
|
+
# Copy a ItLocalVariableReadNode node
|
450
|
+
def visit_it_local_variable_read_node(node)
|
451
|
+
node.copy
|
452
|
+
end
|
453
|
+
|
449
454
|
# Copy a ItParametersNode node
|
450
455
|
def visit_it_parameters_node(node)
|
451
456
|
node.copy
|
@@ -618,7 +623,7 @@ module Prism
|
|
618
623
|
|
619
624
|
# Copy a RationalNode node
|
620
625
|
def visit_rational_node(node)
|
621
|
-
node.copy
|
626
|
+
node.copy
|
622
627
|
end
|
623
628
|
|
624
629
|
# Copy a RedoNode node
|