herb 0.11.1 → 0.11.2

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 (247) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +4 -2
  3. data/config.yml +6 -0
  4. data/ext/herb/extconf.rb +8 -31
  5. data/ext/herb/nodes.c +75 -75
  6. data/ext/herb/parser_options_helpers.c +26 -0
  7. data/lib/herb/analysis/partial_index.rb +1 -1
  8. data/lib/herb/analysis/partial_resolution.rb +27 -0
  9. data/lib/herb/ast/helpers.rb +1 -1
  10. data/lib/herb/configuration.rb +11 -1
  11. data/lib/herb/dev/classifier.rb +1 -1
  12. data/lib/herb/engine/compiler.rb +5 -8
  13. data/lib/herb/engine/slots/dynamics_compiler.rb +53 -14
  14. data/lib/herb/engine/slots/subtree_compiler.rb +1 -1
  15. data/lib/herb/engine/slots/visitor.rb +32 -4
  16. data/lib/herb/engine/visitors/instrumentation_visitor.rb +18 -6
  17. data/lib/herb/parser_options.rb +6 -3
  18. data/lib/herb/project.rb +19 -8
  19. data/lib/herb/version.rb +1 -1
  20. data/lib/herb.rb +1 -1
  21. data/sig/herb/analysis/partial_resolution.rbs +8 -0
  22. data/sig/herb/configuration.rbs +3 -0
  23. data/sig/herb/engine/slots/dynamics_compiler.rbs +24 -7
  24. data/sig/herb/engine/slots/visitor.rbs +14 -0
  25. data/sig/herb/engine/visitors/instrumentation_visitor.rbs +5 -1
  26. data/sig/herb/parser_options.rbs +6 -4
  27. data/sig/herb.rbs +2 -2
  28. data/src/analyze/action_view/attribute_extraction_helpers.c +40 -21
  29. data/src/analyze/action_view/generated_handlers.c +36 -36
  30. data/src/analyze/action_view/image_tag.c +7 -3
  31. data/src/analyze/action_view/javascript_include_tag.c +6 -3
  32. data/src/analyze/action_view/link_to.c +23 -23
  33. data/src/analyze/action_view/registry.c +7 -3
  34. data/src/analyze/action_view/tag_helper_node_builders.c +6 -13
  35. data/src/analyze/action_view/tag_helpers.c +139 -90
  36. data/src/analyze/action_view/turbo_frame_tag.c +5 -4
  37. data/src/analyze/analyze.c +35 -19
  38. data/src/analyze/analyze_helpers.c +161 -188
  39. data/src/analyze/analyzed_ruby.c +8 -7
  40. data/src/analyze/control_type.c +29 -22
  41. data/src/analyze/herb_directives.c +16 -20
  42. data/src/analyze/iteration_nodes.c +69 -24
  43. data/src/analyze/parse_errors.c +32 -22
  44. data/src/analyze/postfix_conditionals.c +23 -13
  45. data/src/analyze/prism_annotate.c +29 -28
  46. data/src/analyze/render_nodes.c +51 -41
  47. data/src/analyze/strict_locals.c +14 -15
  48. data/src/analyze/ternary_conditionals.c +14 -10
  49. data/src/herb.c +10 -8
  50. data/src/include/analyze/action_view/tag_helper_handler.h +1 -1
  51. data/src/include/analyze/action_view/tag_helper_node_builders.h +1 -0
  52. data/src/include/analyze/action_view/tag_helpers.h +1 -1
  53. data/src/include/analyze/analyze.h +3 -2
  54. data/src/include/analyze/analyzed_ruby.h +4 -2
  55. data/src/include/analyze/helpers.h +6 -6
  56. data/src/include/herb.h +3 -2
  57. data/src/include/parser/parser_options.h +5 -0
  58. data/src/include/prism/prism_context.h +12 -12
  59. data/src/include/prism/prism_helpers.h +30 -0
  60. data/src/include/prism_version.h +11 -0
  61. data/src/include/version.h +1 -1
  62. data/src/parser/parser_helpers.c +1 -2
  63. data/src/parser.c +6 -7
  64. data/src/parser_options_defaults.c +1 -0
  65. data/src/prism/prism_helpers.c +84 -50
  66. data/src/prism/ruby_parser.c +20 -20
  67. data/templates/ext/herb/nodes.c.erb +5 -5
  68. data/templates/ext/herb/parser_options_helpers.c.erb +33 -0
  69. data/templates/java/nodes.c.erb +6 -6
  70. data/templates/java/parser_options_helpers.c.erb +41 -2
  71. data/templates/java/parser_options_helpers.h.erb +2 -1
  72. data/templates/javascript/packages/node/extension/nodes.cpp.erb +5 -5
  73. data/templates/javascript/packages/node/extension/parser_options_helpers.cpp.erb +34 -2
  74. data/templates/javascript/packages/node/extension/parser_options_helpers.h.erb +1 -1
  75. data/templates/lib/herb/parser_options.rb.erb +1 -1
  76. data/templates/rust/src/prism/generated_deserialize.rs.erb +90 -44
  77. data/templates/rust/src/prism/generated_prettyprint.rs.erb +18 -27
  78. data/templates/src/analyze/action_view/generated_handlers.c.erb +23 -22
  79. data/templates/src/include/parser/parser_options.h.erb +10 -0
  80. data/templates/src/include/prism_version.h.erb +17 -0
  81. data/templates/src/parser_options_defaults.c.erb +1 -1
  82. data/templates/template.rb +17 -2
  83. data/templates/wasm/nodes.cpp.erb +5 -5
  84. data/templates/wasm/parser_options_helpers.cpp.erb +24 -0
  85. data/vendor/prism/Rakefile +76 -7
  86. data/vendor/prism/config.yml +174 -161
  87. data/vendor/prism/include/prism/arena.h +45 -0
  88. data/vendor/prism/include/prism/arena.hpp +42 -0
  89. data/vendor/prism/include/prism/ast.h +2738 -611
  90. data/vendor/prism/include/prism/ast.hpp +641 -0
  91. data/vendor/prism/include/prism/buffer.h +60 -0
  92. data/vendor/prism/include/prism/buffer.hpp +55 -0
  93. data/vendor/prism/include/prism/comments.h +72 -0
  94. data/vendor/prism/include/prism/compiler/accel.h +26 -0
  95. data/vendor/prism/include/prism/compiler/align.h +36 -0
  96. data/vendor/prism/include/prism/compiler/assume.h +25 -0
  97. data/vendor/prism/include/prism/compiler/branch.h +26 -0
  98. data/vendor/prism/include/prism/compiler/bswap.h +46 -0
  99. data/vendor/prism/include/prism/compiler/cplusplus.hpp +16 -0
  100. data/vendor/prism/include/prism/compiler/endianness.h +34 -0
  101. data/vendor/prism/include/prism/compiler/exceptions.hpp +17 -0
  102. data/vendor/prism/include/prism/compiler/exported.h +24 -0
  103. data/vendor/prism/include/prism/compiler/fallthrough.h +22 -0
  104. data/vendor/prism/include/prism/compiler/filesystem.h +32 -0
  105. data/vendor/prism/include/prism/compiler/flex_array.h +19 -0
  106. data/vendor/prism/include/prism/compiler/force_inline.h +21 -0
  107. data/vendor/prism/include/prism/compiler/format.h +27 -0
  108. data/vendor/prism/include/prism/compiler/inline.h +17 -0
  109. data/vendor/prism/include/prism/compiler/lifetimebound.hpp +25 -0
  110. data/vendor/prism/include/prism/compiler/nodiscard.h +22 -0
  111. data/vendor/prism/include/prism/compiler/nonnull.h +18 -0
  112. data/vendor/prism/include/prism/compiler/unused.h +18 -0
  113. data/vendor/prism/include/prism/constant_pool.h +106 -0
  114. data/vendor/prism/include/prism/diagnostic.h +55 -402
  115. data/vendor/prism/include/prism/errors_format.h +61 -0
  116. data/vendor/prism/include/prism/excludes.h +29 -0
  117. data/vendor/prism/include/prism/integer.h +41 -0
  118. data/vendor/prism/include/prism/internal/allocator.h +68 -0
  119. data/vendor/prism/include/prism/internal/allocator_debug.h +88 -0
  120. data/vendor/prism/include/prism/internal/arena.h +108 -0
  121. data/vendor/prism/include/prism/internal/bit.h +42 -0
  122. data/vendor/prism/include/prism/internal/buffer.h +94 -0
  123. data/vendor/prism/include/prism/internal/char.h +145 -0
  124. data/vendor/prism/include/prism/internal/comments.h +54 -0
  125. data/vendor/prism/include/prism/internal/constant_pool.h +152 -0
  126. data/vendor/prism/include/prism/internal/diagnostic.h +389 -0
  127. data/vendor/prism/include/prism/{encoding.h → internal/encoding.h} +27 -68
  128. data/vendor/prism/include/prism/internal/integer.h +68 -0
  129. data/vendor/prism/include/prism/internal/isinf.h +16 -0
  130. data/vendor/prism/include/prism/internal/line_offset_list.h +34 -0
  131. data/vendor/prism/include/prism/{util/pm_list.h → internal/list.h} +11 -52
  132. data/vendor/prism/include/prism/internal/magic_comments.h +23 -0
  133. data/vendor/prism/include/prism/internal/memchr.h +15 -0
  134. data/vendor/prism/include/prism/internal/node.h +42 -0
  135. data/vendor/prism/include/prism/internal/options.h +232 -0
  136. data/vendor/prism/include/prism/internal/parser.h +1015 -0
  137. data/vendor/prism/include/prism/internal/regexp.h +26 -0
  138. data/vendor/prism/include/prism/internal/serialize.h +39 -0
  139. data/vendor/prism/include/prism/internal/source.h +72 -0
  140. data/vendor/prism/include/prism/internal/static_literals.h +60 -0
  141. data/vendor/prism/include/prism/internal/stringy.h +30 -0
  142. data/vendor/prism/include/prism/{util/pm_strncasecmp.h → internal/strncasecmp.h} +3 -17
  143. data/vendor/prism/include/prism/{util/pm_strpbrk.h → internal/strpbrk.h} +7 -20
  144. data/vendor/prism/include/prism/internal/tokens.h +11 -0
  145. data/vendor/prism/include/prism/internal/xxh3.h +16 -0
  146. data/vendor/prism/include/prism/json.h +40 -0
  147. data/vendor/prism/include/prism/line_offset_list.h +69 -0
  148. data/vendor/prism/include/prism/magic_comments.h +53 -0
  149. data/vendor/prism/include/prism/node.h +59 -49
  150. data/vendor/prism/include/prism/node.hpp +272 -0
  151. data/vendor/prism/include/prism/node_type.hpp +38 -0
  152. data/vendor/prism/include/prism/options.h +154 -279
  153. data/vendor/prism/include/prism/options.hpp +43 -0
  154. data/vendor/prism/include/prism/parser.h +367 -870
  155. data/vendor/prism/include/prism/parser.hpp +274 -0
  156. data/vendor/prism/include/prism/prettyprint.h +14 -9
  157. data/vendor/prism/include/prism/serialize.h +123 -0
  158. data/vendor/prism/include/prism/source.h +163 -0
  159. data/vendor/prism/include/prism/stream.h +36 -0
  160. data/vendor/prism/include/prism/string_query.h +82 -0
  161. data/vendor/prism/include/prism/stringy.h +61 -0
  162. data/vendor/prism/include/prism/stringy.hpp +31 -0
  163. data/vendor/prism/include/prism/version.h +20 -3
  164. data/vendor/prism/include/prism.h +35 -320
  165. data/vendor/prism/include/prism.hpp +24 -0
  166. data/vendor/prism/src/arena.c +122 -0
  167. data/vendor/prism/src/{util/pm_buffer.c → buffer.c} +53 -21
  168. data/vendor/prism/src/{util/pm_char.c → char.c} +28 -57
  169. data/vendor/prism/src/comments.c +455 -0
  170. data/vendor/prism/src/constant_pool.c +406 -0
  171. data/vendor/prism/src/diagnostic.c +120 -68
  172. data/vendor/prism/src/encoding.c +8 -3
  173. data/vendor/prism/src/errors_format.c +519 -0
  174. data/vendor/prism/src/{util/pm_integer.c → integer.c} +38 -22
  175. data/vendor/prism/src/json.c +5733 -0
  176. data/vendor/prism/src/line_offset_list.c +100 -0
  177. data/vendor/prism/src/list.c +24 -0
  178. data/vendor/prism/src/{util/pm_memchr.c → memchr.c} +8 -6
  179. data/vendor/prism/src/node.c +3465 -7787
  180. data/vendor/prism/src/options.c +161 -54
  181. data/vendor/prism/src/parser.c +371 -0
  182. data/vendor/prism/src/prettyprint.c +421 -354
  183. data/vendor/prism/src/prism.c +8522 -7280
  184. data/vendor/prism/src/regexp.c +960 -45
  185. data/vendor/prism/src/serialize.c +2434 -2048
  186. data/vendor/prism/src/source.c +524 -0
  187. data/vendor/prism/src/static_literals.c +303 -360
  188. data/vendor/prism/src/string_query.c +180 -0
  189. data/vendor/prism/src/stringy.c +61 -0
  190. data/vendor/prism/src/{util/pm_strncasecmp.c → strncasecmp.c} +5 -4
  191. data/vendor/prism/src/strpbrk.c +447 -0
  192. data/vendor/prism/src/{token_type.c → tokens.c} +39 -18
  193. data/vendor/prism/src/xxh3.c +292 -0
  194. data/vendor/prism/templates/ext/prism/api_node.c.erb +58 -44
  195. data/vendor/prism/templates/include/prism/ast.h.erb +67 -17
  196. data/vendor/prism/templates/include/prism/ast.hpp.erb +31 -0
  197. data/vendor/prism/templates/include/prism/internal/diagnostic.h.erb +60 -0
  198. data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/AbstractNodeVisitor.java.erb +1 -1
  199. data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/Loader.java.erb +232 -133
  200. data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/Nodes.java.erb +62 -23
  201. data/vendor/prism/templates/javascript/src/deserialize.js.erb +153 -146
  202. data/vendor/prism/templates/javascript/src/nodes.js.erb +4 -9
  203. data/vendor/prism/templates/lib/prism/compiler.rb.erb +14 -5
  204. data/vendor/prism/templates/lib/prism/dispatcher.rb.erb +20 -12
  205. data/vendor/prism/templates/lib/prism/dot_visitor.rb.erb +37 -11
  206. data/vendor/prism/templates/lib/prism/dsl.rb.erb +43 -4
  207. data/vendor/prism/templates/lib/prism/inspect_visitor.rb.erb +26 -10
  208. data/vendor/prism/templates/lib/prism/mutation_compiler.rb.erb +5 -2
  209. data/vendor/prism/templates/lib/prism/node.rb.erb +283 -105
  210. data/vendor/prism/templates/lib/prism/reflection.rb.erb +11 -2
  211. data/vendor/prism/templates/lib/prism/serialize.rb.erb +291 -134
  212. data/vendor/prism/templates/lib/prism/visitor.rb.erb +18 -0
  213. data/vendor/prism/templates/src/diagnostic.c.erb +114 -63
  214. data/vendor/prism/templates/src/json.c.erb +130 -0
  215. data/vendor/prism/templates/src/node.c.erb +79 -236
  216. data/vendor/prism/templates/src/prettyprint.c.erb +24 -13
  217. data/vendor/prism/templates/src/serialize.c.erb +369 -183
  218. data/vendor/prism/templates/src/{token_type.c.erb → tokens.c.erb} +22 -11
  219. data/vendor/prism/templates/template.rb +193 -91
  220. metadata +100 -42
  221. data/vendor/prism/include/prism/defines.h +0 -260
  222. data/vendor/prism/include/prism/pack.h +0 -163
  223. data/vendor/prism/include/prism/regexp.h +0 -43
  224. data/vendor/prism/include/prism/static_literals.h +0 -121
  225. data/vendor/prism/include/prism/util/pm_buffer.h +0 -236
  226. data/vendor/prism/include/prism/util/pm_char.h +0 -204
  227. data/vendor/prism/include/prism/util/pm_constant_pool.h +0 -218
  228. data/vendor/prism/include/prism/util/pm_integer.h +0 -130
  229. data/vendor/prism/include/prism/util/pm_memchr.h +0 -29
  230. data/vendor/prism/include/prism/util/pm_newline_list.h +0 -113
  231. data/vendor/prism/include/prism/util/pm_string.h +0 -200
  232. data/vendor/prism/src/pack.c +0 -509
  233. data/vendor/prism/src/util/pm_constant_pool.c +0 -342
  234. data/vendor/prism/src/util/pm_list.c +0 -49
  235. data/vendor/prism/src/util/pm_newline_list.c +0 -125
  236. data/vendor/prism/src/util/pm_string.c +0 -381
  237. data/vendor/prism/src/util/pm_strpbrk.c +0 -206
  238. data/vendor/prism/templates/include/prism/diagnostic.h.erb +0 -130
  239. data/vendor/prism/templates/rbi/prism/dsl.rbi.erb +0 -68
  240. data/vendor/prism/templates/rbi/prism/node.rbi.erb +0 -167
  241. data/vendor/prism/templates/rbi/prism/visitor.rbi.erb +0 -18
  242. data/vendor/prism/templates/sig/prism/_private/dot_visitor.rbs.erb +0 -45
  243. data/vendor/prism/templates/sig/prism/dsl.rbs.erb +0 -31
  244. data/vendor/prism/templates/sig/prism/mutation_compiler.rbs.erb +0 -7
  245. data/vendor/prism/templates/sig/prism/node.rbs.erb +0 -136
  246. data/vendor/prism/templates/sig/prism/visitor.rbs.erb +0 -17
  247. data/vendor/prism/templates/sig/prism.rbs.erb +0 -92
