yarp 0.7.0 → 0.9.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.
data/config.yml CHANGED
@@ -527,7 +527,7 @@ nodes:
527
527
  - name: parameters
528
528
  type: node?
529
529
  kind: BlockParametersNode
530
- - name: statements
530
+ - name: body
531
531
  type: node?
532
532
  - name: opening_loc
533
533
  type: location
@@ -714,16 +714,18 @@ nodes:
714
714
  type: location?
715
715
  - name: superclass
716
716
  type: node?
717
- - name: statements
717
+ - name: body
718
718
  type: node?
719
719
  - name: end_keyword_loc
720
720
  type: location
721
+ - name: name
722
+ type: string
721
723
  comment: |
722
724
  Represents a class declaration involving the `class` keyword.
723
725
 
724
726
  class Foo end
725
727
  ^^^^^^^^^^^^^
726
- - name: ClassVariableOperatorAndWriteNode
728
+ - name: ClassVariableAndWriteNode
727
729
  child_nodes:
728
730
  - name: name_loc
729
731
  type: location
@@ -736,7 +738,7 @@ nodes:
736
738
 
737
739
  @@target &&= value
738
740
  ^^^^^^^^^^^^^^^^
739
- - name: ClassVariableOperatorOrWriteNode
741
+ - name: ClassVariableOperatorWriteNode
740
742
  child_nodes:
741
743
  - name: name_loc
742
744
  type: location
@@ -744,12 +746,14 @@ nodes:
744
746
  type: location
745
747
  - name: value
746
748
  type: node
749
+ - name: operator
750
+ type: constant
747
751
  comment: |
748
- Represents the use of the `||=` operator for assignment to a class variable.
752
+ Represents assigning to a class variable using an operator that isn't `=`.
749
753
 
750
- @@target ||= value
751
- ^^^^^^^^^^^^^^^^^^
752
- - name: ClassVariableOperatorWriteNode
754
+ @@target += value
755
+ ^^^^^^^^^^^^^^^^^
756
+ - name: ClassVariableOrWriteNode
753
757
  child_nodes:
754
758
  - name: name_loc
755
759
  type: location
@@ -757,19 +761,23 @@ nodes:
757
761
  type: location
758
762
  - name: value
759
763
  type: node
760
- - name: operator
761
- type: constant
762
764
  comment: |
763
- Represents assigning to a class variable using an operator that isn't `=`.
765
+ Represents the use of the `||=` operator for assignment to a class variable.
764
766
 
765
- @@target += value
766
- ^^^^^^^^^^^^^^^^^
767
+ @@target ||= value
768
+ ^^^^^^^^^^^^^^^^^^
767
769
  - name: ClassVariableReadNode
768
770
  comment: |
769
771
  Represents referencing a class variable.
770
772
 
771
773
  @@foo
772
774
  ^^^^^
775
+ - name: ClassVariableTargetNode
776
+ comment: |
777
+ Represents writing to a class variable in a context that doesn't have an explicit value.
778
+
779
+ @@foo, @@bar = baz
780
+ ^^^^^ ^^^^^
773
781
  - name: ClassVariableWriteNode
774
782
  child_nodes:
775
783
  - name: name_loc
@@ -783,7 +791,7 @@ nodes:
783
791
 
784
792
  @@foo = 1
785
793
  ^^^^^^^^^
786
- - name: ConstantOperatorAndWriteNode
794
+ - name: ConstantAndWriteNode
787
795
  child_nodes:
788
796
  - name: name_loc
789
797
  type: location
@@ -796,7 +804,22 @@ nodes:
796
804
 
797
805
  Target &&= value
798
806
  ^^^^^^^^^^^^^^^^
799
- - name: ConstantOperatorOrWriteNode
807
+ - name: ConstantOperatorWriteNode
808
+ child_nodes:
809
+ - name: name_loc
810
+ type: location
811
+ - name: operator_loc
812
+ type: location
813
+ - name: value
814
+ type: node
815
+ - name: operator
816
+ type: constant
817
+ comment: |
818
+ Represents assigning to a constant using an operator that isn't `=`.
819
+
820
+ Target += value
821
+ ^^^^^^^^^^^^^^^
822
+ - name: ConstantOrWriteNode
800
823
  child_nodes:
