prism 0.26.0 → 0.27.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
 
@@ -515,7 +517,7 @@ parser_warnings(pm_parser_t *parser, rb_encoding *encoding, VALUE source) {
515
517
  * Create a new parse result from the given parser, value, encoding, and source.
516
518
  */
517
519
  static VALUE
518
- parse_result_create(pm_parser_t *parser, VALUE value, rb_encoding *encoding, VALUE source) {
520
+ parse_result_create(VALUE class, pm_parser_t *parser, VALUE value, rb_encoding *encoding, VALUE source) {
519
521
  VALUE result_argv[] = {
520
522
  value,
521
523
  parser_comments(parser, source),
@@ -526,7 +528,7 @@ parse_result_create(pm_parser_t *parser, VALUE value, rb_encoding *encoding, VAL
526
528
  source
527
529
  };
528
530
 
529
- return rb_class_new_instance(7, result_argv, rb_cPrismParseResult);
531
+ return rb_class_new_instance(7, result_argv, class);
530
532
  }
531
533
 
532
534
  /******************************************************************************/
@@ -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);
@@ -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
- rb_cPrismParseResult = rb_define_class_under(rb_cPrism, "ParseResult", rb_cObject);
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.
@@ -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.26.0"
4
+ #define EXPECTED_PRISM_VERSION "0.27.0"
5
5
 
6
6
  #include <ruby.h>
7
7
  #include <ruby/encoding.h>
data/include/prism/ast.h CHANGED
@@ -1099,16 +1099,31 @@ typedef struct pm_alias_global_variable_node {
1099
1099
 
1100
1100
  /**
1101
1101
  * AliasGlobalVariableNode#new_name
1102
+ *
1103
+ * Represents the new name of the global variable that can be used after aliasing. This can be either a global variable, a back reference, or a numbered reference.
1104
+ *
1105
+ * alias $foo $bar
1106
+ * ^^^^
1102
1107
  */
1103
1108
  struct pm_node *new_name;
1104
1109
 
1105
1110
  /**
1106
1111
  * AliasGlobalVariableNode#old_name
1112
+ *
1113
+ * Represents the old name of the global variable that could be used before aliasing. This can be either a global variable, a back reference, or a numbered reference.
1114
+ *
1115
+ * alias $foo $bar
1116
+ * ^^^^
1107
1117
  */
1108
1118
  struct pm_node *old_name;
1109
1119
 
1110
1120
  /**
1111
1121
  * AliasGlobalVariableNode#keyword_loc
1122
+ *
1123
+ * The location of the `alias` keyword.
1124
+ *
1125
+ * alias $foo $bar
1126
+ * ^^^^^
1112
1127
  */
1113
1128
  pm_location_t keyword_loc;
1114
1129
  } pm_alias_global_variable_node_t;
@@ -1249,16 +1264,32 @@ typedef struct pm_array_node {
1249
1264
 
1250
1265
  /**
1251
1266
  * ArrayNode#elements
1267
+ *
1268
+ * Represent the list of zero or more [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression) within the array.
1252
1269
  */
1253
1270
  struct pm_node_list elements;
1254
1271
 
1255
1272
  /**
1256
1273
  * ArrayNode#opening_loc
1274
+ *
1275
+ * Represents the optional source location for the opening token.
1276
+ *
1277
+ * [1,2,3] # "["
1278
+ * %w[foo bar baz] # "%w["
1279
+ * %I(apple orange banana) # "%I("
1280
+ * foo = 1, 2, 3 # nil
1257
1281
  */
1258
1282
  pm_location_t opening_loc;
1259
1283
 
1260
1284
  /**
1261
1285
  * ArrayNode#closing_loc
1286
+ *
1287
+ * Represents the optional source location for the closing token.
1288
+ *
1289
+ * [1,2,3] # "]"
1290
+ * %w[foo bar baz] # "]"
1291
+ * %I(apple orange banana) # ")"
1292
+ * foo = 1, 2, 3 # nil
1262
1293
  */
1263
1294
  pm_location_t closing_loc;
1264
1295
  } pm_array_node_t;
@@ -1605,11 +1636,21 @@ typedef struct pm_break_node {
1605
1636
 
1606
1637
  /**
1607
1638
  * BreakNode#arguments
1639
+ *
1640
+ * The arguments to the break statement, if present. These can be any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
1641
+ *
1642
+ * break foo
1643
+ * ^^^
1608
1644
  */
1609
1645
  struct pm_arguments_node *arguments;
1610
1646
 
1611
1647
  /**
1612
1648
  * BreakNode#keyword_loc
1649
+ *
1650
+ * The location of the `break` keyword.
1651
+ *
1652
+ * break foo
1653
+ * ^^^^^
1613
1654
  */
1614
1655
  pm_location_t keyword_loc;
1615
1656
  } pm_break_node_t;
@@ -2209,8 +2250,7 @@ typedef struct pm_class_variable_write_node {
2209
2250
  /**
2210
2251
  * ClassVariableWriteNode#value
2211
2252
  *
2212
- * The value to assign to the class variable. Can be any node that
2213
- * represents a non-void expression.
2253
+ * The value to write to the class variable. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
2214
2254
  *
2215
2255
  * @@foo = :bar
2216
2256
  * ^^^^
@@ -2372,16 +2412,47 @@ typedef struct pm_constant_path_node {
2372
2412
 
2373
2413
  /**
2374
2414
  * ConstantPathNode#parent
2415
+ *
2416
+ * The left-hand node of the path, if present. It can be `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression). It will be `nil` when the constant lookup is at the root of the module tree.
2417
+ *
2418
+ * Foo::Bar
2419
+ * ^^^
2420
+ *
2421
+ * self::Test
2422
+ * ^^^^
2423
+ *
2424
+ * a.b::C
2425
+ * ^^^
2375
2426
  */
2376
2427
  struct pm_node *parent;
2377
2428
 
2378
2429
  /**
2379
2430
  * ConstantPathNode#child
2431
+ *
2432
+ * The right-hand node of the path. Always a `ConstantReadNode` in a
2433
+ * valid Ruby syntax tree.
2434
+ *
2435
+ * ::Foo
2436
+ * ^^^
2437
+ *
2438
+ * self::Test
2439
+ * ^^^^
2440
+ *
2441
+ * a.b::C
2442
+ * ^
2380
2443
  */
2381
2444
  struct pm_node *child;
2382
2445
 
2383
2446
  /**
2384
2447
  * ConstantPathNode#delimiter_loc
2448
+ *
2449
+ * The location of the `::` delimiter.
2450
+ *
2451
+ * ::Foo
2452
+ * ^^
2453
+ *
2454
+ * One::Two
2455
+ * ^^
2385
2456
  */
2386
2457
  pm_location_t delimiter_loc;
2387
2458
  } pm_constant_path_node_t;
@@ -2485,16 +2556,34 @@ typedef struct pm_constant_path_write_node {
2485
2556
 
2486
2557
  /**
2487
2558
  * ConstantPathWriteNode#target
2559
+ *
2560
+ * A node representing the constant path being written to.
2561
+ *
2562
+ * Foo::Bar = 1
2563
+ * ^^^^^^^^
2564
+ *
2565
+ * ::Foo = :abc
2566
+ * ^^^^^
2488
2567
  */
2489
2568
  struct pm_constant_path_node *target;
2490
2569
 
2491
2570
  /**
2492
2571
  * ConstantPathWriteNode#operator_loc
2572
+ *
2573
+ * The location of the `=` operator.
2574
+ *
2575
+ * ::ABC = 123
2576
+ * ^
2493
2577
  */
2494
2578
  pm_location_t operator_loc;
2495
2579
 
2496
2580
  /**
2497
2581
  * ConstantPathWriteNode#value
2582
+ *
2583
+ * The value to write to the constant path. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
2584
+ *
2585
+ * FOO::BAR = :abc
2586
+ * ^^^^
2498
2587
  */
2499
2588
  struct pm_node *value;
2500
2589
  } pm_constant_path_write_node_t;
@@ -2552,21 +2641,45 @@ typedef struct pm_constant_write_node {
2552
2641
 
2553
2642
  /**
2554
2643
  * ConstantWriteNode#name
2644
+ *
2645
+ * The name of the [constant](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#constants).
2646
+ *
2647
+ * Foo = :bar # name `:Foo`
2648
+ *
2649
+ * XYZ = 1 # name `:XYZ`
2555
2650
  */
2556
2651
  pm_constant_id_t name;
2557
2652
 
2558
2653
  /**
2559
2654
  * ConstantWriteNode#name_loc
2655
+ *
2656
+ * The location of the constant name.
2657
+ *
2658
+ * FOO = 1
2659
+ * ^^^
2560
2660
  */
2561
2661
  pm_location_t name_loc;
2562
2662
 
2563
2663
  /**
2564
2664
  * ConstantWriteNode#value
2665
+ *
2666
+ * The value to write to the constant. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
2667
+ *
2668
+ * FOO = :bar
2669
+ * ^^^^
2670
+ *
2671
+ * MyClass = Class.new
2672
+ * ^^^^^^^^^
2565
2673
  */
2566
2674
  struct pm_node *value;
2567
2675
 
2568
2676
  /**
2569
2677
  * ConstantWriteNode#operator_loc
2678
+ *
2679
+ * The location of the `=` operator.
2680
+ *
2681
+ * FOO = :bar
2682
+ * ^
2570
2683
  */
2571
2684
  pm_location_t operator_loc;
2572
2685
  } pm_constant_write_node_t;
@@ -3122,21 +3235,45 @@ typedef struct pm_global_variable_write_node {
3122
3235
 
3123
3236
  /**
3124
3237
  * GlobalVariableWriteNode#name
3238
+ *
3239
+ * The name of the global variable, which is a `$` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifier). Alternatively, it can be one of the special global variables designated by a symbol.
3240
+ *
3241
+ * $foo = :bar # name `:$foo`
3242
+ *
3243
+ * $_Test = 123 # name `:$_Test`
3125
3244
  */
3126
3245
  pm_constant_id_t name;
3127
3246
 
3128
3247
  /**
3129
3248
  * GlobalVariableWriteNode#name_loc
3249
+ *
3250
+ * The location of the global variable's name.
3251
+ *
3252
+ * $foo = :bar
3253
+ * ^^^^
3130
3254
  */
3131
3255
  pm_location_t name_loc;
3132
3256
 
3133
3257
  /**
3134
3258
  * GlobalVariableWriteNode#value
3259
+ *
3260
+ * The value to write to the global variable. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
3261
+ *
3262
+ * $foo = :bar
3263
+ * ^^^^
3264
+ *
3265
+ * $-xyz = 123
3266
+ * ^^^
3135
3267
  */
3136
3268
  struct pm_node *value;
3137
3269
 
3138
3270
  /**
3139
3271
  * GlobalVariableWriteNode#operator_loc
3272
+ *
3273
+ * The location of the `=` operator.
3274
+ *
3275
+ * $foo = :bar
3276
+ * ^
3140
3277
  */
3141
3278
  pm_location_t operator_loc;
3142
3279
  } pm_global_variable_write_node_t;
@@ -3236,31 +3373,89 @@ typedef struct pm_if_node {
3236
3373
 
3237
3374
  /**
3238
3375
  * IfNode#if_keyword_loc
3376
+ *
3377
+ * The location of the `if` keyword if present.
3378
+ *
3379
+ * bar if foo
3380
+ * ^^
3381
+ *
3382
+ * The `if_keyword_loc` field will be `nil` when the `IfNode` represents a ternary expression.
3239
3383
  */
3240
3384
  pm_location_t if_keyword_loc;
3241
3385
 
3242
3386
  /**
3243
3387
  * IfNode#predicate
3388
+ *
3389
+ * The node for the condition the `IfNode` is testing.
3390
+ *
3391
+ * if foo
3392
+ * ^^^
3393
+ * bar
3394
+ * end
3395
+ *
3396
+ * bar if foo
3397
+ * ^^^
3398
+ *
3399
+ * foo ? bar : baz
3400
+ * ^^^
3244
3401
  */
3245
3402
  struct pm_node *predicate;
3246
3403
 
3247
3404
  /**
3248
3405
  * IfNode#then_keyword_loc
3406
+ *
3407
+ * The location of the `then` keyword (if present) or the `?` in a ternary expression, `nil` otherwise.
3408
+ *
3409
+ * if foo then bar end
3410
+ * ^^^^
3411
+ *
3412
+ * a ? b : c
3413
+ * ^
3249
3414
  */
3250
3415
  pm_location_t then_keyword_loc;
3251
3416
 
3252
3417
  /**
3253
3418
  * IfNode#statements
3419
+ *
3420
+ * Represents the body of statements that will be executed when the predicate is evaluated as truthy. Will be `nil` when no body is provided.
3421
+ *
3422
+ * if foo
3423
+ * bar
3424
+ * ^^^
3425
+ * baz
3426
+ * ^^^
3427
+ * end
3254
3428
  */
3255
3429
  struct pm_statements_node *statements;
3256
3430
 
3257
3431
  /**
3258
3432
  * IfNode#consequent
3433
+ *
3434
+ * Represents an `ElseNode` or an `IfNode` when there is an `else` or an `elsif` in the `if` statement.
3435
+ *
3436
+ * if foo
3437
+ * bar
3438
+ * elsif baz
3439
+ * ^^^^^^^^^
3440
+ * qux
3441
+ * ^^^
3442
+ * end
3443
+ * ^^^
3444
+ *
3445
+ * if foo then bar else baz end
3446
+ * ^^^^^^^^^^^^
3259
3447
  */
3260
3448
  struct pm_node *consequent;
3261
3449
 
3262
3450
  /**
3263
3451
  * IfNode#end_keyword_loc
3452
+ *
3453
+ * The location of the `end` keyword if present, `nil` otherwise.
3454
+ *
3455
+ * if foo
3456
+ * bar
3457
+ * end
3458
+ * ^^^
3264
3459
  */
3265
3460
  pm_location_t end_keyword_loc;
3266
3461
  } pm_if_node_t;
@@ -3737,8 +3932,7 @@ typedef struct pm_instance_variable_write_node {
3737
3932
  /**
3738
3933
  * InstanceVariableWriteNode#value
3739
3934
  *
3740
- * The value to assign to the instance variable. Can be any node that
3741
- * represents a non-void expression.
3935
+ * The value to write to the instance variable. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
3742
3936
  *
3743
3937
  * @foo = :bar
3744
3938
  * ^^^^
@@ -4242,26 +4436,62 @@ typedef struct pm_local_variable_write_node {
4242
4436
 
4243
4437
  /**
4244
4438
  * LocalVariableWriteNode#name
4439
+ *
4440
+ * The name of the local variable, which is an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
4441
+ *
4442
+ * foo = :bar # name `:foo`
4443
+ *
4444
+ * abc = 123 # name `:abc`
4245
4445
  */
4246
4446
  pm_constant_id_t name;
4247
4447
 
4248
4448
  /**
4249
4449
  * LocalVariableWriteNode#depth
4450
+ *
4451
+ * The number of semantic scopes we have to traverse to find the declaration of this variable.
4452
+ *
4453
+ * foo = 1 # depth 0
4454
+ *
4455
+ * tap { foo = 1 } # depth 1
4456
+ *
4457
+ * The specific rules for calculating the depth may differ from individual Ruby implementations, as they are not specified by the language. For more information, see [the Prism documentation](https://github.com/ruby/prism/blob/main/docs/local_variable_depth.md).
4250
4458
  */
4251
4459
  uint32_t depth;
4252
4460
 
4253
4461
  /**
4254
4462
  * LocalVariableWriteNode#name_loc
4463
+ *
4464
+ * The location of the variable name.
4465
+ *
4466
+ * foo = :bar
4467
+ * ^^^
4255
4468
  */
4256
4469
  pm_location_t name_loc;
4257
4470
 
4258
4471
  /**
4259
4472
  * LocalVariableWriteNode#value
4473
+ *
4474
+ * The value to write to the local variable. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
4475
+ *
4476
+ * foo = :bar
4477
+ * ^^^^
4478
+ *
4479
+ * abc = 1234
4480
+ * ^^^^
4481
+ *
4482
+ * Note that since the name of a local variable is known before the value is parsed, it is valid for a local variable to appear within the value of its own write.
4483
+ *
4484
+ * foo = foo
4260
4485
  */
4261
4486
  struct pm_node *value;
4262
4487
 
4263
4488
  /**
4264
4489
  * LocalVariableWriteNode#operator_loc
4490
+ *
4491
+ * The location of the `=` operator.
4492
+ *
4493
+ * x = :y
4494
+ * ^
4265
4495
  */
4266
4496
  pm_location_t operator_loc;
4267
4497
  } pm_local_variable_write_node_t;
@@ -5350,6 +5580,8 @@ typedef struct pm_source_file_node {
5350
5580
 
5351
5581
  /**
5352
5582
  * SourceFileNode#filepath
5583
+ *
5584
+ * Represents the file path being parsed. This corresponds directly to the `filepath` option given to the various `Prism::parse*` APIs.
5353
5585
  */
5354
5586
  pm_string_t filepath;
5355
5587
  } pm_source_file_node_t;
@@ -5562,31 +5794,66 @@ typedef struct pm_unless_node {
5562
5794
 
5563
5795
  /**
5564
5796
  * UnlessNode#keyword_loc
5797
+ *
5798
+ * The location of the `unless` keyword.
5799
+ *
5800
+ * unless cond then bar end
5801
+ * ^^^^^^
5802
+ *
5803
+ * bar unless cond
5804
+ * ^^^^^^
5565
5805
  */
5566
5806
  pm_location_t keyword_loc;
5567
5807
 
5568
5808
  /**
5569
5809
  * UnlessNode#predicate
5810
+ *
5811
+ * The condition to be evaluated for the unless expression. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
5812
+ *
5813
+ * unless cond then bar end
5814
+ * ^^^^
5815
+ *
5816
+ * bar unless cond
5817
+ * ^^^^
5570
5818
  */
5571
5819
  struct pm_node *predicate;
5572
5820
 
5573
5821
  /**
5574
5822
  * UnlessNode#then_keyword_loc
5823
+ *
5824
+ * The location of the `then` keyword, if present.
5825
+ * unless cond then bar end ^^^^
5575
5826
  */
5576
5827
  pm_location_t then_keyword_loc;
5577
5828
 
5578
5829
  /**
5579
5830
  * UnlessNode#statements
5831
+ *
5832
+ * The body of statements that will executed if the unless condition is
5833
+ * falsey. Will be `nil` if no body is provided.
5834
+ *
5835
+ * unless cond then bar end
5836
+ * ^^^
5580
5837
  */
5581
5838
  struct pm_statements_node *statements;
5582
5839
 
5583
5840
  /**
5584
5841
  * UnlessNode#consequent
5842
+ *
5843
+ * The else clause of the unless expression, if present.
5844
+ *
5845
+ * unless cond then bar else baz end
5846
+ * ^^^^^^^^
5585
5847
  */
5586
5848
  struct pm_else_node *consequent;
5587
5849
 
5588
5850
  /**
5589
5851
  * UnlessNode#end_keyword_loc
5852
+ *
5853
+ * The location of the `end` keyword, if present.
5854
+ *
5855
+ * unless cond then bar end
5856
+ * ^^^
5590
5857
  */
5591
5858
  pm_location_t end_keyword_loc;
5592
5859
  } pm_unless_node_t;
@@ -163,6 +163,8 @@ typedef enum {
163
163
  PM_ERR_INVALID_CHARACTER,
164
164
  PM_ERR_INVALID_ENCODING_MAGIC_COMMENT,
165
165
  PM_ERR_INVALID_FLOAT_EXPONENT,
166
+ PM_ERR_INVALID_LOCAL_VARIABLE_READ,
167
+ PM_ERR_INVALID_LOCAL_VARIABLE_WRITE,
166
168
  PM_ERR_INVALID_MULTIBYTE_CHAR,
167
169
  PM_ERR_INVALID_MULTIBYTE_CHARACTER,
168
170
  PM_ERR_INVALID_MULTIBYTE_ESCAPE,
@@ -235,6 +237,7 @@ typedef enum {
235
237
  PM_ERR_PATTERN_HASH_KEY,
236
238
  PM_ERR_PATTERN_HASH_KEY_DUPLICATE,
237
239
  PM_ERR_PATTERN_HASH_KEY_LABEL,
240
+ PM_ERR_PATTERN_HASH_KEY_LOCALS,
238
241
  PM_ERR_PATTERN_IDENT_AFTER_HROCKET,
239
242
  PM_ERR_PATTERN_LABEL_AFTER_COMMA,
240
243
  PM_ERR_PATTERN_REST,
@@ -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 26
17
+ #define PRISM_VERSION_MINOR 27
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.26.0"
27
+ #define PRISM_VERSION "0.27.0"
28
28
 
29
29
  #endif
data/lib/prism/ffi.rb CHANGED
@@ -350,7 +350,7 @@ module Prism
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
- ParseResult.new([node, tokens], comments, magic_comments, data_loc, errors, warnings, source)
353
+ ParseLexResult.new([node, tokens], comments, magic_comments, data_loc, errors, warnings, source)
354
354
  end
355
355
  end
356
356
 
@@ -10,6 +10,23 @@ module Prism
10
10
  # generally lines up. However, there are a few cases that require special
11
11
  # handling.
12
12
  class LexCompat # :nodoc:
13
+ # A result class specialized for holding tokens produced by the lexer.
14
+ class Result < Prism::Result
15
+ # The list of tokens that were produced by the lexer.
16
+ attr_reader :value
17
+
18
+ # Create a new lex compat result object with the given values.
19
+ def initialize(value, comments, magic_comments, data_loc, errors, warnings, source)
20
+ @value = value
21
+ super(comments, magic_comments, data_loc, errors, warnings, source)
22
+ end
23
+
24
+ # Implement the hash pattern matching interface for Result.
25
+ def deconstruct_keys(keys)
26
+ super.merge!(value: value)
27
+ end
28
+ end
29
+
13
30
  # This is a mapping of prism token types to Ripper token types. This is a
14
31
  # many-to-one mapping because we split up our token types, whereas Ripper
15
32
  # tends to group them.
@@ -844,7 +861,7 @@ module Prism
844
861
  # We sort by location to compare against Ripper's output
845
862
  tokens.sort_by!(&:location)
846
863
 
847
- ParseResult.new(tokens, result.comments, result.magic_comments, result.data_loc, result.errors, result.warnings, Source.new(source))
864
+ Result.new(tokens, result.comments, result.magic_comments, result.data_loc, result.errors, result.warnings, Source.new(source))
848
865
  end
849
866
  end
850
867