@@ -1,121 +0,0 @@
1
- /**
2
- * @file static_literals.h
3
- *
4
- * A set of static literal nodes that can be checked for duplicates.
5
- */
6
- #ifndef PRISM_STATIC_LITERALS_H
7
- #define PRISM_STATIC_LITERALS_H
8
-
9
- #include "prism/defines.h"
10
- #include "prism/ast.h"
11
- #include "prism/util/pm_newline_list.h"
12
-
13
- #include <assert.h>
14
- #include <stdbool.h>
15
-
16
- /**
17
- * An internal hash table for a set of nodes.
18
- */
19
- typedef struct {
20
- /** The array of nodes in the hash table. */
21
- pm_node_t **nodes;
22
-
23
- /** The size of the hash table. */
24
- uint32_t size;
25
-
26
- /** The space that has been allocated in the hash table. */
27
- uint32_t capacity;
28
- } pm_node_hash_t;
29
-
30
- /**
31
- * Certain sets of nodes (hash keys and when clauses) check for duplicate nodes
32
- * to alert the user of potential issues. To do this, we keep a set of the nodes
33
- * that have been seen so far, and compare whenever we find a new node.
34
- *
35
- * We bucket the nodes based on their type to minimize the number of comparisons
36
- * that need to be performed.
37
- */
38
- typedef struct {
39
- /**
40
- * This is the set of IntegerNode and SourceLineNode instances.
41
- */
42
- pm_node_hash_t integer_nodes;
43
-
44
- /**
45
- * This is the set of FloatNode instances.
46
- */
47
- pm_node_hash_t float_nodes;
48
-
49
- /**
50
- * This is the set of RationalNode and ImaginaryNode instances.
51
- */
52
- pm_node_hash_t number_nodes;
53
-
54
- /**
55
- * This is the set of StringNode and SourceFileNode instances.
56
- */
57
- pm_node_hash_t string_nodes;
58
-
59
- /**
60
- * This is the set of RegularExpressionNode instances.
61
- */
62
- pm_node_hash_t regexp_nodes;
63
-
64
- /**
65
- * This is the set of SymbolNode instances.
66
- */
67
- pm_node_hash_t symbol_nodes;
68
-
69
- /**
70
- * A pointer to the last TrueNode instance that was inserted, or NULL.
71
- */
72
- pm_node_t *true_node;
73
-
74
- /**
75
- * A pointer to the last FalseNode instance that was inserted, or NULL.
76
- */
77
- pm_node_t *false_node;
78
-
79
- /**
80
- * A pointer to the last NilNode instance that was inserted, or NULL.
81
- */
82
- pm_node_t *nil_node;
83
-
84
- /**
85
- * A pointer to the last SourceEncodingNode instance that was inserted, or
86
- * NULL.
87
- */
88
- pm_node_t *source_encoding_node;
89
- } pm_static_literals_t;
90
-
91
- /**
92
- * Add a node to the set of static literals.
93
- *
94
- * @param newline_list The list of newline offsets to use to calculate lines.
95
- * @param start_line The line number that the parser starts on.
96
- * @param literals The set of static literals to add the node to.
97
- * @param node The node to add to the set.
98
- * @param replace Whether to replace the previous node if one already exists.
99
- * @return A pointer to the node that is being overwritten, if there is one.
100
- */
101
- pm_node_t * pm_static_literals_add(const pm_newline_list_t *newline_list, int32_t start_line, pm_static_literals_t *literals, pm_node_t *node, bool replace);
102
-
103
- /**
104
- * Free the internal memory associated with the given static literals set.
105
- *
106
- * @param literals The set of static literals to free.
107
- */
108
- void pm_static_literals_free(pm_static_literals_t *literals);
109
-
110
- /**
111
- * Create a string-based representation of the given static literal.
112
- *
113
- * @param buffer The buffer to write the string to.
114
- * @param newline_list The list of newline offsets to use to calculate lines.
115
- * @param start_line The line number that the parser starts on.
116
- * @param encoding_name The name of the encoding of the source being parsed.
117
- * @param node The node to create a string representation of.
118
- */
119
- void pm_static_literal_inspect(pm_buffer_t *buffer, const pm_newline_list_t *newline_list, int32_t start_line, const char *encoding_name, const pm_node_t *node);
120
-
121
- #endif
@@ -1,236 +0,0 @@
1
- /**
2
- * @file pm_buffer.h
3
- *
4
- * A wrapper around a contiguous block of allocated memory.
5
- */
6
- #ifndef PRISM_BUFFER_H
7
- #define PRISM_BUFFER_H
8
-
9
- #include "prism/defines.h"
10
- #include "prism/util/pm_char.h"
11
-
12
- #include <assert.h>
13
- #include <stdbool.h>
14
- #include <stdint.h>
15
- #include <stdlib.h>
16
- #include <string.h>
17
-
18
- /**
19
- * A pm_buffer_t is a simple memory buffer that stores data in a contiguous
20
- * block of memory.
21
- */
22
- typedef struct {
23
- /** The length of the buffer in bytes. */
24
- size_t length;
25
-
26
- /** The capacity of the buffer in bytes that has been allocated. */
27
- size_t capacity;
28
-
29
- /** A pointer to the start of the buffer. */
30
- char *value;
31
- } pm_buffer_t;
32
-
33
- /**
34
- * Return the size of the pm_buffer_t struct.
35
- *
36
- * @returns The size of the pm_buffer_t struct.
37
- */
38
- PRISM_EXPORTED_FUNCTION size_t pm_buffer_sizeof(void);
39
-
40
- /**
41
- * Initialize a pm_buffer_t with the given capacity.
42
- *
43
- * @param buffer The buffer to initialize.
44
- * @param capacity The capacity of the buffer.
45
- * @returns True if the buffer was initialized successfully, false otherwise.
46
- */
47
- bool pm_buffer_init_capacity(pm_buffer_t *buffer, size_t capacity);
48
-
49
- /**
50
- * Initialize a pm_buffer_t with its default values.
51
- *
52
- * @param buffer The buffer to initialize.
53
- * @returns True if the buffer was initialized successfully, false otherwise.
54
- *
55
- * \public \memberof pm_buffer_t
56
- */
57
- PRISM_EXPORTED_FUNCTION bool pm_buffer_init(pm_buffer_t *buffer);
58
-
59
- /**
60
- * Return the value of the buffer.
61
- *
62
- * @param buffer The buffer to get the value of.
63
- * @returns The value of the buffer.
64
- *
65
- * \public \memberof pm_buffer_t
66
- */
67
- PRISM_EXPORTED_FUNCTION char * pm_buffer_value(const pm_buffer_t *buffer);
68
-
69
- /**
70
- * Return the length of the buffer.
71
- *
72
- * @param buffer The buffer to get the length of.
73
- * @returns The length of the buffer.
74
- *
75
- * \public \memberof pm_buffer_t
76
- */
77
- PRISM_EXPORTED_FUNCTION size_t pm_buffer_length(const pm_buffer_t *buffer);
78
-
79
- /**
80
- * Append the given amount of space as zeroes to the buffer.
81
- *
82
- * @param buffer The buffer to append to.
83
- * @param length The amount of space to append and zero.
84
- */
85
- void pm_buffer_append_zeroes(pm_buffer_t *buffer, size_t length);
86
-
87
- /**
88
- * Append a formatted string to the buffer.
89
- *
90
- * @param buffer The buffer to append to.
91
- * @param format The format string to append.
92
- * @param ... The arguments to the format string.
93
- */
94
- void pm_buffer_append_format(pm_buffer_t *buffer, const char *format, ...) PRISM_ATTRIBUTE_FORMAT(2, 3);
95
-
96
- /**
97
- * Append a string to the buffer.
98
- *
99
- * @param buffer The buffer to append to.
100
- * @param value The string to append.
101
- * @param length The length of the string to append.
102
- */
103
- void pm_buffer_append_string(pm_buffer_t *buffer, const char *value, size_t length);
104
-
105
- /**
106
- * Append a list of bytes to the buffer.
107
- *
108
- * @param buffer The buffer to append to.
109
- * @param value The bytes to append.
110
- * @param length The length of the bytes to append.
111
- */
112
- void pm_buffer_append_bytes(pm_buffer_t *buffer, const uint8_t *value, size_t length);
113
-
114
- /**
115
- * Append a single byte to the buffer.
116
- *
117
- * @param buffer The buffer to append to.
118
- * @param value The byte to append.
119
- */
120
- void pm_buffer_append_byte(pm_buffer_t *buffer, uint8_t value);
121
-
122
- /**
123
- * Append a 32-bit unsigned integer to the buffer as a variable-length integer.
124
- *
125
- * @param buffer The buffer to append to.
126
- * @param value The integer to append.
127
- */
128
- void pm_buffer_append_varuint(pm_buffer_t *buffer, uint32_t value);
129
-
130
- /**
131
- * Append a 32-bit signed integer to the buffer as a variable-length integer.
132
- *
133
- * @param buffer The buffer to append to.
134
- * @param value The integer to append.
135
- */
136
- void pm_buffer_append_varsint(pm_buffer_t *buffer, int32_t value);
137
-
138
- /**
139
- * Append a double to the buffer.
140
- *
141
- * @param buffer The buffer to append to.
142
- * @param value The double to append.
143
- */
144
- void pm_buffer_append_double(pm_buffer_t *buffer, double value);
145
-
146
- /**
147
- * Append a unicode codepoint to the buffer.
148
- *
149
- * @param buffer The buffer to append to.
150
- * @param value The character to append.
151
- * @returns True if the codepoint was valid and appended successfully, false
152
- * otherwise.
153
- */
154
- bool pm_buffer_append_unicode_codepoint(pm_buffer_t *buffer, uint32_t value);
155
-
156
- /**
157
- * The different types of escaping that can be performed by the buffer when
158
- * appending a slice of Ruby source code.
159
- */
160
- typedef enum {
161
- PM_BUFFER_ESCAPING_RUBY,
162
- PM_BUFFER_ESCAPING_JSON
163
- } pm_buffer_escaping_t;
164
-
165
- /**
166
- * Append a slice of source code to the buffer.
167
- *
168
- * @param buffer The buffer to append to.
169
- * @param source The source code to append.
170
- * @param length The length of the source code to append.
171
- * @param escaping The type of escaping to perform.
172
- */
173
- void pm_buffer_append_source(pm_buffer_t *buffer, const uint8_t *source, size_t length, pm_buffer_escaping_t escaping);
174
-
175
- /**
176
- * Prepend the given string to the buffer.
177
- *
178
- * @param buffer The buffer to prepend to.
179
- * @param value The string to prepend.
180
- * @param length The length of the string to prepend.
181
- */
182
- void pm_buffer_prepend_string(pm_buffer_t *buffer, const char *value, size_t length);
183
-
184
- /**
185
- * Concatenate one buffer onto another.
186
- *
187
- * @param destination The buffer to concatenate onto.
188
- * @param source The buffer to concatenate.
189
- */
190
- void pm_buffer_concat(pm_buffer_t *destination, const pm_buffer_t *source);
191
-
192
- /**
193
- * Clear the buffer by reducing its size to 0. This does not free the allocated
194
- * memory, but it does allow the buffer to be reused.
195
- *
196
- * @param buffer The buffer to clear.
197
- */
198
- void pm_buffer_clear(pm_buffer_t *buffer);
199
-
200
- /**
201
- * Strip the whitespace from the end of the buffer.
202
- *
203
- * @param buffer The buffer to strip.
204
- */
205
- void pm_buffer_rstrip(pm_buffer_t *buffer);
206
-
207
- /**
208
- * Checks if the buffer includes the given value.
209
- *
210
- * @param buffer The buffer to check.
211
- * @param value The value to check for.
212
- * @returns The index of the first occurrence of the value in the buffer, or
213
- * SIZE_MAX if the value is not found.
214
- */
215
- size_t pm_buffer_index(const pm_buffer_t *buffer, char value);
216
-
217
- /**
218
- * Insert the given string into the buffer at the given index.
219
- *
220
- * @param buffer The buffer to insert into.
221
- * @param index The index to insert at.
222
- * @param value The string to insert.
223
- * @param length The length of the string to insert.
224
- */
225
- void pm_buffer_insert(pm_buffer_t *buffer, size_t index, const char *value, size_t length);
226
-
227
- /**
228
- * Free the memory associated with the buffer.
229
- *
230
- * @param buffer The buffer to free.
231
- *
232
- * \public \memberof pm_buffer_t
233
- */
234
- PRISM_EXPORTED_FUNCTION void pm_buffer_free(pm_buffer_t *buffer);
235
-
236
- #endif
@@ -1,204 +0,0 @@
1
- /**
2
- * @file pm_char.h
3
- *
4
- * Functions for working with characters and strings.
5
- */
6
- #ifndef PRISM_CHAR_H
7
- #define PRISM_CHAR_H
8
-
9
- #include "prism/defines.h"
10
- #include "prism/util/pm_newline_list.h"
11
-
12
- #include <stdbool.h>
13
- #include <stddef.h>
14
-
15
- /**
16
- * Returns the number of characters at the start of the string that are
17
- * whitespace. Disallows searching past the given maximum number of characters.
18
- *
19
- * @param string The string to search.
20
- * @param length The maximum number of characters to search.
21
- * @return The number of characters at the start of the string that are
22
- * whitespace.
23
- */
24
- size_t pm_strspn_whitespace(const uint8_t *string, ptrdiff_t length);
25
-
26
- /**
27
- * Returns the number of characters at the start of the string that are
28
- * whitespace while also tracking the location of each newline. Disallows
29
- * searching past the given maximum number of characters.
30
- *
31
- * @param string The string to search.
32
- * @param length The maximum number of characters to search.
33
- * @param newline_list The list of newlines to populate.
34
- * @return The number of characters at the start of the string that are
35
- * whitespace.
36
- */
37
- size_t pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_newline_list_t *newline_list);
38
-
39
- /**
40
- * Returns the number of characters at the start of the string that are inline
41
- * whitespace. Disallows searching past the given maximum number of characters.
42
- *
43
- * @param string The string to search.
44
- * @param length The maximum number of characters to search.
45
- * @return The number of characters at the start of the string that are inline
46
- * whitespace.
47
- */
48
- size_t pm_strspn_inline_whitespace(const uint8_t *string, ptrdiff_t length);
49
-
50
- /**
51
- * Returns the number of characters at the start of the string that are decimal
52
- * digits. Disallows searching past the given maximum number of characters.
53
- *
54
- * @param string The string to search.
55
- * @param length The maximum number of characters to search.
56
- * @return The number of characters at the start of the string that are decimal
57
- * digits.
58
- */
59
- size_t pm_strspn_decimal_digit(const uint8_t *string, ptrdiff_t length);
60
-
61
- /**
62
- * Returns the number of characters at the start of the string that are
63
- * hexadecimal digits. Disallows searching past the given maximum number of
64
- * characters.
65
- *
66
- * @param string The string to search.
67
- * @param length The maximum number of characters to search.
68
- * @return The number of characters at the start of the string that are
69
- * hexadecimal digits.
70
- */
71
- size_t pm_strspn_hexadecimal_digit(const uint8_t *string, ptrdiff_t length);
72
-
73
- /**
74
- * Returns the number of characters at the start of the string that are octal
75
- * digits or underscores. Disallows searching past the given maximum number of
76
- * characters.
77
- *
78
- * If multiple underscores are found in a row or if an underscore is
79
- * found at the end of the number, then the invalid pointer is set to the index
80
- * of the first invalid underscore.
81
- *
82
- * @param string The string to search.
83
- * @param length The maximum number of characters to search.
84
- * @param invalid The pointer to set to the index of the first invalid
85
- * underscore.
86
- * @return The number of characters at the start of the string that are octal
87
- * digits or underscores.
88
- */
89
- size_t pm_strspn_octal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid);
90
-
91
- /**
92
- * Returns the number of characters at the start of the string that are decimal
93
- * digits or underscores. Disallows searching past the given maximum number of
94
- * characters.
95
- *
96
- * If multiple underscores are found in a row or if an underscore is
97
- * found at the end of the number, then the invalid pointer is set to the index
98
- * of the first invalid underscore.
99
- *
100
- * @param string The string to search.
101
- * @param length The maximum number of characters to search.
102
- * @param invalid The pointer to set to the index of the first invalid
103
- * underscore.
104
- * @return The number of characters at the start of the string that are decimal
105
- * digits or underscores.
106
- */
107
- size_t pm_strspn_decimal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid);
108
-
109
- /**
110
- * Returns the number of characters at the start of the string that are
111
- * hexadecimal digits or underscores. Disallows searching past the given maximum
112
- * number of characters.
113
- *
114
- * If multiple underscores are found in a row or if an underscore is
115
- * found at the end of the number, then the invalid pointer is set to the index
116
- * of the first invalid underscore.
117
- *
118
- * @param string The string to search.
119
- * @param length The maximum number of characters to search.
120
- * @param invalid The pointer to set to the index of the first invalid
121
- * underscore.
122
- * @return The number of characters at the start of the string that are
123
- * hexadecimal digits or underscores.
124
- */
125
- size_t pm_strspn_hexadecimal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid);
126
-
127
- /**
128
- * Returns the number of characters at the start of the string that are regexp
129
- * options. Disallows searching past the given maximum number of characters.
130
- *
131
- * @param string The string to search.
132
- * @param length The maximum number of characters to search.
133
- * @return The number of characters at the start of the string that are regexp
134
- * options.
135
- */
136
- size_t pm_strspn_regexp_option(const uint8_t *string, ptrdiff_t length);
137
-
138
- /**
139
- * Returns the number of characters at the start of the string that are binary
140
- * digits or underscores. Disallows searching past the given maximum number of
141
- * characters.
142
- *
143
- * If multiple underscores are found in a row or if an underscore is
144
- * found at the end of the number, then the invalid pointer is set to the index
145
- * of the first invalid underscore.
146
- *
147
- * @param string The string to search.
148
- * @param length The maximum number of characters to search.
149
- * @param invalid The pointer to set to the index of the first invalid
150
- * underscore.
151
- * @return The number of characters at the start of the string that are binary
152
- * digits or underscores.
153
- */
154
- size_t pm_strspn_binary_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid);
155
-
156
- /**
157
- * Returns true if the given character is a whitespace character.
158
- *
159
- * @param b The character to check.
160
- * @return True if the given character is a whitespace character.
161
- */
162
- bool pm_char_is_whitespace(const uint8_t b);
163
-
164
- /**
165
- * Returns true if the given character is an inline whitespace character.
166
- *
167
- * @param b The character to check.
168
- * @return True if the given character is an inline whitespace character.
169
- */
170
- bool pm_char_is_inline_whitespace(const uint8_t b);
171
-
172
- /**
173
- * Returns true if the given character is a binary digit.
174
- *
175
- * @param b The character to check.
176
- * @return True if the given character is a binary digit.
177
- */
178
- bool pm_char_is_binary_digit(const uint8_t b);
179
-
180
- /**
181
- * Returns true if the given character is an octal digit.
182
- *
183
- * @param b The character to check.
184
- * @return True if the given character is an octal digit.
185
- */
186
- bool pm_char_is_octal_digit(const uint8_t b);
187
-
188
- /**
189
- * Returns true if the given character is a decimal digit.
190
- *
191
- * @param b The character to check.
192
- * @return True if the given character is a decimal digit.
193
- */
194
- bool pm_char_is_decimal_digit(const uint8_t b);
195
-
196
- /**
197
- * Returns true if the given character is a hexadecimal digit.
198
- *
199
- * @param b The character to check.
200
- * @return True if the given character is a hexadecimal digit.
201
- */
202
- bool pm_char_is_hexadecimal_digit(const uint8_t b);
203
-
204
- #endif