prism 0.17.1 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -1
  3. data/Makefile +5 -5
  4. data/README.md +2 -2
  5. data/config.yml +26 -13
  6. data/docs/build_system.md +6 -6
  7. data/docs/building.md +1 -1
  8. data/docs/configuration.md +1 -0
  9. data/docs/encoding.md +68 -32
  10. data/docs/heredocs.md +1 -1
  11. data/docs/javascript.md +29 -1
  12. data/docs/ruby_api.md +14 -0
  13. data/ext/prism/api_node.c +74 -45
  14. data/ext/prism/extconf.rb +91 -127
  15. data/ext/prism/extension.c +1 -1
  16. data/ext/prism/extension.h +1 -1
  17. data/include/prism/ast.h +148 -133
  18. data/include/prism/diagnostic.h +27 -1
  19. data/include/prism/enc/pm_encoding.h +42 -1
  20. data/include/prism/parser.h +6 -0
  21. data/include/prism/version.h +3 -3
  22. data/lib/prism/compiler.rb +3 -3
  23. data/lib/prism/debug.rb +4 -0
  24. data/lib/prism/desugar_compiler.rb +1 -0
  25. data/lib/prism/dispatcher.rb +14 -14
  26. data/lib/prism/dot_visitor.rb +4334 -0
  27. data/lib/prism/dsl.rb +11 -11
  28. data/lib/prism/ffi.rb +3 -3
  29. data/lib/prism/mutation_compiler.rb +6 -6
  30. data/lib/prism/node.rb +182 -113
  31. data/lib/prism/node_ext.rb +61 -3
  32. data/lib/prism/parse_result.rb +46 -12
  33. data/lib/prism/serialize.rb +125 -131
  34. data/lib/prism/visitor.rb +3 -3
  35. data/lib/prism.rb +1 -0
  36. data/prism.gemspec +5 -1
  37. data/rbi/prism.rbi +83 -54
  38. data/sig/prism.rbs +47 -32
  39. data/src/diagnostic.c +61 -3
  40. data/src/enc/pm_big5.c +63 -0
  41. data/src/enc/pm_cp51932.c +57 -0
  42. data/src/enc/pm_euc_jp.c +10 -0
  43. data/src/enc/pm_gbk.c +5 -2
  44. data/src/enc/pm_tables.c +1478 -148
  45. data/src/node.c +33 -21
  46. data/src/prettyprint.c +1027 -925
  47. data/src/prism.c +925 -374
  48. data/src/regexp.c +12 -12
  49. data/src/serialize.c +36 -9
  50. metadata +6 -2
data/src/regexp.c CHANGED
@@ -116,18 +116,18 @@ pm_regexp_char_find(pm_regexp_parser_t *parser, uint8_t value) {
116
116
  * The properly track everything, we're going to build a little state machine.
117
117
  * It looks something like the following:
118
118
  *
119
- * ┌───────┐ ┌─────────┐ ────────────┐
120
- * ──── lbrace ───> start ──── digit ───> minimum
121
- * └───────┘ └─────────┘ <─── digit ─┘
122
- *
123
- * ┌───────┐ rbrace
124
- * comma <───── comma ┌──── comma ───────┘
125
- * └───────┘ V V
126
- * ┌─────────┐ ┌─────────┐
127
- * └── digit ──> maximum ── rbrace ──> │| final |│
128
- * └─────────┘ └─────────┘
129
- * ^
130
- * └─ digit ─┘
119
+ * +-------+ +---------+ ------------+
120
+ * ---- lbrace ---> | start | ---- digit ---> | minimum | |
121
+ * +-------+ +---------+ <--- digit -+
122
+ * | | |
123
+ * +-------+ | | rbrace
124
+ * | comma | <----- comma +---- comma -------+ |
125
+ * +-------+ V V
126
+ * | +---------+ +---------+
127
+ * +-- digit --> | maximum | -- rbrace --> || final ||
128
+ * +---------+ +---------+
129
+ * | ^
130
+ * +- digit -+
131
131
  *
132
132
  * Note that by the time we've hit this function, the lbrace has already been
133
133
  * consumed so we're in the start state.
data/src/serialize.c CHANGED
@@ -422,6 +422,26 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
422
422
  pm_serialize_location(parser, &((pm_capture_pattern_node_t *)node)->operator_loc, buffer);
423
423
  break;
424
424
  }