801
824
  - name: name_loc
802
825
  type: location
@@ -809,21 +832,20 @@ nodes:
809
832
 
810
833
  Target ||= value
811
834
  ^^^^^^^^^^^^^^^^
812
- - name: ConstantOperatorWriteNode
835
+ - name: ConstantPathAndWriteNode
813
836
  child_nodes:
814
- - name: name_loc
815
- type: location
837
+ - name: target
838
+ type: node
839
+ kind: ConstantPathNode
816
840
  - name: operator_loc
817
841
  type: location
818
842
  - name: value
819
843
  type: node
820
- - name: operator
821
- type: constant
822
844
  comment: |
823
- Represents assigning to a constant using an operator that isn't `=`.
845
+ Represents the use of the `&&=` operator for assignment to a constant path.
824
846
 
825
- Target += value
826
- ^^^^^^^^^^^^^^^
847
+ Parent::Child &&= value
848
+ ^^^^^^^^^^^^^^^^^^^^^^^
827
849
  - name: ConstantPathNode
828
850
  child_nodes:
829
851
  - name: parent
@@ -837,7 +859,7 @@ nodes:
837
859
 
838
860
  Foo::Bar
839
861
  ^^^^^^^^
840
- - name: ConstantPathOperatorAndWriteNode
862
+ - name: ConstantPathOperatorWriteNode
841
863
  child_nodes:
842
864
  - name: target
843
865
  type: node
@@ -846,12 +868,14 @@ nodes:
846
868
  type: location
847
869
  - name: value
848
870
  type: node
871
+ - name: operator
872
+ type: constant
849
873
  comment: |
850
- Represents the use of the `&&=` operator for assignment to a constant path.
874
+ Represents assigning to a constant path using an operator that isn't `=`.
851
875
 
852
- Parent::Child &&= value
853
- ^^^^^^^^^^^^^^^^^^^^^^^
854
- - name: ConstantPathOperatorOrWriteNode
876
+ Parent::Child += value
877
+ ^^^^^^^^^^^^^^^^^^^^^^
878
+ - name: ConstantPathOrWriteNode
855
879
  child_nodes:
856
880
  - name: target
857
881
  type: node
@@ -865,31 +889,28 @@ nodes:
865
889
 
866
890
  Parent::Child ||= value
867
891
  ^^^^^^^^^^^^^^^^^^^^^^^
868
- - name: ConstantPathOperatorWriteNode
892
+ - name: ConstantPathTargetNode
869
893
  child_nodes:
870
- - name: target
894
+ - name: parent
895
+ type: node?
896
+ - name: child
871
897
  type: node
872
- kind: ConstantPathNode
873
- - name: operator_loc
898
+ - name: delimiter_loc
874
899
  type: location
875
- - name: value
876
- type: node
877
- - name: operator
878
- type: constant
879
900
  comment: |
880
- Represents assigning to a constant path using an operator that isn't `=`.
901
+ Represents writing to a constant path in a context that doesn't have an explicit value.
881
902
 
882
- Parent::Child += value
883
- ^^^^^^^^^^^^^^^^^^^^^^
903
+ Foo::Foo, Bar::Bar = baz
904
+ ^^^^^^^^ ^^^^^^^^
884
905
  - name: ConstantPathWriteNode
885
906
  child_nodes:
886
907
  - name: target
887
908
  type: node
888
909
  kind: ConstantPathNode
889
910
  - name: operator_loc
890
- type: location?
911
+ type: location
891
912
  - name: value
892
- type: node?
913
+ type: node
893
914
  comment: |
894
915
  Represents writing to a constant path.
895
916
 
@@ -907,14 +928,20 @@ nodes:
907
928
 
908
929
  Foo
909
930
  ^^^
931
+ - name: ConstantTargetNode
932
+ comment: |
933
+ Represents writing to a constant in a context that doesn't have an explicit value.
934
+
935
+ Foo, Bar = baz
936
+ ^^^ ^^^
910
937
  - name: ConstantWriteNode
911
938
  child_nodes:
912
939
  - name: name_loc
913
940
  type: location
914
941
  - name: value
915
- type: node?
942
+ type: node
916
943
  - name: operator_loc
917
- type: location?
944
+ type: location
918
945
  comment: |
919
946
  Represents writing to a constant.
920
947
 
@@ -929,7 +956,7 @@ nodes:
929
956
  - name: parameters
930
957
  type: node?
931
958
  kind: ParametersNode
932
- - name: statements
959
+ - name: body
933
960
  type: node?
934
961
  - name: locals
935
962
  type: constant[]
@@ -1123,7 +1150,7 @@ nodes:
1123
1150
 
1124
1151
  super
1125
1152
  ^^^^^
1126
- - name: GlobalVariableOperatorAndWriteNode
1153
+ - name: GlobalVariableAndWriteNode
1127
1154
  child_nodes:
1128
1155
  - name: name_loc
1129
1156
  type: location
@@ -1136,7 +1163,7 @@ nodes:
1136
1163
 
1137
1164
  $target &&= value
1138
1165
  ^^^^^^^^^^^^^^^^^
1139
- - name: GlobalVariableOperatorOrWriteNode
1166
+ - name: GlobalVariableOperatorWriteNode
1140
1167
  child_nodes:
1141
1168
  - name: name_loc
1142
1169
  type: location
@@ -1144,12 +1171,14 @@ nodes:
1144
1171
  type: location
1145
1172
  - name: value
1146
1173
  type: node
1174
+ - name: operator
1175
+ type: constant
1147
1176
  comment: |
1148
- Represents the use of the `||=` operator for assignment to a global variable.
1177
+ Represents assigning to a global variable using an operator that isn't `=`.
1149
1178
 
1150
- $target ||= value
1151
- ^^^^^^^^^^^^^^^^^
1152
- - name: GlobalVariableOperatorWriteNode
1179
+ $target += value
1180
+ ^^^^^^^^^^^^^^^^
1181
+ - name: GlobalVariableOrWriteNode
1153
1182
  child_nodes:
1154
1183
  - name: name_loc
1155
1184
  type: location
@@ -1157,27 +1186,31 @@ nodes:
1157
1186
  type: location
1158
1187
  - name: value
1159
1188
  type: node
1160
- - name: operator
1161
- type: constant
1162
1189
  comment: |
1163
- Represents assigning to a global variable using an operator that isn't `=`.
1190
+ Represents the use of the `||=` operator for assignment to a global variable.
1164
1191
 
1165
- $target += value
1166
- ^^^^^^^^^^^^^^^^
1192
+ $target ||= value
1193
+ ^^^^^^^^^^^^^^^^^
1167
1194
  - name: GlobalVariableReadNode
1168
1195
  comment: |
1169
1196
  Represents referencing a global variable.
1170
1197
 
1171
1198
  $foo
1172
1199
  ^^^^
1200
+ - name: GlobalVariableTargetNode
1201
+ comment: |
1202
+ Represents writing to a global variable in a context that doesn't have an explicit value.
1203
+
1204
+ $foo, $bar = baz
1205
+ ^^^^ ^^^^
1173
1206
  - name: GlobalVariableWriteNode
1174
1207
  child_nodes:
1175
1208
  - name: name_loc
1176
1209
  type: location
1177
1210
  - name: operator_loc
1178
- type: location?
1211
+ type: location
1179
1212
  - name: value
1180
- type: node?
1213
+ type: node
1181
1214
  comment: |
1182
1215
  Represents writing to a global variable.
1183
1216
 
@@ -1263,7 +1296,7 @@ nodes:
1263
1296
 
1264
1297
  case a; in b then c end
1265
1298
  ^^^^^^^^^^^
1266
- - name: InstanceVariableOperatorAndWriteNode
1299
+ - name: InstanceVariableAndWriteNode
1267
1300
  child_nodes:
1268
1301
  - name: name_loc
1269
1302
  type: location
@@ -1276,7 +1309,7 @@ nodes:
1276
1309
 
1277
1310
  @target &&= value
1278
1311
  ^^^^^^^^^^^^^^^^^
1279
- - name: InstanceVariableOperatorOrWriteNode
1312
+ - name: InstanceVariableOperatorWriteNode
1280
1313
  child_nodes:
1281
1314
  - name: name_loc
1282
1315
  type: location
@@ -1284,12 +1317,14 @@ nodes:
1284
1317
  type: location
1285
1318
  - name: value
1286
1319
  type: node
1320
+ - name: operator
1321
+ type: constant
1287
1322
  comment: |
1288
- Represents the use of the `||=` operator for assignment to an instance variable.
1323
+ Represents assigning to an instance variable using an operator that isn't `=`.
1289
1324
 
1290
- @target ||= value
1291
- ^^^^^^^^^^^^^^^^^
1292
- - name: InstanceVariableOperatorWriteNode
1325
+ @target += value
1326
+ ^^^^^^^^^^^^^^^^
1327
+ - name: InstanceVariableOrWriteNode
1293
1328
  child_nodes:
1294
1329
  - name: name_loc
1295
1330
  type: location
@@ -1297,27 +1332,31 @@ nodes:
1297
1332
  type: location
1298
1333
  - name: value
1299
1334
  type: node
1300
- - name: operator
1301
- type: constant
1302
1335
  comment: |
1303
- Represents assigning to an instance variable using an operator that isn't `=`.
1336
+ Represents the use of the `||=` operator for assignment to an instance variable.
1304
1337
 
1305
- @target += value
1306
- ^^^^^^^^^^^^^^^^
1338
+ @target ||= value
1339
+ ^^^^^^^^^^^^^^^^^
1307
1340
  - name: InstanceVariableReadNode
1308
1341
  comment: |
1309
1342
  Represents referencing an instance variable.
1310
1343
 
1311
1344
  @foo
1312
1345
  ^^^^
1346
+ - name: InstanceVariableTargetNode
1347
+ comment: |
1348
+ Represents writing to an instance variable in a context that doesn't have an explicit value.
1349
+
1350
+ @foo, @bar = baz
1351
+ ^^^^ ^^^^
1313
1352
  - name: InstanceVariableWriteNode
1314
1353
  child_nodes:
1315
1354
  - name: name_loc
1316
1355
  type: location
1317
1356
  - name: value
1318
- type: node?
1357
+ type: node
1319
1358
  - name: operator_loc
1320
- type: location?
1359
+ type: location
1321
1360
  comment: |
1322
1361
  Represents writing to an instance variable.
1323
1362
 
@@ -1429,19 +1468,23 @@ nodes:
1429
1468
  child_nodes:
1430
1469
  - name: locals
1431
1470
  type: constant[]
1471
+ - name: operator_loc
1472
+ type: location
1432
1473
  - name: opening_loc
1433
1474
  type: location
1475
+ - name: closing_loc
1476
+ type: location
1434
1477
  - name: parameters
1435
1478
  type: node?
1436
1479
  kind: BlockParametersNode
1437
- - name: statements
1480
+ - name: body
1438
1481
  type: node?
1439
1482
  comment: |
1440
1483
  Represents using a lambda literal (not the lambda method call).
1441
1484
 
1442
1485
  ->(value) { value * 2 }
1443
1486
  ^^^^^^^^^^^^^^^^^^^^^^^
1444
- - name: LocalVariableOperatorAndWriteNode
1487
+ - name: LocalVariableAndWriteNode
1445
1488
  child_nodes:
1446
1489
  - name: name_loc
1447
1490
  type: location
@@ -1451,12 +1494,14 @@ nodes:
1451
1494
  type: node
1452
1495
  - name: constant_id
1453
1496
  type: constant
1497
+ - name: depth
1498
+ type: uint32
1454
1499
  comment: |
1455
1500
  Represents the use of the `&&=` operator for assignment to a local variable.
1456
1501
 
1457
1502
  target &&= value
1458
1503
  ^^^^^^^^^^^^^^^^
1459
- - name: LocalVariableOperatorOrWriteNode
1504
+ - name: LocalVariableOperatorWriteNode
1460
1505
  child_nodes:
1461
1506
  - name: name_loc
1462
1507
  type: location
@@ -1466,12 +1511,16 @@ nodes:
1466
1511
  type: node
1467
1512
  - name: constant_id
1468
1513
  type: constant
1514
+ - name: operator_id
1515
+ type: constant
1516
+ - name: depth
1517
+ type: uint32
1469
1518
  comment: |
1470
- Represents the use of the `||=` operator for assignment to a local variable.
1519
+ Represents assigning to a local variable using an operator that isn't `=`.
1471
1520
 
