prism 2.0.0-arm-linux-musl

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 (233) hide show
  1. checksums.yaml +7 -0
  2. data/BSDmakefile +58 -0
  3. data/CHANGELOG.md +881 -0
  4. data/CODE_OF_CONDUCT.md +76 -0
  5. data/CONTRIBUTING.md +58 -0
  6. data/LICENSE.md +7 -0
  7. data/Makefile +145 -0
  8. data/README.md +81 -0
  9. data/config.yml +4752 -0
  10. data/docs/build_system.md +119 -0
  11. data/docs/configuration.md +69 -0
  12. data/docs/cruby_compilation.md +27 -0
  13. data/docs/design.md +53 -0
  14. data/docs/encoding.md +121 -0
  15. data/docs/fuzzing.md +81 -0
  16. data/docs/heredocs.md +36 -0
  17. data/docs/javascript.md +133 -0
  18. data/docs/local_variable_depth.md +229 -0
  19. data/docs/mapping.md +117 -0
  20. data/docs/parser_translation.md +24 -0
  21. data/docs/parsing_rules.md +22 -0
  22. data/docs/releasing.md +147 -0
  23. data/docs/relocation.md +32 -0
  24. data/docs/ripper_translation.md +63 -0
  25. data/docs/ruby_api.md +45 -0
  26. data/docs/ruby_parser_translation.md +19 -0
  27. data/docs/serialization.md +244 -0
  28. data/docs/testing.md +72 -0
  29. data/ext/prism/api_node.c +7005 -0
  30. data/ext/prism/extconf.rb +126 -0
  31. data/ext/prism/extension.c +1768 -0
  32. data/ext/prism/extension.h +19 -0
  33. data/include/prism/arena.h +45 -0
  34. data/include/prism/arena.hpp +42 -0
  35. data/include/prism/ast.h +10381 -0
  36. data/include/prism/ast.hpp +641 -0
  37. data/include/prism/buffer.h +60 -0
  38. data/include/prism/buffer.hpp +55 -0
  39. data/include/prism/comments.h +72 -0
  40. data/include/prism/compiler/accel.h +26 -0
  41. data/include/prism/compiler/align.h +36 -0
  42. data/include/prism/compiler/assume.h +25 -0
  43. data/include/prism/compiler/branch.h +26 -0
  44. data/include/prism/compiler/bswap.h +46 -0
  45. data/include/prism/compiler/cplusplus.hpp +16 -0
  46. data/include/prism/compiler/endianness.h +34 -0
  47. data/include/prism/compiler/exceptions.hpp +17 -0
  48. data/include/prism/compiler/exported.h +24 -0
  49. data/include/prism/compiler/fallthrough.h +22 -0
  50. data/include/prism/compiler/filesystem.h +32 -0
  51. data/include/prism/compiler/flex_array.h +19 -0
  52. data/include/prism/compiler/force_inline.h +21 -0
  53. data/include/prism/compiler/format.h +27 -0
  54. data/include/prism/compiler/inline.h +17 -0
  55. data/include/prism/compiler/lifetimebound.hpp +25 -0
  56. data/include/prism/compiler/nodiscard.h +22 -0
  57. data/include/prism/compiler/nonnull.h +18 -0
  58. data/include/prism/compiler/unused.h +18 -0
  59. data/include/prism/constant_pool.h +106 -0
  60. data/include/prism/diagnostic.h +111 -0
  61. data/include/prism/errors_format.h +61 -0
  62. data/include/prism/excludes.h +29 -0
  63. data/include/prism/integer.h +41 -0
  64. data/include/prism/internal/allocator.h +68 -0
  65. data/include/prism/internal/allocator_debug.h +88 -0
  66. data/include/prism/internal/arena.h +108 -0
  67. data/include/prism/internal/bit.h +42 -0
  68. data/include/prism/internal/buffer.h +94 -0
  69. data/include/prism/internal/char.h +145 -0
  70. data/include/prism/internal/comments.h +53 -0
  71. data/include/prism/internal/constant_pool.h +152 -0
  72. data/include/prism/internal/diagnostic.h +389 -0
  73. data/include/prism/internal/encoding.h +242 -0
  74. data/include/prism/internal/integer.h +68 -0
  75. data/include/prism/internal/isinf.h +16 -0
  76. data/include/prism/internal/line_offset_list.h +34 -0
  77. data/include/prism/internal/list.h +62 -0
  78. data/include/prism/internal/magic_comments.h +23 -0
  79. data/include/prism/internal/memchr.h +15 -0
  80. data/include/prism/internal/node.h +42 -0
  81. data/include/prism/internal/options.h +232 -0
  82. data/include/prism/internal/parser.h +1004 -0
  83. data/include/prism/internal/regexp.h +26 -0
  84. data/include/prism/internal/serialize.h +39 -0
  85. data/include/prism/internal/source.h +72 -0
  86. data/include/prism/internal/static_literals.h +100 -0
  87. data/include/prism/internal/stringy.h +30 -0
  88. data/include/prism/internal/strncasecmp.h +18 -0
  89. data/include/prism/internal/strpbrk.h +33 -0
  90. data/include/prism/internal/tokens.h +11 -0
  91. data/include/prism/internal/xxh3.h +16 -0
  92. data/include/prism/json.h +40 -0
  93. data/include/prism/line_offset_list.h +69 -0
  94. data/include/prism/magic_comments.h +53 -0
  95. data/include/prism/node.h +139 -0
  96. data/include/prism/node.hpp +272 -0
  97. data/include/prism/node_type.hpp +38 -0
  98. data/include/prism/options.h +363 -0
  99. data/include/prism/options.hpp +43 -0
  100. data/include/prism/parser.h +433 -0
  101. data/include/prism/parser.hpp +274 -0
  102. data/include/prism/prettyprint.h +39 -0
  103. data/include/prism/serialize.h +123 -0
  104. data/include/prism/source.h +163 -0
  105. data/include/prism/stream.h +36 -0
  106. data/include/prism/string_query.h +82 -0
  107. data/include/prism/stringy.h +61 -0
  108. data/include/prism/stringy.hpp +31 -0
  109. data/include/prism/version.h +46 -0
  110. data/include/prism.h +123 -0
  111. data/include/prism.hpp +24 -0
  112. data/lib/prism/3.3/prism.so +0 -0
  113. data/lib/prism/3.4/prism.so +0 -0
  114. data/lib/prism/4.0/prism.so +0 -0
  115. data/lib/prism/compiler.rb +815 -0
  116. data/lib/prism/desugar_compiler.rb +463 -0
  117. data/lib/prism/dispatcher.rb +2383 -0
  118. data/lib/prism/dot_visitor.rb +4848 -0
  119. data/lib/prism/dsl.rb +1369 -0
  120. data/lib/prism/ffi.rb +746 -0
  121. data/lib/prism/inspect_visitor.rb +2425 -0
  122. data/lib/prism/lex_compat.rb +953 -0
  123. data/lib/prism/mutation_compiler.rb +780 -0
  124. data/lib/prism/node.rb +33940 -0
  125. data/lib/prism/node_ext.rb +504 -0
  126. data/lib/prism/node_find.rb +215 -0
  127. data/lib/prism/parse_result/errors.rb +72 -0
  128. data/lib/prism/parse_result/newlines.rb +423 -0
  129. data/lib/prism/parse_result.rb +1236 -0
  130. data/lib/prism/pattern.rb +314 -0
  131. data/lib/prism/polyfill/append_as_bytes.rb +15 -0
  132. data/lib/prism/polyfill/byteindex.rb +13 -0
  133. data/lib/prism/polyfill/scan_byte.rb +14 -0
  134. data/lib/prism/polyfill/unpack1.rb +14 -0
  135. data/lib/prism/polyfill/warn.rb +36 -0
  136. data/lib/prism/reflection.rb +427 -0
  137. data/lib/prism/relocation.rb +567 -0
  138. data/lib/prism/serialize.rb +4589 -0
  139. data/lib/prism/string_query.rb +54 -0
  140. data/lib/prism/translation/parser/builder.rb +70 -0
  141. data/lib/prism/translation/parser/compiler.rb +2226 -0
  142. data/lib/prism/translation/parser/lexer.rb +769 -0
  143. data/lib/prism/translation/parser.rb +376 -0
  144. data/lib/prism/translation/parser_current.rb +26 -0
  145. data/lib/prism/translation/parser_versions.rb +36 -0
  146. data/lib/prism/translation/ripper/filter.rb +53 -0
  147. data/lib/prism/translation/ripper/lexer.rb +133 -0
  148. data/lib/prism/translation/ripper/sexp.rb +118 -0
  149. data/lib/prism/translation/ripper/shim.rb +7 -0
  150. data/lib/prism/translation/ripper.rb +4278 -0
  151. data/lib/prism/translation/ruby_parser.rb +1721 -0
  152. data/lib/prism/translation.rb +20 -0
  153. data/lib/prism/visitor.rb +1440 -0
  154. data/lib/prism.rb +168 -0
  155. data/prism.gemspec +251 -0
  156. data/rbi/generated/prism/compiler.rbi +489 -0
  157. data/rbi/generated/prism/desugar_compiler.rbi +306 -0
  158. data/rbi/generated/prism/dispatcher.rbi +1138 -0
  159. data/rbi/generated/prism/dot_visitor.rbi +618 -0
  160. data/rbi/generated/prism/dsl.rbi +751 -0
  161. data/rbi/generated/prism/inspect_visitor.rbi +503 -0
  162. data/rbi/generated/prism/lex_compat.rbi +162 -0
  163. data/rbi/generated/prism/mutation_compiler.rbi +464 -0
  164. data/rbi/generated/prism/node.rbi +15143 -0
  165. data/rbi/generated/prism/node_ext.rbi +259 -0
  166. data/rbi/generated/prism/node_find.rbi +79 -0
  167. data/rbi/generated/prism/parse_result/errors.rbi +21 -0
  168. data/rbi/generated/prism/parse_result/newlines.rbi +208 -0
  169. data/rbi/generated/prism/parse_result.rbi +776 -0
  170. data/rbi/generated/prism/pattern.rbi +134 -0
  171. data/rbi/generated/prism/reflection.rbi +89 -0
  172. data/rbi/generated/prism/relocation.rbi +329 -0
  173. data/rbi/generated/prism/serialize.rbi +185 -0
  174. data/rbi/generated/prism/string_query.rbi +43 -0
  175. data/rbi/generated/prism/translation.rbi +7 -0
  176. data/rbi/generated/prism/visitor.rbi +650 -0
  177. data/rbi/generated/prism.rbi +86 -0
  178. data/rbi/prism/translation/parser.rbi +11 -0
  179. data/rbi/prism/translation/parser_versions.rbi +28 -0
  180. data/rbi/prism/translation/ripper.rbi +15 -0
  181. data/rbi/rubyvm/node_find.rbi +14 -0
  182. data/sig/generated/prism/compiler.rbs +492 -0
  183. data/sig/generated/prism/desugar_compiler.rbs +305 -0
  184. data/sig/generated/prism/dispatcher.rbs +1292 -0
  185. data/sig/generated/prism/dot_visitor.rbs +635 -0
  186. data/sig/generated/prism/dsl.rbs +928 -0
  187. data/sig/generated/prism/inspect_visitor.rbs +509 -0
  188. data/sig/generated/prism/lex_compat.rbs +166 -0
  189. data/sig/generated/prism/mutation_compiler.rbs +464 -0
  190. data/sig/generated/prism/node.rbs +21632 -0
  191. data/sig/generated/prism/node_ext.rbs +290 -0
  192. data/sig/generated/prism/node_find.rbs +90 -0
  193. data/sig/generated/prism/parse_result/errors.rbs +22 -0
  194. data/sig/generated/prism/parse_result/newlines.rbs +223 -0
  195. data/sig/generated/prism/parse_result.rbs +871 -0
  196. data/sig/generated/prism/pattern.rbs +156 -0
  197. data/sig/generated/prism/reflection.rbs +101 -0
  198. data/sig/generated/prism/relocation.rbs +428 -0
  199. data/sig/generated/prism/serialize.rbs +200 -0
  200. data/sig/generated/prism/string_query.rbs +43 -0
  201. data/sig/generated/prism/translation.rbs +8 -0
  202. data/sig/generated/prism/visitor.rbs +1111 -0
  203. data/sig/generated/prism.rbs +84 -0
  204. data/sig/manifest.yaml +2 -0
  205. data/src/arena.c +117 -0
  206. data/src/buffer.c +389 -0
  207. data/src/char.c +289 -0
  208. data/src/comments.c +454 -0
  209. data/src/constant_pool.c +406 -0
  210. data/src/diagnostic.c +894 -0
  211. data/src/encoding.c +5345 -0
  212. data/src/errors_format.c +519 -0
  213. data/src/integer.c +681 -0
  214. data/src/json.c +5733 -0
  215. data/src/line_offset_list.c +100 -0
  216. data/src/list.c +24 -0
  217. data/src/memchr.c +37 -0
  218. data/src/node.c +4363 -0
  219. data/src/options.c +445 -0
  220. data/src/parser.c +371 -0
  221. data/src/prettyprint.c +9024 -0
  222. data/src/prism.c +23901 -0
  223. data/src/regexp.c +1705 -0
  224. data/src/serialize.c +2660 -0
  225. data/src/source.c +524 -0
  226. data/src/static_literals.c +685 -0
  227. data/src/string_query.c +180 -0
  228. data/src/stringy.c +61 -0
  229. data/src/strncasecmp.c +37 -0
  230. data/src/strpbrk.c +447 -0
  231. data/src/tokens.c +724 -0
  232. data/src/xxh3.c +292 -0
  233. metadata +276 -0
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @file string_query.h
3
+ *
4
+ * Functions for querying properties of strings, such as whether they are valid
5
+ * local variable names, constant names, or method names.
6
+ */
7
+ #ifndef PRISM_STRING_QUERY_H
8
+ #define PRISM_STRING_QUERY_H
9
+
10
+ #include "prism/compiler/exported.h"
11
+ #include "prism/compiler/nonnull.h"
12
+
13
+ #include <stddef.h>
14
+ #include <stdint.h>
15
+
16
+ #ifdef __cplusplus
17
+ extern "C" {
18
+ #endif
19
+
20
+ /**
21
+ * Represents the results of a slice query.
22
+ */
23
+ typedef enum {
24
+ /** Returned if the encoding given to a slice query was invalid. */
25
+ PM_STRING_QUERY_ERROR = -1,
26
+
27
+ /** Returned if the result of the slice query is false. */
28
+ PM_STRING_QUERY_FALSE,
29
+
30
+ /** Returned if the result of the slice query is true. */
31
+ PM_STRING_QUERY_TRUE
32
+ } pm_string_query_t;
33
+
34
+ /**
35
+ * Check that the slice is a valid local variable name.
36
+ *
37
+ * @param source The source to check.
38
+ * @param length The length of the source.
39
+ * @param encoding_name The name of the encoding of the source.
40
+ * @returns PM_STRING_QUERY_TRUE if the query is true, PM_STRING_QUERY_FALSE if
41
+ * the query is false, and PM_STRING_QUERY_ERROR if the encoding was invalid.
42
+ */
43
+ PRISM_EXPORTED_FUNCTION pm_string_query_t pm_string_query_local(const uint8_t *source, size_t length, const char *encoding_name) PRISM_NONNULL(1, 3);
44
+
45
+ /**
46
+ * Check that the slice is a valid constant name.
47
+ *
48
+ * @param source The source to check.
49
+ * @param length The length of the source.
50
+ * @param encoding_name The name of the encoding of the source.
51
+ * @returns PM_STRING_QUERY_TRUE if the query is true, PM_STRING_QUERY_FALSE if
52
+ * the query is false, and PM_STRING_QUERY_ERROR if the encoding was invalid.
53
+ */
54
+ PRISM_EXPORTED_FUNCTION pm_string_query_t pm_string_query_constant(const uint8_t *source, size_t length, const char *encoding_name) PRISM_NONNULL(1, 3);
55
+
56
+ /**
57
+ * Check that the slice is a valid method name.
58
+ *
59
+ * @param source The source to check.
60
+ * @param length The length of the source.
61
+ * @param encoding_name The name of the encoding of the source.
62
+ * @returns PM_STRING_QUERY_TRUE if the query is true, PM_STRING_QUERY_FALSE if
63
+ * the query is false, and PM_STRING_QUERY_ERROR if the encoding was invalid.
64
+ */
65
+ PRISM_EXPORTED_FUNCTION pm_string_query_t pm_string_query_method_name(const uint8_t *source, size_t length, const char *encoding_name) PRISM_NONNULL(1, 3);
66
+
67
+ /**
68
+ * Check that the slice is a keyword.
69
+ *
70
+ * @param source The source to check.
71
+ * @param length The length of the source.
72
+ * @param encoding_name The name of the encoding of the source.
73
+ * @returns PM_STRING_QUERY_TRUE if the query is true, PM_STRING_QUERY_FALSE if
74
+ * the query is false, and PM_STRING_QUERY_ERROR if the encoding was invalid.
75
+ */
76
+ PRISM_EXPORTED_FUNCTION pm_string_query_t pm_string_query_keyword(const uint8_t *source, size_t length, const char *encoding_name) PRISM_NONNULL(1, 3);
77
+
78
+ #ifdef __cplusplus
79
+ }
80
+ #endif
81
+
82
+ #endif
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @file stringy.h
3
+ *
4
+ * A view of a sequence of bytes owned by someone else.
5
+ */
6
+ #ifndef PRISM_STRINGY_H
7
+ #define PRISM_STRINGY_H
8
+
9
+ #include "prism/compiler/exported.h"
10
+ #include "prism/compiler/nonnull.h"
11
+
12
+ #include <stddef.h>
13
+ #include <stdint.h>
14
+
15
+ #ifdef __cplusplus
16
+ extern "C" {
17
+ #endif
18
+
19
+ /**
20
+ * A view of a sequence of bytes. The string does not own the bytes, so they
21
+ * must remain valid for as long as the string is in use.
22
+ */
23
+ typedef struct {
24
+ /** A pointer to the start of the string. */
25
+ const uint8_t *source;
26
+
27
+ /** The length of the string in bytes of memory. */
28
+ size_t length;
29
+ } pm_string_t;
30
+
31
+ /**
32
+ * Initialize a string that views the given bytes. The bytes are not copied, so
33
+ * they must remain valid for as long as the string is in use.
34
+ *
35
+ * @param string The string to initialize.
36
+ * @param source The start of the bytes.
37
+ * @param length The number of bytes.
38
+ */
39
+ PRISM_EXPORTED_FUNCTION void pm_string_init(pm_string_t *string, const uint8_t *source, size_t length) PRISM_NONNULL(1);
40
+
41
+ /**
42
+ * Returns the length associated with the string.
43
+ *
44
+ * @param string The string to get the length of.
45
+ * @returns The length of the string.
46
+ */
47
+ PRISM_EXPORTED_FUNCTION size_t pm_string_length(const pm_string_t *string) PRISM_NONNULL(1);
48
+
49
+ /**
50
+ * Returns the start pointer associated with the string.
51
+ *
52
+ * @param string The string to get the start pointer of.
53
+ * @returns The start pointer of the string.
54
+ */
55
+ PRISM_EXPORTED_FUNCTION const uint8_t * pm_string_source(const pm_string_t *string) PRISM_NONNULL(1);
56
+
57
+ #ifdef __cplusplus
58
+ }
59
+ #endif
60
+
61
+ #endif
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @file stringy.hpp
3
+ *
4
+ * Access to the contents of strings from C++.
5
+ */
6
+ #ifndef PRISM_STRINGY_HPP
7
+ #define PRISM_STRINGY_HPP
8
+
9
+ #include "prism/compiler/cplusplus.hpp"
10
+ #include "prism/compiler/lifetimebound.hpp"
11
+
12
+ #include "prism/stringy.h"
13
+
14
+ #include <string_view>
15
+
16
+ namespace prism {
17
+
18
+ /**
19
+ * The bytes of the given string.
20
+ *
21
+ * @param string The string to view.
22
+ * @return A view of the bytes of the string.
23
+ */
24
+ [[nodiscard]] inline std::string_view
25
+ view(const pm_string_t &string PRISM_LIFETIMEBOUND) noexcept {
26
+ return std::string_view(reinterpret_cast<const char *>(pm_string_source(&string)), pm_string_length(&string));
27
+ }
28
+
29
+ }
30
+
31
+ #endif
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @file version.h
3
+ *
4
+ * The version of the Prism library.
5
+ */
6
+ #ifndef PRISM_VERSION_H
7
+ #define PRISM_VERSION_H
8
+
9
+ #include "prism/compiler/exported.h"
10
+
11
+ #ifdef __cplusplus
12
+ extern "C" {
13
+ #endif
14
+
15
+ /**
16
+ * The major version of the Prism library as an int.
17
+ */
18
+ #define PRISM_VERSION_MAJOR 2
19
+
20
+ /**
21
+ * The minor version of the Prism library as an int.
22
+ */
23
+ #define PRISM_VERSION_MINOR 0
24
+
25
+ /**
26
+ * The patch version of the Prism library as an int.
27
+ */
28
+ #define PRISM_VERSION_PATCH 0
29
+
30
+ /**
31
+ * The version of the Prism library as a constant string.
32
+ */
33
+ #define PRISM_VERSION "2.0.0"
34
+
35
+ /**
36
+ * The prism version and the serialization format.
37
+ *
38
+ * @returns The prism version as a constant string.
39
+ */
40
+ PRISM_EXPORTED_FUNCTION const char * pm_version(void);
41
+
42
+ #ifdef __cplusplus
43
+ }
44
+ #endif
45
+
46
+ #endif
data/include/prism.h ADDED
@@ -0,0 +1,123 @@
1
+ /**
2
+ * @file prism.h
3
+ *
4
+ * The main header file for the prism parser.
5
+ */
6
+ #ifndef PRISM_H
7
+ #define PRISM_H
8
+
9
+ #include "prism/arena.h"
10
+ #include "prism/ast.h"
11
+ #include "prism/buffer.h"
12
+ #include "prism/diagnostic.h"
13
+ #include "prism/errors_format.h"
14
+ #include "prism/json.h"
15
+ #include "prism/node.h"
16
+ #include "prism/options.h"
17
+ #include "prism/parser.h"
18
+ #include "prism/prettyprint.h"
19
+ #include "prism/serialize.h"
20
+ #include "prism/source.h"
21
+ #include "prism/stream.h"
22
+ #include "prism/string_query.h"
23
+ #include "prism/version.h"
24
+
25
+ /**
26
+ * @mainpage
27
+ *
28
+ * Prism is a parser for the Ruby programming language. It is designed to be
29
+ * portable, error tolerant, and maintainable. It is written in C99 and has no
30
+ * dependencies. It is currently being integrated into
31
+ * [CRuby](https://github.com/ruby/ruby),
32
+ * [JRuby](https://github.com/jruby/jruby),
33
+ * [TruffleRuby](https://github.com/truffleruby/truffleruby),
34
+ * [Sorbet](https://github.com/sorbet/sorbet), and
35
+ * [Syntax Tree](https://github.com/ruby-syntax-tree/syntax_tree).
36
+ *
37
+ * @section getting-started Getting started
38
+ *
39
+ * If you're vendoring this project and compiling it statically then as long as
40
+ * you have a C99 compiler you will be fine. If you're linking against it as
41
+ * shared library, then you should compile with `-fvisibility=hidden` and
42
+ * `-DPRISM_EXPORT_SYMBOLS` to tell prism to make only its public interface
43
+ * visible.
44
+ *
45
+ * @section parsing Parsing
46
+ *
47
+ * In order to parse Ruby code, the functions that you are going to want to use
48
+ * and be aware of are:
49
+ *
50
+ * * `pm_arena_new()` - create a new arena to hold all AST-lifetime allocations
51
+ * * `pm_parser_new()` - allocate and initialize a new parser
52
+ * * `pm_parse()` - parse and return the root node
53
+ * * `pm_parser_free()` - free the parser and its internal memory
54
+ * * `pm_arena_free()` - free all AST-lifetime memory
55
+ *
56
+ * Putting all of this together would look something like:
57
+ *
58
+ * ```c
59
+ * void parse(const uint8_t *source, size_t length) {
60
+ * pm_arena_t *arena = pm_arena_new();
61
+ * pm_parser_t *parser = pm_parser_new(arena, source, length, NULL);
62
+ *
63
+ * pm_node_t *root = pm_parse(parser);
64
+ * printf("PARSED!\n");
65
+ *
66
+ * pm_parser_free(parser);
67
+ * pm_arena_free(arena);
68
+ * }
69
+ * ```
70
+ *
71
+ * All of the nodes "inherit" from `pm_node_t` by embedding those structures
72
+ * as their first member. This means you can downcast and upcast any node in the
73
+ * tree to a `pm_node_t`.
74
+ *
75
+ * @section serializing Serializing
76
+ *
77
+ * Prism provides the ability to serialize the AST and its related metadata into
78
+ * a binary format. This format is designed to be portable to different
79
+ * languages and runtimes so that you only need to make one FFI call in order to
80
+ * parse Ruby code. The functions that you are going to want to use and be
81
+ * aware of are:
82
+ *
83
+ * * `pm_buffer_new()` - create a new buffer
84
+ * * `pm_buffer_free()` - free the buffer and its internal memory
85
+ * * `pm_serialize_parse()` - parse and serialize the AST into a buffer
86
+ *
87
+ * Putting all of this together would look something like:
88
+ *
89
+ * ```c
90
+ * void serialize(const uint8_t *source, size_t length) {
91
+ * pm_buffer_t *buffer = pm_buffer_new();
92
+ *
93
+ * pm_serialize_parse(buffer, source, length, NULL);
94
+ * printf("SERIALIZED!\n");
95
+ *
96
+ * pm_buffer_free(buffer);
97
+ * }
98
+ * ```
99
+ *
100
+ * @section inspecting Inspecting
101
+ *
102
+ * Prism provides the ability to inspect the AST by pretty-printing nodes. You
103
+ * can do this with the `pm_prettyprint()` function, which you would use like:
104
+ *
105
+ * ```c
106
+ * void prettyprint(const uint8_t *source, size_t length) {
107
+ * pm_arena_t *arena = pm_arena_new();
108
+ * pm_parser_t *parser = pm_parser_new(arena, source, length, NULL);
109
+ *
110
+ * pm_node_t *root = pm_parse(parser);
111
+ * pm_buffer_t *buffer = pm_buffer_new();
112
+ *
113
+ * pm_prettyprint(buffer, parser, root);
114
+ * printf("%*.s\n", (int) pm_buffer_length(buffer), pm_buffer_value(buffer));
115
+ *
116
+ * pm_buffer_free(buffer);
117
+ * pm_parser_free(parser);
118
+ * pm_arena_free(arena);
119
+ * }
120
+ * ```
121
+ */
122
+
123
+ #endif
data/include/prism.hpp ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @file prism.hpp
3
+ *
4
+ * The main header file for the C++ interface to the prism parser. It adds
5
+ * ownership, checked casts between node types, and callable-based iteration on
6
+ * top of the C API. It never wraps the C structs: every function in it takes
7
+ * and returns the same pm_*_t types that prism.h declares, so the two can be
8
+ * mixed freely. It requires C++17 or later.
9
+ */
10
+ #ifndef PRISM_HPP
11
+ #define PRISM_HPP
12
+
13
+ #include "prism.h"
14
+
15
+ #include "prism/arena.hpp"
16
+ #include "prism/ast.hpp"
17
+ #include "prism/buffer.hpp"
18
+ #include "prism/node.hpp"
19
+ #include "prism/node_type.hpp"
20
+ #include "prism/options.hpp"
21
+ #include "prism/parser.hpp"
22
+ #include "prism/stringy.hpp"
23
+
24
+ #endif
Binary file
Binary file
Binary file