425
+ case PM_CASE_MATCH_NODE: {
426
+ if (((pm_case_match_node_t *)node)->predicate == NULL) {
427
+ pm_buffer_append_byte(buffer, 0);
428
+ } else {
429
+ pm_serialize_node(parser, (pm_node_t *)((pm_case_match_node_t *)node)->predicate, buffer);
430
+ }
431
+ uint32_t conditions_size = pm_sizet_to_u32(((pm_case_match_node_t *)node)->conditions.size);
432
+ pm_buffer_append_varint(buffer, conditions_size);
433
+ for (uint32_t index = 0; index < conditions_size; index++) {
434
+ pm_serialize_node(parser, (pm_node_t *) ((pm_case_match_node_t *)node)->conditions.nodes[index], buffer);
435
+ }
436
+ if (((pm_case_match_node_t *)node)->consequent == NULL) {
437
+ pm_buffer_append_byte(buffer, 0);
438
+ } else {
439
+ pm_serialize_node(parser, (pm_node_t *)((pm_case_match_node_t *)node)->consequent, buffer);
440
+ }
441
+ pm_serialize_location(parser, &((pm_case_match_node_t *)node)->case_keyword_loc, buffer);
442
+ pm_serialize_location(parser, &((pm_case_match_node_t *)node)->end_keyword_loc, buffer);
443
+ break;
444
+ }
425
445
  case PM_CASE_NODE: {
426
446
  if (((pm_case_node_t *)node)->predicate == NULL) {
427
447
  pm_buffer_append_byte(buffer, 0);
@@ -880,6 +900,12 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
880
900
  pm_serialize_location(parser, &((pm_if_node_t *)node)->if_keyword_loc, buffer);
881
901
  }
882
902
  pm_serialize_node(parser, (pm_node_t *)((pm_if_node_t *)node)->predicate, buffer);
903
+ if (((pm_if_node_t *)node)->then_keyword_loc.start == NULL) {
904
+ pm_buffer_append_byte(buffer, 0);
905
+ } else {
906
+ pm_buffer_append_byte(buffer, 1);
907
+ pm_serialize_location(parser, &((pm_if_node_t *)node)->then_keyword_loc, buffer);
908
+ }
883
909
  if (((pm_if_node_t *)node)->statements == NULL) {
884
910
  pm_buffer_append_byte(buffer, 0);
885
911
  } else {
@@ -1228,10 +1254,10 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1228
1254
  }
1229
1255
  case PM_MATCH_WRITE_NODE: {
1230
1256
  pm_serialize_node(parser, (pm_node_t *)((pm_match_write_node_t *)node)->call, buffer);
1231
- uint32_t locals_size = pm_sizet_to_u32(((pm_match_write_node_t *)node)->locals.size);
1232
- pm_buffer_append_varint(buffer, locals_size);
1233
- for (uint32_t index = 0; index < locals_size; index++) {
1234
- pm_buffer_append_varint(buffer, pm_sizet_to_u32(((pm_match_write_node_t *)node)->locals.ids[index]));
1257
+ uint32_t targets_size = pm_sizet_to_u32(((pm_match_write_node_t *)node)->targets.size);
1258
+ pm_buffer_append_varint(buffer, targets_size);
1259
+ for (uint32_t index = 0; index < targets_size; index++) {
1260
+ pm_serialize_node(parser, (pm_node_t *) ((pm_match_write_node_t *)node)->targets.nodes[index], buffer);
1235
1261
  }
1236
1262
  break;
1237
1263
  }
@@ -1593,11 +1619,6 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1593
1619
  }
1594
1620
  break;
1595
1621
  }
1596
- case PM_STRING_CONCAT_NODE: {
1597
- pm_serialize_node(parser, (pm_node_t *)((pm_string_concat_node_t *)node)->left, buffer);
1598
- pm_serialize_node(parser, (pm_node_t *)((pm_string_concat_node_t *)node)->right, buffer);
1599
- break;
1600
- }
1601
1622
  case PM_STRING_NODE: {
1602
1623
  pm_buffer_append_varint(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
1603
1624
  if (((pm_string_node_t *)node)->opening_loc.start == NULL) {
@@ -1679,6 +1700,12 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1679
1700
  case PM_UNLESS_NODE: {
1680
1701
  pm_serialize_location(parser, &((pm_unless_node_t *)node)->keyword_loc, buffer);
1681
1702
  pm_serialize_node(parser, (pm_node_t *)((pm_unless_node_t *)node)->predicate, buffer);
1703
+ if (((pm_unless_node_t *)node)->then_keyword_loc.start == NULL) {
1704
+ pm_buffer_append_byte(buffer, 0);
1705
+ } else {
1706
+ pm_buffer_append_byte(buffer, 1);
1707
+ pm_serialize_location(parser, &((pm_unless_node_t *)node)->then_keyword_loc, buffer);
1708
+ }
1682
1709
  if (((pm_unless_node_t *)node)->statements == NULL) {
1683
1710
  pm_buffer_append_byte(buffer, 0);
1684
1711
  } else {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prism
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.1
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-03 00:00:00.000000000 Z
11
+ date: 2023-11-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -72,6 +72,7 @@ files:
72
72
  - lib/prism/debug.rb
73
73
  - lib/prism/desugar_compiler.rb
74
74
  - lib/prism/dispatcher.rb
75
+ - lib/prism/dot_visitor.rb
75
76
  - lib/prism/dsl.rb
76
77
  - lib/prism/ffi.rb
77
78
  - lib/prism/lex_compat.rb
@@ -94,6 +95,7 @@ files:
94
95
  - sig/prism_static.rbs
95
96
  - src/diagnostic.c
96
97
  - src/enc/pm_big5.c
98
+ - src/enc/pm_cp51932.c
97
99
  - src/enc/pm_euc_jp.c
98
100
  - src/enc/pm_gbk.c
99
101
  - src/enc/pm_shift_jis.c
@@ -124,6 +126,8 @@ licenses:
124
126
  - MIT
125
127
  metadata:
126
128
  allowed_push_host: https://rubygems.org
129
+ source_code_uri: https://github.com/ruby/prism
130
+ changelog_uri: https://github.com/ruby/prism/blob/main/CHANGELOG.md
127
131
  post_install_message:
128
132
  rdoc_options: []
129
133
  require_paths: