yarp 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/ext/yarp/extension.c CHANGED
@@ -66,7 +66,7 @@ dump_input(yp_string_t *input, const char *filepath) {
66
66
  yp_node_t *node = yp_parse(&parser);
67
67
  yp_serialize(&parser, node, &buffer);
68
68
 
69
- VALUE result = rb_str_new(buffer.value, buffer.length);
69
+ VALUE result = rb_str_new(yp_buffer_value(&buffer), yp_buffer_length(&buffer));
70
70
  yp_node_destroy(&parser, node);
71
71
  yp_buffer_free(&buffer);
72
72
  yp_parser_free(&parser);
@@ -483,7 +483,7 @@ parse_serialize_file_metadata(VALUE self, VALUE filepath, VALUE metadata) {
483
483
  if (!yp_string_mapped_init(&input, checked)) return Qnil;
484
484
 
485
485
  yp_parse_serialize(yp_string_source(&input), yp_string_length(&input), &buffer, check_string(metadata));
486
- VALUE result = rb_str_new(buffer.value, buffer.length);
486
+ VALUE result = rb_str_new(yp_buffer_value(&buffer), yp_buffer_length(&buffer));
487
487
 
488
488
  yp_buffer_free(&buffer);
489
489
  return result;
data/ext/yarp/extension.h CHANGED
@@ -5,7 +5,7 @@
5
5
  #include <ruby/encoding.h>
6
6
  #include "yarp.h"
7
7
 
8
- #define EXPECTED_YARP_VERSION "0.7.0"
8
+ #define EXPECTED_YARP_VERSION "0.8.0"
9
9
 
10
10
  VALUE yp_source_new(yp_parser_t *parser);
11
11
  VALUE yp_token_new(yp_parser_t *parser, yp_token_t *token, rb_encoding *encoding, VALUE source);
data/include/yarp/ast.h CHANGED
@@ -217,131 +217,116 @@ enum yp_node_type {
217
217
  YP_NODE_ALIAS_NODE = 1,
218
218
  YP_NODE_ALTERNATION_PATTERN_NODE = 2,
219
219
  YP_NODE_AND_NODE = 3,
220
- YP_NODE_ARGUMENTS_NODE = 4,
221
- YP_NODE_ARRAY_NODE = 5,
222
- YP_NODE_ARRAY_PATTERN_NODE = 6,
223
- YP_NODE_ASSOC_NODE = 7,
224
- YP_NODE_ASSOC_SPLAT_NODE = 8,
225
- YP_NODE_BACK_REFERENCE_READ_NODE = 9,
226
- YP_NODE_BEGIN_NODE = 10,
227
- YP_NODE_BLOCK_ARGUMENT_NODE = 11,
228
- YP_NODE_BLOCK_NODE = 12,
229
- YP_NODE_BLOCK_PARAMETER_NODE = 13,
230
- YP_NODE_BLOCK_PARAMETERS_NODE = 14,
231
- YP_NODE_BREAK_NODE = 15,
232
- YP_NODE_CALL_NODE = 16,
233
- YP_NODE_CALL_OPERATOR_AND_WRITE_NODE = 17,
234
- YP_NODE_CALL_OPERATOR_OR_WRITE_NODE = 18,
235
- YP_NODE_CALL_OPERATOR_WRITE_NODE = 19,
236
- YP_NODE_CAPTURE_PATTERN_NODE = 20,
237
- YP_NODE_CASE_NODE = 21,
238
- YP_NODE_CLASS_NODE = 22,
239
- YP_NODE_CLASS_VARIABLE_OPERATOR_AND_WRITE_NODE = 23,
240
- YP_NODE_CLASS_VARIABLE_OPERATOR_OR_WRITE_NODE = 24,
241
- YP_NODE_CLASS_VARIABLE_OPERATOR_WRITE_NODE = 25,
242
- YP_NODE_CLASS_VARIABLE_READ_NODE = 26,
243
- YP_NODE_CLASS_VARIABLE_WRITE_NODE = 27,
244
- YP_NODE_CONSTANT_OPERATOR_AND_WRITE_NODE = 28,
245
- YP_NODE_CONSTANT_OPERATOR_OR_WRITE_NODE = 29,
246
- YP_NODE_CONSTANT_OPERATOR_WRITE_NODE = 30,
247
- YP_NODE_CONSTANT_PATH_NODE = 31,
248
- YP_NODE_CONSTANT_PATH_OPERATOR_AND_WRITE_NODE = 32,
249
- YP_NODE_CONSTANT_PATH_OPERATOR_OR_WRITE_NODE = 33,
250
- YP_NODE_CONSTANT_PATH_OPERATOR_WRITE_NODE = 34,
251
- YP_NODE_CONSTANT_PATH_WRITE_NODE = 35,
252
- YP_NODE_CONSTANT_READ_NODE = 36,
253
- YP_NODE_CONSTANT_WRITE_NODE = 37,
254
- YP_NODE_DEF_NODE = 38,
255
- YP_NODE_DEFINED_NODE = 39,
256
- YP_NODE_ELSE_NODE = 40,
257
- YP_NODE_EMBEDDED_STATEMENTS_NODE = 41,
258
- YP_NODE_EMBEDDED_VARIABLE_NODE = 42,
259
- YP_NODE_ENSURE_NODE = 43,
260
- YP_NODE_FALSE_NODE = 44,
261
- YP_NODE_FIND_PATTERN_NODE = 45,
262
- YP_NODE_FLIP_FLOP_NODE = 46,
263
- YP_NODE_FLOAT_NODE = 47,
264
- YP_NODE_FOR_NODE = 48,
265
- YP_NODE_FORWARDING_ARGUMENTS_NODE = 49,
266
- YP_NODE_FORWARDING_PARAMETER_NODE = 50,
267
- YP_NODE_FORWARDING_SUPER_NODE = 51,
268
- YP_NODE_GLOBAL_VARIABLE_OPERATOR_AND_WRITE_NODE = 52,
269
- YP_NODE_GLOBAL_VARIABLE_OPERATOR_OR_WRITE_NODE = 53,
270
- YP_NODE_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE = 54,
271
- YP_NODE_GLOBAL_VARIABLE_READ_NODE = 55,
272
- YP_NODE_GLOBAL_VARIABLE_WRITE_NODE = 56,
273
- YP_NODE_HASH_NODE = 57,
274
- YP_NODE_HASH_PATTERN_NODE = 58,
275
- YP_NODE_IF_NODE = 59,
276
- YP_NODE_IMAGINARY_NODE = 60,
277
- YP_NODE_IN_NODE = 61,
278
- YP_NODE_INSTANCE_VARIABLE_OPERATOR_AND_WRITE_NODE = 62,
279
- YP_NODE_INSTANCE_VARIABLE_OPERATOR_OR_WRITE_NODE = 63,
280
- YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE = 64,
281
- YP_NODE_INSTANCE_VARIABLE_READ_NODE = 65,
282
- YP_NODE_INSTANCE_VARIABLE_WRITE_NODE = 66,
283
- YP_NODE_INTEGER_NODE = 67,
284
- YP_NODE_INTERPOLATED_REGULAR_EXPRESSION_NODE = 68,
285
- YP_NODE_INTERPOLATED_STRING_NODE = 69,
286
- YP_NODE_INTERPOLATED_SYMBOL_NODE = 70,
287
- YP_NODE_INTERPOLATED_X_STRING_NODE = 71,
288
- YP_NODE_KEYWORD_HASH_NODE = 72,
289
- YP_NODE_KEYWORD_PARAMETER_NODE = 73,
290
- YP_NODE_KEYWORD_REST_PARAMETER_NODE = 74,
291
- YP_NODE_LAMBDA_NODE = 75,
292
- YP_NODE_LOCAL_VARIABLE_OPERATOR_AND_WRITE_NODE = 76,
293
- YP_NODE_LOCAL_VARIABLE_OPERATOR_OR_WRITE_NODE = 77,
294
- YP_NODE_LOCAL_VARIABLE_OPERATOR_WRITE_NODE = 78,
295
- YP_NODE_LOCAL_VARIABLE_READ_NODE = 79,
296
- YP_NODE_LOCAL_VARIABLE_WRITE_NODE = 80,
297
- YP_NODE_MATCH_PREDICATE_NODE = 81,
298
- YP_NODE_MATCH_REQUIRED_NODE = 82,
299
- YP_NODE_MISSING_NODE = 83,
300
- YP_NODE_MODULE_NODE = 84,
301
- YP_NODE_MULTI_WRITE_NODE = 85,
302
- YP_NODE_NEXT_NODE = 86,
303
- YP_NODE_NIL_NODE = 87,
304
- YP_NODE_NO_KEYWORDS_PARAMETER_NODE = 88,
305
- YP_NODE_NUMBERED_REFERENCE_READ_NODE = 89,
306
- YP_NODE_OPTIONAL_PARAMETER_NODE = 90,
307
- YP_NODE_OR_NODE = 91,
308
- YP_NODE_PARAMETERS_NODE = 92,
309
- YP_NODE_PARENTHESES_NODE = 93,
310
- YP_NODE_PINNED_EXPRESSION_NODE = 94,
311
- YP_NODE_PINNED_VARIABLE_NODE = 95,
312
- YP_NODE_POST_EXECUTION_NODE = 96,
313
- YP_NODE_PRE_EXECUTION_NODE = 97,
314
- YP_NODE_PROGRAM_NODE = 98,
315
- YP_NODE_RANGE_NODE = 99,
316
- YP_NODE_RATIONAL_NODE = 100,
317
- YP_NODE_REDO_NODE = 101,
318
- YP_NODE_REGULAR_EXPRESSION_NODE = 102,
319
- YP_NODE_REQUIRED_DESTRUCTURED_PARAMETER_NODE = 103,
320
- YP_NODE_REQUIRED_PARAMETER_NODE = 104,
321
- YP_NODE_RESCUE_MODIFIER_NODE = 105,
322
- YP_NODE_RESCUE_NODE = 106,
323
- YP_NODE_REST_PARAMETER_NODE = 107,
324
- YP_NODE_RETRY_NODE = 108,
325
- YP_NODE_RETURN_NODE = 109,
326
- YP_NODE_SELF_NODE = 110,
327
- YP_NODE_SINGLETON_CLASS_NODE = 111,
328
- YP_NODE_SOURCE_ENCODING_NODE = 112,
329
- YP_NODE_SOURCE_FILE_NODE = 113,
330
- YP_NODE_SOURCE_LINE_NODE = 114,
331
- YP_NODE_SPLAT_NODE = 115,
332
- YP_NODE_STATEMENTS_NODE = 116,
333
- YP_NODE_STRING_CONCAT_NODE = 117,
334
- YP_NODE_STRING_NODE = 118,
335
- YP_NODE_SUPER_NODE = 119,
336
- YP_NODE_SYMBOL_NODE = 120,
337
- YP_NODE_TRUE_NODE = 121,
338
- YP_NODE_UNDEF_NODE = 122,
339
- YP_NODE_UNLESS_NODE = 123,
340
- YP_NODE_UNTIL_NODE = 124,
341
- YP_NODE_WHEN_NODE = 125,
342
- YP_NODE_WHILE_NODE = 126,
343
- YP_NODE_X_STRING_NODE = 127,
344
- YP_NODE_YIELD_NODE = 128,
220
+ YP_NODE_AND_WRITE_NODE = 4,
221
+ YP_NODE_ARGUMENTS_NODE = 5,
222
+ YP_NODE_ARRAY_NODE = 6,
223
+ YP_NODE_ARRAY_PATTERN_NODE = 7,
224
+ YP_NODE_ASSOC_NODE = 8,
225
+ YP_NODE_ASSOC_SPLAT_NODE = 9,
226
+ YP_NODE_BACK_REFERENCE_READ_NODE = 10,
227
+ YP_NODE_BEGIN_NODE = 11,
228
+ YP_NODE_BLOCK_ARGUMENT_NODE = 12,
229
+ YP_NODE_BLOCK_NODE = 13,
230
+ YP_NODE_BLOCK_PARAMETER_NODE = 14,
231
+ YP_NODE_BLOCK_PARAMETERS_NODE = 15,
232
+ YP_NODE_BREAK_NODE = 16,
233
+ YP_NODE_CALL_NODE = 17,
234
+ YP_NODE_CALL_OPERATOR_AND_WRITE_NODE = 18,
235
+ YP_NODE_CALL_OPERATOR_OR_WRITE_NODE = 19,
236
+ YP_NODE_CALL_OPERATOR_WRITE_NODE = 20,
237
+ YP_NODE_CAPTURE_PATTERN_NODE = 21,
238
+ YP_NODE_CASE_NODE = 22,
239
+ YP_NODE_CLASS_NODE = 23,
240
+ YP_NODE_CLASS_VARIABLE_READ_NODE = 24,
241
+ YP_NODE_CLASS_VARIABLE_WRITE_NODE = 25,
242
+ YP_NODE_CONSTANT_PATH_NODE = 26,
243
+ YP_NODE_CONSTANT_PATH_WRITE_NODE = 27,
244
+ YP_NODE_CONSTANT_READ_NODE = 28,
245
+ YP_NODE_CONSTANT_WRITE_NODE = 29,
246
+ YP_NODE_DEF_NODE = 30,
247
+ YP_NODE_DEFINED_NODE = 31,
248
+ YP_NODE_ELSE_NODE = 32,
249
+ YP_NODE_EMBEDDED_STATEMENTS_NODE = 33,
250
+ YP_NODE_EMBEDDED_VARIABLE_NODE = 34,
251
+ YP_NODE_ENSURE_NODE = 35,
252
+ YP_NODE_FALSE_NODE = 36,
253
+ YP_NODE_FIND_PATTERN_NODE = 37,
254
+ YP_NODE_FLIP_FLOP_NODE = 38,
255
+ YP_NODE_FLOAT_NODE = 39,
256
+ YP_NODE_FOR_NODE = 40,
257
+ YP_NODE_FORWARDING_ARGUMENTS_NODE = 41,
258
+ YP_NODE_FORWARDING_PARAMETER_NODE = 42,
259
+ YP_NODE_FORWARDING_SUPER_NODE = 43,
260
+ YP_NODE_GLOBAL_VARIABLE_READ_NODE = 44,
261
+ YP_NODE_GLOBAL_VARIABLE_WRITE_NODE = 45,
262
+ YP_NODE_HASH_NODE = 46,
263
+ YP_NODE_HASH_PATTERN_NODE = 47,
264
+ YP_NODE_IF_NODE = 48,
265
+ YP_NODE_IMAGINARY_NODE = 49,
266
+ YP_NODE_IN_NODE = 50,
267
+ YP_NODE_INSTANCE_VARIABLE_READ_NODE = 51,
268
+ YP_NODE_INSTANCE_VARIABLE_WRITE_NODE = 52,
269
+ YP_NODE_INTEGER_NODE = 53,
270
+ YP_NODE_INTERPOLATED_REGULAR_EXPRESSION_NODE = 54,
271
+ YP_NODE_INTERPOLATED_STRING_NODE = 55,
272
+ YP_NODE_INTERPOLATED_SYMBOL_NODE = 56,
273
+ YP_NODE_INTERPOLATED_X_STRING_NODE = 57,
274
+ YP_NODE_KEYWORD_HASH_NODE = 58,
275
+ YP_NODE_KEYWORD_PARAMETER_NODE = 59,
276
+ YP_NODE_KEYWORD_REST_PARAMETER_NODE = 60,
277
+ YP_NODE_LAMBDA_NODE = 61,
278
+ YP_NODE_LOCAL_VARIABLE_READ_NODE = 62,
279
+ YP_NODE_LOCAL_VARIABLE_WRITE_NODE = 63,
280
+ YP_NODE_MATCH_PREDICATE_NODE = 64,
281
+ YP_NODE_MATCH_REQUIRED_NODE = 65,
282
+ YP_NODE_MISSING_NODE = 66,
283
+ YP_NODE_MODULE_NODE = 67,
284
+ YP_NODE_MULTI_WRITE_NODE = 68,
285
+ YP_NODE_NEXT_NODE = 69,
286
+ YP_NODE_NIL_NODE = 70,
287
+ YP_NODE_NO_KEYWORDS_PARAMETER_NODE = 71,
288
+ YP_NODE_NUMBERED_REFERENCE_READ_NODE = 72,
289
+ YP_NODE_OPERATOR_WRITE_NODE = 73,
290
+ YP_NODE_OPTIONAL_PARAMETER_NODE = 74,
291
+ YP_NODE_OR_NODE = 75,
292
+ YP_NODE_OR_WRITE_NODE = 76,
293
+ YP_NODE_PARAMETERS_NODE = 77,
294
+ YP_NODE_PARENTHESES_NODE = 78,
295
+ YP_NODE_PINNED_EXPRESSION_NODE = 79,
296
+ YP_NODE_PINNED_VARIABLE_NODE = 80,
297
+ YP_NODE_POST_EXECUTION_NODE = 81,
298
+ YP_NODE_PRE_EXECUTION_NODE = 82,
299
+ YP_NODE_PROGRAM_NODE = 83,
300
+ YP_NODE_RANGE_NODE = 84,
301
+ YP_NODE_RATIONAL_NODE = 85,
302
+ YP_NODE_REDO_NODE = 86,
303
+ YP_NODE_REGULAR_EXPRESSION_NODE = 87,
304
+ YP_NODE_REQUIRED_DESTRUCTURED_PARAMETER_NODE = 88,
305
+ YP_NODE_REQUIRED_PARAMETER_NODE = 89,
306
+ YP_NODE_RESCUE_MODIFIER_NODE = 90,
307
+ YP_NODE_RESCUE_NODE = 91,
308
+ YP_NODE_REST_PARAMETER_NODE = 92,
309
+ YP_NODE_RETRY_NODE = 93,
310
+ YP_NODE_RETURN_NODE = 94,
311
+ YP_NODE_SELF_NODE = 95,
312
+ YP_NODE_SINGLETON_CLASS_NODE = 96,
313
+ YP_NODE_SOURCE_ENCODING_NODE = 97,
314
+ YP_NODE_SOURCE_FILE_NODE = 98,
315
+ YP_NODE_SOURCE_LINE_NODE = 99,
316
+ YP_NODE_SPLAT_NODE = 100,
317
+ YP_NODE_STATEMENTS_NODE = 101,
318
+ YP_NODE_STRING_CONCAT_NODE = 102,
319
+ YP_NODE_STRING_NODE = 103,
320
+ YP_NODE_SUPER_NODE = 104,
321
+ YP_NODE_SYMBOL_NODE = 105,
322
+ YP_NODE_TRUE_NODE = 106,
323
+ YP_NODE_UNDEF_NODE = 107,
324
+ YP_NODE_UNLESS_NODE = 108,
325
+ YP_NODE_UNTIL_NODE = 109,
326
+ YP_NODE_WHEN_NODE = 110,
327
+ YP_NODE_WHILE_NODE = 111,
328
+ YP_NODE_X_STRING_NODE = 112,
329
+ YP_NODE_YIELD_NODE = 113,
345
330
  };
346
331
 
347
332
  typedef uint16_t yp_node_type_t;
@@ -394,6 +379,14 @@ typedef struct yp_and_node {
394
379
  yp_location_t operator_loc;
395
380
  } yp_and_node_t;
396
381
 
382
+ // AndWriteNode
383
+ typedef struct yp_and_write_node {
384
+ yp_node_t base;
385
+ struct yp_node *target;
386
+ struct yp_node *value;
387
+ yp_location_t operator_loc;
388
+ } yp_and_write_node_t;
389
+
397
390
  // ArgumentsNode
398
391
  typedef struct yp_arguments_node {
399
392
  yp_node_t base;
@@ -462,7 +455,7 @@ typedef struct yp_block_node {
462
455
  yp_node_t base;
463
456
  yp_constant_id_list_t locals;
464
457
  struct yp_block_parameters_node *parameters;
465
- struct yp_node *statements;
458
+ struct yp_node *body;
466
459
  yp_location_t opening_loc;
467
460
  yp_location_t closing_loc;
468
461
  } yp_block_node_t;
@@ -554,35 +547,10 @@ typedef struct yp_class_node {
554
547
  struct yp_node *constant_path;
555
548
  yp_location_t inheritance_operator_loc;
556
549
  struct yp_node *superclass;
557
- struct yp_node *statements;
550
+ struct yp_node *body;
558
551
  yp_location_t end_keyword_loc;
559
552
  } yp_class_node_t;
560
553
 
561
- // ClassVariableOperatorAndWriteNode
562
- typedef struct yp_class_variable_operator_and_write_node {
563
- yp_node_t base;
564
- yp_location_t name_loc;
565
- yp_location_t operator_loc;
566
- struct yp_node *value;
567
- } yp_class_variable_operator_and_write_node_t;
568
-
569
- // ClassVariableOperatorOrWriteNode
570
- typedef struct yp_class_variable_operator_or_write_node {
571
- yp_node_t base;
572
- yp_location_t name_loc;
573
- yp_location_t operator_loc;
574
- struct yp_node *value;
575
- } yp_class_variable_operator_or_write_node_t;
576
-
577
- // ClassVariableOperatorWriteNode
578
- typedef struct yp_class_variable_operator_write_node {
579
- yp_node_t base;
580
- yp_location_t name_loc;
581
- yp_location_t operator_loc;
582
- struct yp_node *value;
583
- yp_constant_id_t operator;
584
- } yp_class_variable_operator_write_node_t;
585
-
586
554
  // ClassVariableReadNode
587
555
  typedef struct yp_class_variable_read_node {
588
556
  yp_node_t base;
@@ -596,31 +564,6 @@ typedef struct yp_class_variable_write_node {
596
564
  yp_location_t operator_loc;
597
565
  } yp_class_variable_write_node_t;
598
566
 
599
- // ConstantOperatorAndWriteNode
600
- typedef struct yp_constant_operator_and_write_node {
601
- yp_node_t base;
602
- yp_location_t name_loc;
603
- yp_location_t operator_loc;
604
- struct yp_node *value;
605
- } yp_constant_operator_and_write_node_t;
606
-
607
- // ConstantOperatorOrWriteNode
608
- typedef struct yp_constant_operator_or_write_node {
609
- yp_node_t base;
610
- yp_location_t name_loc;
611
- yp_location_t operator_loc;
612
- struct yp_node *value;
613
- } yp_constant_operator_or_write_node_t;
614
-
615
- // ConstantOperatorWriteNode
616
- typedef struct yp_constant_operator_write_node {
617
- yp_node_t base;
618
- yp_location_t name_loc;
619
- yp_location_t operator_loc;
620
- struct yp_node *value;
621
- yp_constant_id_t operator;
622
- } yp_constant_operator_write_node_t;
623
-
624
567
  // ConstantPathNode
625
568
  typedef struct yp_constant_path_node {
626
569
  yp_node_t base;
@@ -629,31 +572,6 @@ typedef struct yp_constant_path_node {
629
572
  yp_location_t delimiter_loc;
630
573
  } yp_constant_path_node_t;
631
574
 
632
- // ConstantPathOperatorAndWriteNode
633
- typedef struct yp_constant_path_operator_and_write_node {
634
- yp_node_t base;
635
- struct yp_constant_path_node *target;
636
- yp_location_t operator_loc;
637
- struct yp_node *value;
638
- } yp_constant_path_operator_and_write_node_t;
639
-
640
- // ConstantPathOperatorOrWriteNode
641
- typedef struct yp_constant_path_operator_or_write_node {
642
- yp_node_t base;
643
- struct yp_constant_path_node *target;
644
- yp_location_t operator_loc;
645
- struct yp_node *value;
646
- } yp_constant_path_operator_or_write_node_t;
647
-
648
- // ConstantPathOperatorWriteNode
649
- typedef struct yp_constant_path_operator_write_node {
650
- yp_node_t base;
651
- struct yp_constant_path_node *target;
652
- yp_location_t operator_loc;
653
- struct yp_node *value;
654
- yp_constant_id_t operator;
655
- } yp_constant_path_operator_write_node_t;
656
-
657
575
  // ConstantPathWriteNode
658
576
  typedef struct yp_constant_path_write_node {
659
577
  yp_node_t base;
@@ -681,7 +599,7 @@ typedef struct yp_def_node {
681
599
  yp_location_t name_loc;
682
600
  struct yp_node *receiver;
683
601
  struct yp_parameters_node *parameters;
684
- struct yp_node *statements;
602
+ struct yp_node *body;
685
603
  yp_constant_id_list_t locals;
686
604
  yp_location_t def_keyword_loc;
687
605
  yp_location_t operator_loc;
@@ -788,31 +706,6 @@ typedef struct yp_forwarding_super_node {
788
706
  struct yp_block_node *block;
789
707
  } yp_forwarding_super_node_t;
790
708
 
791
- // GlobalVariableOperatorAndWriteNode
792
- typedef struct yp_global_variable_operator_and_write_node {
793
- yp_node_t base;
794
- yp_location_t name_loc;
795
- yp_location_t operator_loc;
796
- struct yp_node *value;
797
- } yp_global_variable_operator_and_write_node_t;
798
-
799
- // GlobalVariableOperatorOrWriteNode
800
- typedef struct yp_global_variable_operator_or_write_node {
801
- yp_node_t base;
802
- yp_location_t name_loc;
803
- yp_location_t operator_loc;
804
- struct yp_node *value;
805
- } yp_global_variable_operator_or_write_node_t;
806
-
807
- // GlobalVariableOperatorWriteNode
808
- typedef struct yp_global_variable_operator_write_node {
809
- yp_node_t base;
810
- yp_location_t name_loc;
811
- yp_location_t operator_loc;
812
- struct yp_node *value;
813
- yp_constant_id_t operator;
814
- } yp_global_variable_operator_write_node_t;
815
-
816
709
  // GlobalVariableReadNode
817
710
  typedef struct yp_global_variable_read_node {
818
711
  yp_node_t base;
@@ -869,31 +762,6 @@ typedef struct yp_in_node {
869
762
  yp_location_t then_loc;
870
763
  } yp_in_node_t;
871
764
 
872
- // InstanceVariableOperatorAndWriteNode
873
- typedef struct yp_instance_variable_operator_and_write_node {
874
- yp_node_t base;
875
- yp_location_t name_loc;
876
- yp_location_t operator_loc;
877
- struct yp_node *value;
878
- } yp_instance_variable_operator_and_write_node_t;
879
-
880
- // InstanceVariableOperatorOrWriteNode
881
- typedef struct yp_instance_variable_operator_or_write_node {
882
- yp_node_t base;
883
- yp_location_t name_loc;
884
- yp_location_t operator_loc;
885
- struct yp_node *value;
886
- } yp_instance_variable_operator_or_write_node_t;
887
-
888
- // InstanceVariableOperatorWriteNode
889
- typedef struct yp_instance_variable_operator_write_node {
890
- yp_node_t base;
891
- yp_location_t name_loc;
892
- yp_location_t operator_loc;
893
- struct yp_node *value;
894
- yp_constant_id_t operator;
895
- } yp_instance_variable_operator_write_node_t;
896
-
897
765
  // InstanceVariableReadNode
898
766
  typedef struct yp_instance_variable_read_node {
899
767
  yp_node_t base;
@@ -970,37 +838,9 @@ typedef struct yp_lambda_node {
970
838
  yp_constant_id_list_t locals;
971
839
  yp_location_t opening_loc;
972
840
  struct yp_block_parameters_node *parameters;
973
- struct yp_node *statements;
841
+ struct yp_node *body;
974
842
  } yp_lambda_node_t;
975
843
 
976
- // LocalVariableOperatorAndWriteNode
977
- typedef struct yp_local_variable_operator_and_write_node {
978
- yp_node_t base;
979
- yp_location_t name_loc;
980
- yp_location_t operator_loc;
981
- struct yp_node *value;
982
- yp_constant_id_t constant_id;
983
- } yp_local_variable_operator_and_write_node_t;
984
-
985
- // LocalVariableOperatorOrWriteNode
986
- typedef struct yp_local_variable_operator_or_write_node {
987
- yp_node_t base;
988
- yp_location_t name_loc;
989
- yp_location_t operator_loc;
990
- struct yp_node *value;
991
- yp_constant_id_t constant_id;
992
- } yp_local_variable_operator_or_write_node_t;
993
-
994
- // LocalVariableOperatorWriteNode
995
- typedef struct yp_local_variable_operator_write_node {
996
- yp_node_t base;
997
- yp_location_t name_loc;
998
- yp_location_t operator_loc;
999
- struct yp_node *value;
1000
- yp_constant_id_t constant_id;
1001
- yp_constant_id_t operator_id;
1002
- } yp_local_variable_operator_write_node_t;
1003
-
1004
844
  // LocalVariableReadNode
1005
845
  typedef struct yp_local_variable_read_node {
1006
846
  yp_node_t base;
@@ -1045,7 +885,7 @@ typedef struct yp_module_node {
1045
885
  yp_constant_id_list_t locals;
1046
886
  yp_location_t module_keyword_loc;
1047
887
  struct yp_node *constant_path;
1048
- struct yp_node *statements;
888
+ struct yp_node *body;
1049
889
  yp_location_t end_keyword_loc;
1050
890
  } yp_module_node_t;
1051
891
 
@@ -1083,6 +923,15 @@ typedef struct yp_numbered_reference_read_node {
1083
923
  yp_node_t base;
1084
924
  } yp_numbered_reference_read_node_t;
1085
925
 
926
+ // OperatorWriteNode
927
+ typedef struct yp_operator_write_node {
928
+ yp_node_t base;
929
+ struct yp_node *target;
930
+ yp_location_t operator_loc;
931
+ yp_constant_id_t operator;
932
+ struct yp_node *value;
933
+ } yp_operator_write_node_t;
934
+
1086
935
  // OptionalParameterNode
1087
936
  typedef struct yp_optional_parameter_node {
1088
937
  yp_node_t base;
@@ -1100,6 +949,14 @@ typedef struct yp_or_node {
1100
949
  yp_location_t operator_loc;
1101
950
  } yp_or_node_t;
1102
951
 
952
+ // OrWriteNode
953
+ typedef struct yp_or_write_node {
954
+ yp_node_t base;
955
+ struct yp_node *target;
956
+ struct yp_node *value;
957
+ yp_location_t operator_loc;
958
+ } yp_or_write_node_t;
959
+
1103
960
  // ParametersNode
1104
961
  typedef struct yp_parameters_node {
1105
962
  yp_node_t base;
@@ -1115,7 +972,7 @@ typedef struct yp_parameters_node {
1115
972
  // ParenthesesNode
1116
973
  typedef struct yp_parentheses_node {
1117
974
  yp_node_t base;
1118
- struct yp_node *statements;
975
+ struct yp_node *body;
1119
976
  yp_location_t opening_loc;
1120
977
  yp_location_t closing_loc;
1121
978
  } yp_parentheses_node_t;
@@ -1253,7 +1110,7 @@ typedef struct yp_singleton_class_node {
1253
1110
  yp_location_t class_keyword_loc;
1254
1111
  yp_location_t operator_loc;
1255
1112
  struct yp_node *expression;
1256
- struct yp_node *statements;
1113
+ struct yp_node *body;
1257
1114
  yp_location_t end_keyword_loc;
1258
1115
  } yp_singleton_class_node_t;
1259
1116
 
@@ -34,6 +34,11 @@
34
34
  # define inline __inline
35
35
  #endif
36
36
 
37
+ // Windows versions before 2015 use _snprintf
38
+ #if defined(_MSC_VER) && (_MSC_VER < 1900)
39
+ # define snprintf _snprintf
40
+ #endif
41
+
37
42
  int yp_strncasecmp(const char *string1, const char *string2, size_t length);
38
43
 
39
44
  #endif
@@ -31,7 +31,7 @@ typedef enum {
31
31
 
32
32
  // Unescape the contents of the given token into the given string using the
33
33
  // given unescape mode.
34
- YP_EXPORTED_FUNCTION void yp_unescape_manipulate_string(yp_parser_t *parser, const char *value, size_t length, yp_string_t *string, yp_unescape_type_t unescape_type, yp_list_t *error_list);
34
+ YP_EXPORTED_FUNCTION void yp_unescape_manipulate_string(yp_parser_t *parser, yp_string_t *string, yp_unescape_type_t unescape_type, yp_list_t *error_list);
35
35
 
36
36
  // Accepts a source string and a type of unescaping and returns the unescaped version.
37
37
  // The caller must yp_string_free(result); after calling this function.
@@ -12,16 +12,24 @@
12
12
  // A yp_buffer_t is a simple memory buffer that stores data in a contiguous
13
13
  // block of memory. It is used to store the serialized representation of a
14
14
  // YARP tree.
15
- // NOTE: keep in sync with YARP::LibRubyParser::Buffer in lib/yarp.rb
16
15
  typedef struct {
17
16
  char *value;
18
17
  size_t length;
19
18
  size_t capacity;
20
19
  } yp_buffer_t;
21
20
 
21
+ // Return the size of the yp_buffer_t struct.
22
+ YP_EXPORTED_FUNCTION size_t yp_buffer_sizeof(void);
23
+
22
24
  // Initialize a yp_buffer_t with its default values.
23
25
  YP_EXPORTED_FUNCTION bool yp_buffer_init(yp_buffer_t *buffer);
24
26
 
27
+ // Return the value of the buffer.
28
+ YP_EXPORTED_FUNCTION char * yp_buffer_value(yp_buffer_t *buffer);
29
+
30
+ // Return the length of the buffer.
31
+ YP_EXPORTED_FUNCTION size_t yp_buffer_length(yp_buffer_t *buffer);
32
+
25
33
  // Append the given amount of space as zeroes to the buffer.
26
34
  void yp_buffer_append_zeroes(yp_buffer_t *buffer, size_t length);
27
35
 
@@ -51,6 +51,9 @@ typedef struct {
51
51
  size_t capacity;
52
52
  } yp_constant_pool_t;
53
53
 
54
+ // Define an empty constant pool.
55
+ #define YP_CONSTANT_POOL_EMPTY ((yp_constant_pool_t) { .constants = NULL, .size = 0, .capacity = 0 })
56
+
54
57
  // Initialize a new constant pool with a given capacity.
55
58
  bool yp_constant_pool_init(yp_constant_pool_t *pool, size_t capacity);
56
59
 
@@ -15,9 +15,7 @@
15
15
  // int value;
16
16
  // } yp_int_node_t;
17
17
  //
18
- // yp_list_t list;
19
- // yp_list_init(&list);
20
- //
18
+ // yp_list_t list = YP_LIST_EMPTY;
21
19
  // yp_int_node_t *node = malloc(sizeof(yp_int_node_t));
22
20
  // node->value = 5;
23
21
  //
@@ -45,18 +43,20 @@ typedef struct yp_list_node {
45
43
  // This represents the overall linked list. It keeps a pointer to the head and
46
44
  // tail so that iteration is easy and pushing new nodes is easy.
47
45
  typedef struct {
46
+ size_t size;
48
47
  yp_list_node_t *head;
49
48
  yp_list_node_t *tail;
50
49
  } yp_list_t;
51
50
 
52
- // Initializes a new list.
53
- YP_EXPORTED_FUNCTION void yp_list_init(yp_list_t *list);
51
+ // This represents an empty list. It's used to initialize a stack-allocated list
52
+ // as opposed to a method call.
53
+ #define YP_LIST_EMPTY ((yp_list_t) { .size = 0, .head = NULL, .tail = NULL })
54
54
 
55
55
  // Returns true if the given list is empty.
56
56
  YP_EXPORTED_FUNCTION bool yp_list_empty_p(yp_list_t *list);
57
57
 
58
- // Returns the size of the list in O(n) time.
59
- YP_EXPORTED_FUNCTION uint32_t yp_list_size(yp_list_t *list);
58
+ // Returns the size of the list.
59
+ YP_EXPORTED_FUNCTION size_t yp_list_size(yp_list_t *list);
60
60
 
61
61
  // Append a node to the given list.
62
62
  void yp_list_append(yp_list_t *list, yp_list_node_t *node);
@@ -35,6 +35,10 @@ typedef struct {
35
35
  size_t column;
36
36
  } yp_line_column_t;
37
37
 
38
+ #define YP_NEWLINE_LIST_EMPTY ((yp_newline_list_t) { \
39
+ .start = NULL, .offsets = NULL, .size = 0, .capacity = 0, .last_offset = 0, .last_index = 0 \
40
+ })
41
+
38
42
  // Initialize a new newline list with the given capacity. Returns true if the
39
43
  // allocation of the offsets succeeds, otherwise returns false.
40
44
  bool yp_newline_list_init(yp_newline_list_t *list, const char *start, size_t capacity);
@@ -10,7 +10,7 @@
10
10
  typedef uint32_t yp_state_stack_t;
11
11
 
12
12
  // Initializes the state stack to an empty stack.
13
- void yp_state_stack_init(yp_state_stack_t *stack);
13
+ #define YP_STATE_STACK_EMPTY ((yp_state_stack_t) 0)
14
14
 
15
15
  // Pushes a value onto the stack.
16
16
  void yp_state_stack_push(yp_state_stack_t *stack, bool value);