prism 2.0.0.rc2 → 2.0.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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -2
  3. data/docs/serialization.md +19 -6
  4. data/ext/prism/api_node.c +80 -80
  5. data/ext/prism/extension.c +34 -67
  6. data/ext/prism/extension.h +1 -1
  7. data/include/prism/arena.h +8 -0
  8. data/include/prism/arena.hpp +42 -0
  9. data/include/prism/ast.h +11 -1
  10. data/include/prism/ast.hpp +641 -0
  11. data/include/prism/buffer.h +8 -0
  12. data/include/prism/buffer.hpp +55 -0
  13. data/include/prism/comments.h +17 -0
  14. data/include/prism/compiler/branch.h +26 -0
  15. data/include/prism/compiler/cplusplus.hpp +16 -0
  16. data/include/prism/compiler/exceptions.hpp +17 -0
  17. data/include/prism/compiler/format.h +2 -0
  18. data/include/prism/compiler/lifetimebound.hpp +25 -0
  19. data/include/prism/constant_pool.h +25 -0
  20. data/include/prism/diagnostic.h +18 -0
  21. data/include/prism/errors_format.h +8 -0
  22. data/include/prism/internal/node.h +8 -4
  23. data/include/prism/internal/stringy.h +1 -6
  24. data/include/prism/json.h +8 -0
  25. data/include/prism/line_offset_list.h +8 -0
  26. data/include/prism/magic_comments.h +18 -0
  27. data/include/prism/node.h +55 -10
  28. data/include/prism/node.hpp +272 -0
  29. data/include/prism/node_type.hpp +38 -0
  30. data/include/prism/options.h +10 -1
  31. data/include/prism/options.hpp +43 -0
  32. data/include/prism/parser.h +72 -64
  33. data/include/prism/parser.hpp +274 -0
  34. data/include/prism/prettyprint.h +8 -0
  35. data/include/prism/serialize.h +8 -0
  36. data/include/prism/source.h +8 -0
  37. data/include/prism/stream.h +8 -0
  38. data/include/prism/string_query.h +8 -0
  39. data/include/prism/stringy.h +16 -27
  40. data/include/prism/stringy.hpp +31 -0
  41. data/include/prism/version.h +9 -1
  42. data/include/prism.h +0 -8
  43. data/include/prism.hpp +24 -0
  44. data/lib/prism/serialize.rb +2549 -3281
  45. data/prism.gemspec +14 -1
  46. data/rbi/generated/prism/node.rbi +736 -0
  47. data/rbi/generated/prism/serialize.rbi +6 -5
  48. data/sig/generated/prism/node.rbs +736 -0
  49. data/sig/generated/prism/serialize.rbs +7 -5
  50. data/src/comments.c +2 -2
  51. data/src/diagnostic.c +8 -0
  52. data/src/node.c +216 -368
  53. data/src/options.c +7 -13
  54. data/src/parser.c +52 -48
  55. data/src/prism.c +175 -194
  56. data/src/regexp.c +0 -1
  57. data/src/serialize.c +2300 -1950
  58. data/src/source.c +8 -2
  59. data/src/stringy.c +3 -33
  60. metadata +14 -1
@@ -152,9 +152,6 @@ module Prism
152
152
  # : () -> Integer
153
153
  def load_uint64: () -> Integer
154
154
 
155
- # : (ConstantPool constant_pool, Encoding encoding, bool freeze) -> node?
156
- def load_optional_node: (ConstantPool constant_pool, Encoding encoding, bool freeze) -> node?
157
-
158
155
  # : (Encoding encoding) -> String
159
156
  def load_string: (Encoding encoding) -> String
160
157
 
@@ -184,8 +181,13 @@ module Prism
184
181
  # : (ConstantPool constant_pool, Encoding encoding) -> Symbol?
185
182
  def load_optional_constant: (ConstantPool constant_pool, Encoding encoding) -> Symbol?
186
183
 
187
- # : (ConstantPool constant_pool, Encoding encoding, bool freeze) -> node
188
- def load_node: (ConstantPool constant_pool, Encoding encoding, bool freeze) -> node
184
+ # Load the nodes that are serialized before the given offset and return
185
+ # the root. Nodes are serialized in post-order, so the children of each
186
+ # node are the topmost values on the stack, in field order, by the time
187
+ # its record is read.
188
+ #
189
+ # : (ConstantPool constant_pool, Encoding encoding, bool freeze, Integer finish) -> node
190
+ def load_nodes: (ConstantPool constant_pool, Encoding encoding, bool freeze, Integer finish) -> node
189
191
 
190
192
  @load_node_lambdas: Array[Proc]
191
193
 
data/src/comments.c CHANGED
@@ -223,7 +223,7 @@ pm_comments_blank_after(const pm_comments_walk_t *walk, uint32_t offset, uint32_
223
223
  * descends itself, so that it can visit children in source order and handle
224
224
  * each node after all of its descendants.
225
225
  */
226
- static bool
226
+ static pm_visit_result_t
227
227
  pm_comments_push(const pm_node_t *node, void *data) {
228
228
  pm_comments_walk_t *walk = (pm_comments_walk_t *) data;
229
229
 
@@ -237,7 +237,7 @@ pm_comments_push(const pm_node_t *node, void *data) {
237
237
  }
238
238
 
239
239
  walk->stack.nodes[walk->stack.size++] = node;
240
- return false;
240
+ return PM_VISIT_SKIP;
241
241
  }
242
242
 
243
243
  /*
data/src/diagnostic.c CHANGED
@@ -832,6 +832,14 @@ pm_diagnostic_warning_level(const pm_diagnostic_t *diagnostic) {
832
832
  return (pm_warning_level_t) pm_diagnostic_id_level(diagnostic->diag_id);
833
833
  }
834
834
 
835
+ /**
836
+ * Get the diagnostic that follows the given diagnostic.
837
+ */
838
+ const pm_diagnostic_t *
839
+ pm_diagnostic_next(const pm_diagnostic_t *diagnostic) {
840
+ return (const pm_diagnostic_t *) diagnostic->node.next;
841
+ }
842
+
835
843
  /**
836
844
  * Append an error to the given list of diagnostic.
837
845
  */