1472
- target ||= value
1473
- ^^^^^^^^^^^^^^^^
1474
- - name: LocalVariableOperatorWriteNode
1521
+ target += value
1522
+ ^^^^^^^^^^^^^^^
1523
+ - name: LocalVariableOrWriteNode
1475
1524
  child_nodes:
1476
1525
  - name: name_loc
1477
1526
  type: location
@@ -1481,13 +1530,13 @@ nodes:
1481
1530
  type: node
1482
1531
  - name: constant_id
1483
1532
  type: constant
1484
- - name: operator_id
1485
- type: constant
1533
+ - name: depth
1534
+ type: uint32
1486
1535
  comment: |
1487
- Represents assigning to a local variable using an operator that isn't `=`.
1536
+ Represents the use of the `||=` operator for assignment to a local variable.
1488
1537
 
1489
- target += value
1490
- ^^^^^^^^^^^^^^^
1538
+ target ||= value
1539
+ ^^^^^^^^^^^^^^^^
1491
1540
  - name: LocalVariableReadNode
1492
1541
  child_nodes:
1493
1542
  - name: constant_id
@@ -1501,6 +1550,17 @@ nodes:
1501
1550
 
1502
1551
  foo
1503
1552
  ^^^
1553
+ - name: LocalVariableTargetNode
1554
+ child_nodes:
1555
+ - name: constant_id
1556
+ type: constant
1557
+ - name: depth
1558
+ type: uint32
1559
+ comment: |
1560
+ Represents writing to a local variable in a context that doesn't have an explicit value.
1561
+
1562
+ foo, bar = baz
1563
+ ^^^ ^^^
1504
1564
  - name: LocalVariableWriteNode
1505
1565
  child_nodes:
1506
1566
  - name: constant_id
@@ -1508,11 +1568,11 @@ nodes:
1508
1568
  - name: depth
1509
1569
  type: uint32
1510
1570
  - name: value
1511
- type: node?
1571
+ type: node
1512
1572
  - name: name_loc
1513
1573
  type: location
1514
1574
  - name: operator_loc
1515
- type: location?
1575
+ type: location
1516
1576
  comment: |
1517
1577
  Represents writing to a local variable.
1518
1578
 
@@ -1556,10 +1616,12 @@ nodes:
1556
1616
  type: location
1557
1617
  - name: constant_path
1558
1618
  type: node
1559
- - name: statements
1619
+ - name: body
1560
1620
  type: node?
1561
1621
  - name: end_keyword_loc
1562
1622
  type: location
1623
+ - name: name
1624
+ type: string
1563
1625
  comment: |
1564
1626
  Represents a module declaration involving the `module` keyword.
1565
1627
 
@@ -1673,7 +1735,7 @@ nodes:
1673
1735
  end
1674
1736
  - name: ParenthesesNode
1675
1737
  child_nodes:
1676
- - name: statements
1738
+ - name: body
1677
1739
  type: node?
1678
1740
  - name: opening_loc
1679
1741
  type: location
@@ -1916,7 +1978,7 @@ nodes:
1916
1978
  type: location
1917
1979
  - name: expression
1918
1980
  type: node
1919
- - name: statements
1981
+ - name: body
1920
1982
  type: node?
1921
1983
  - name: end_keyword_loc
1922
1984
  type: location
@@ -1932,7 +1994,6 @@ nodes:
1932
1994
  __ENCODING__
1933
1995
  ^^^^^^^^^^^^
1934
1996
  - name: SourceFileNode
1935
- is_migrated: true
1936
1997
  child_nodes:
1937
1998
  - name: filepath
1938
1999
  type: string
@@ -2027,7 +2088,7 @@ nodes:
2027
2088
  - name: opening_loc
2028
2089
  type: location?
2029
2090
  - name: value_loc
2030
- type: location
2091
+ type: location?
2031
2092
  - name: closing_loc
2032
2093
  type: location?
2033
2094
  - name: unescaped
@@ -2084,6 +2145,8 @@ nodes:
2084
2145
  child_nodes:
2085
2146
  - name: keyword_loc
2086
2147
  type: location
2148
+ - name: closing_loc
2149
+ type: location?
2087
2150
  - name: predicate
2088
2151
  type: node
2089
2152
  - name: statements
@@ -2111,14 +2174,18 @@ nodes:
2111
2174
  type: node?
2112
2175
  kind: StatementsNode
2113
2176
  comment: |
2114
- case true
2115
- when true
2116
- ^^^^^^^^^
2117
- end
2177
+ Represents the use of the `when` keyword within a case statement.
2178
+
2179
+ case true
2180
+ when true
2181
+ ^^^^^^^^^
2182
+ end
2118
2183
  - name: WhileNode
2119
2184
  child_nodes:
2120
2185
  - name: keyword_loc
2121
2186
  type: location
2187
+ - name: closing_loc
2188
+ type: location?
2122
2189
  - name: predicate
2123
2190
  type: node
2124
2191
  - name: statements
@@ -7,6 +7,7 @@ A lot of code in YARP's repository is templated from a single configuration file
7
7
  * `java/org/yarp/AbstractNodeVisitor.java` - for defining the visitor interface for the nodes in Java
8
8
  * `java/org/yarp/Loader.java` - for defining how to deserialize the nodes in Java
9
9
  * `java/org/yarp/Nodes.java` - for defining the nodes in Java
10
+ * `lib/yarp/mutation_visitor.rb` - for defining the mutation visitor for the nodes in Ruby
10
11
  * `lib/yarp/node.rb` - for defining the nodes in Ruby
11
12
  * `lib/yarp/serialize.rb` - for defining how to deserialize the nodes in Ruby
12
13
  * `src/node.c` - for defining how to free the nodes in C and calculate the size in memory in C
data/docs/ruby_api.md CHANGED
@@ -20,4 +20,6 @@ The full API is documented below.
20
20
  * `YARP.lex_file(filepath)` - parse the tokens corresponding to the given source file and return them as an array within a parse result
21
21
  * `YARP.parse(source)` - parse the syntax tree corresponding to the given source string and return it within a parse result
22
22
  * `YARP.parse_file(filepath)` - parse the syntax tree corresponding to the given source file and return it within a parse result
23
+ * `YARP.parse_lex(source)` - parse the syntax tree corresponding to the given source string and return it within a parse result, along with the tokens
24
+ * `YARP.parse_lex_file(filepath)` - parse the syntax tree corresponding to the given source file and return it within a parse result, along with the tokens
23
25
  * `YARP.load(source, serialized)` - load the serialized syntax tree using the source as a reference into a syntax tree
@@ -73,7 +73,7 @@ The header is structured like the following table:
73
73
  | varint | content pool size |
74
74
 
75
75
  After the header comes the body of the serialized string.
76
- The body consistents of a sequence of nodes that is built using a prefix traversal order of the syntax tree.
76
+ The body consists of a sequence of nodes that is built using a prefix traversal order of the syntax tree.
77
77
  Each node is structured like the following table:
78
78
 
79
79
  | # bytes | field |
data/docs/testing.md CHANGED
@@ -12,9 +12,9 @@ These test specific YARP implementation details like comments, errors, and regul
12
12
 
13
13
  ### Snapshot tests
14
14
 
15
- Snapshot tests ensure that parsed output is equivalent to previous parsed output. There are many categorized examples of valid syntax within the `test/fixtures/` directory. When the test suite runs, it will parse all of this syntax, and compare it against corresponding files in the `test/snapshots/` directory. For example, `test/fixtures/strings.txt` has a corresponding `test/snapshots/strings.txt`.
15
+ Snapshot tests ensure that parsed output is equivalent to previous parsed output. There are many categorized examples of valid syntax within the `test/yarp/fixtures/` directory. When the test suite runs, it will parse all of this syntax, and compare it against corresponding files in the `test/yarp/snapshots/` directory. For example, `test/yarp/fixtures/strings.txt` has a corresponding `test/yarp/snapshots/strings.txt`.
16
16
 
17
- If the parsed files do not match, it will raise an error. If there is not a corresponding file in the `test/snapshots/` directory, one will be created so that it exists for the next test run.
17
+ If the parsed files do not match, it will raise an error. If there is not a corresponding file in the `test/yarp/snapshots/` directory, one will be created so that it exists for the next test run.
18
18
 
19
19
  ### Testing against repositories
20
20