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,128 +1,95 @@
1
- /**
2
- * @file encoding.h
3
- *
4
- * The encoding interface and implementations used by the parser.
5
- */
6
- #ifndef PRISM_ENCODING_H
7
- #define PRISM_ENCODING_H
8
-
9
- #include "prism/defines.h"
10
- #include "prism/util/pm_strncasecmp.h"
1
+ #ifndef PRISM_INTERNAL_ENCODING_H
2
+ #define PRISM_INTERNAL_ENCODING_H
11
3
 
12
- #include <assert.h>
13
4
  #include <stdbool.h>
14
5
  #include <stddef.h>
15
6
  #include <stdint.h>
16
7
 
17
- /**
8
+ /*
18
9
  * This struct defines the functions necessary to implement the encoding
19
10
  * interface so we can determine how many bytes the subsequent character takes.
20
11
  * Each callback should return the number of bytes, or 0 if the next bytes are
21
12
  * invalid for the encoding and type.
22
13
  */
23
14
  typedef struct {
24
- /**
15
+ /*
25
16
  * Return the number of bytes that the next character takes if it is valid
26
17
  * in the encoding. Does not read more than n bytes. It is assumed that n is
27
18
  * at least 1.
28
19
  */
29
20
  size_t (*char_width)(const uint8_t *b, ptrdiff_t n);
30
21
 
31
- /**
22
+ /*
32
23
  * Return the number of bytes that the next character takes if it is valid
33
24
  * in the encoding and is alphabetical. Does not read more than n bytes. It
34
25
  * is assumed that n is at least 1.
35
26
  */
36
27
  size_t (*alpha_char)(const uint8_t *b, ptrdiff_t n);
37
28
 
38
- /**
29
+ /*
39
30
  * Return the number of bytes that the next character takes if it is valid
40
31
  * in the encoding and is alphanumeric. Does not read more than n bytes. It
41
32
  * is assumed that n is at least 1.
42
33
  */
43
34
  size_t (*alnum_char)(const uint8_t *b, ptrdiff_t n);
44
35
 
45
- /**
36
+ /*
46
37
  * Return true if the next character is valid in the encoding and is an
47
38
  * uppercase character. Does not read more than n bytes. It is assumed that
48
39
  * n is at least 1.
49
40
  */
50
41
  bool (*isupper_char)(const uint8_t *b, ptrdiff_t n);
51
42
 
52
- /**
43
+ /*
53
44
  * The name of the encoding. This should correspond to a value that can be
54
45
  * passed to Encoding.find in Ruby.
55
46
  */
56
47
  const char *name;
57
48
 
58
- /**
59
- * Return true if the encoding is a multibyte encoding.
60
- */
49
+ /* Return true if the encoding is a multibyte encoding. */
61
50
  bool multibyte;
62
51
  } pm_encoding_t;
63
52
 
64
- /**
53
+ /*
65
54
  * All of the lookup tables use the first bit of each embedded byte to indicate
66
55
  * whether the codepoint is alphabetical.
67
56
  */
68
57
  #define PRISM_ENCODING_ALPHABETIC_BIT 1 << 0
69
58
 
70
- /**
59
+ /*
71
60
  * All of the lookup tables use the second bit of each embedded byte to indicate
72
61
  * whether the codepoint is alphanumeric.
73
62
  */
74
63
  #define PRISM_ENCODING_ALPHANUMERIC_BIT 1 << 1
75
64
 
76
- /**
65
+ /*
77
66
  * All of the lookup tables use the third bit of each embedded byte to indicate
78
67
  * whether the codepoint is uppercase.
79
68
  */
80
69
  #define PRISM_ENCODING_UPPERCASE_BIT 1 << 2
81
70
 
82
- /**
83
- * Return the size of the next character in the UTF-8 encoding.
84
- *
85
- * @param b The bytes to read.
86
- * @param n The number of bytes that can be read.
87
- * @returns The number of bytes that the next character takes if it is valid in
88
- * the encoding, or 0 if it is not.
89
- */
71
+ /* Return the size of the next character in the UTF-8 encoding. */
90
72
  size_t pm_encoding_utf_8_char_width(const uint8_t *b, ptrdiff_t n);
91
73
 
92
- /**
74
+ /*
93
75
  * Return the size of the next character in the UTF-8 encoding if it is an
94
76
  * alphabetical character.
95
- *
96
- * @param b The bytes to read.
97
- * @param n The number of bytes that can be read.
98
- * @returns The number of bytes that the next character takes if it is valid in
99
- * the encoding, or 0 if it is not.
100
77
  */
101
78
  size_t pm_encoding_utf_8_alpha_char(const uint8_t *b, ptrdiff_t n);
102
79
 
103
- /**
80
+ /*
104
81
  * Return the size of the next character in the UTF-8 encoding if it is an
105
82
  * alphanumeric character.
106
- *
107
- * @param b The bytes to read.
108
- * @param n The number of bytes that can be read.
109
- * @returns The number of bytes that the next character takes if it is valid in
110
- * the encoding, or 0 if it is not.
111
83
  */
112
84
  size_t pm_encoding_utf_8_alnum_char(const uint8_t *b, ptrdiff_t n);
113
85
 
114
- /**
86
+ /*
115
87
  * Return true if the next character in the UTF-8 encoding if it is an uppercase
116
88
  * character.
117
- *
118
- * @param b The bytes to read.
119
- * @param n The number of bytes that can be read.
120
- * @returns True if the next character is valid in the encoding and is an
121
- * uppercase character, or false if it is not.
122
89
  */
123
90
  bool pm_encoding_utf_8_isupper_char(const uint8_t *b, ptrdiff_t n);
124
91
 
125
- /**
92
+ /*
126
93
  * This lookup table is referenced in both the UTF-8 encoding file and the
127
94
  * parser directly in order to speed up the default encoding processing. It is
128
95
  * used to indicate whether a character is alphabetical, alphanumeric, or
@@ -130,9 +97,7 @@ bool pm_encoding_utf_8_isupper_char(const uint8_t *b, ptrdiff_t n);
130
97
  */
131
98
  extern const uint8_t pm_encoding_unicode_table[256];
132
99
 
133
- /**
134
- * These are all of the encodings that prism supports.
135
- */
100
+ /* These are all of the encodings that prism supports. */
136
101
  typedef enum {
137
102
  PM_ENCODING_UTF_8 = 0,
138
103
  PM_ENCODING_US_ASCII,
@@ -140,8 +105,8 @@ typedef enum {
140
105
  PM_ENCODING_EUC_JP,
141
106
  PM_ENCODING_WINDOWS_31J,
142
107
 
143
- // We optionally support excluding the full set of encodings to only support the
144
- // minimum necessary to process Ruby code without encoding comments.
108
+ /* We optionally support excluding the full set of encodings to only support the
109
+ * minimum necessary to process Ruby code without encoding comments. */
145
110
  #ifndef PRISM_ENCODING_EXCLUDE_FULL
146
111
  PM_ENCODING_BIG5,
147
112
  PM_ENCODING_BIG5_HKSCS,
@@ -233,50 +198,44 @@ typedef enum {
233
198
  PM_ENCODING_MAXIMUM
234
199
  } pm_encoding_type_t;
235
200
 
236
- /**
237
- * This is the table of all of the encodings that prism supports.
238
- */
201
+ /* This is the table of all of the encodings that prism supports. */
239
202
  extern const pm_encoding_t pm_encodings[PM_ENCODING_MAXIMUM];
240
203
 
241
- /**
204
+ /*
242
205
  * This is the default UTF-8 encoding. We need a reference to it to quickly
243
206
  * create parsers.
244
207
  */
245
208
  #define PM_ENCODING_UTF_8_ENTRY (&pm_encodings[PM_ENCODING_UTF_8])
246
209
 
247
- /**
210
+ /*
248
211
  * This is the US-ASCII encoding. We need a reference to it to be able to
249
212
  * compare against it when a string is being created because it could possibly
250
213
  * need to fall back to ASCII-8BIT.
251
214
  */
252
215
  #define PM_ENCODING_US_ASCII_ENTRY (&pm_encodings[PM_ENCODING_US_ASCII])
253
216
 
254
- /**
217
+ /*
255
218
  * This is the ASCII-8BIT encoding. We need a reference to it so that pm_strpbrk
256
219
  * can compare against it because invalid multibyte characters are not a thing
257
220
  * in this encoding. It is also needed for handling Regexp encoding flags.
258
221
  */
259
222
  #define PM_ENCODING_ASCII_8BIT_ENTRY (&pm_encodings[PM_ENCODING_ASCII_8BIT])
260
223
 
261
- /**
224
+ /*
262
225
  * This is the EUC-JP encoding. We need a reference to it to quickly process
263
226
  * regular expression modifiers.
264
227
  */
265
228
  #define PM_ENCODING_EUC_JP_ENTRY (&pm_encodings[PM_ENCODING_EUC_JP])
266
229
 
267
- /**
230
+ /*
268
231
  * This is the Windows-31J encoding. We need a reference to it to quickly
269
232
  * process regular expression modifiers.
270
233
  */
271
234
  #define PM_ENCODING_WINDOWS_31J_ENTRY (&pm_encodings[PM_ENCODING_WINDOWS_31J])
272
235
 
273
- /**
236
+ /*
274
237
  * Parse the given name of an encoding and return a pointer to the corresponding
275
238
  * encoding struct if one can be found, otherwise return NULL.
276
- *
277
- * @param start A pointer to the first byte of the name.
278
- * @param end A pointer to the last byte of the name.
279
- * @returns A pointer to the encoding struct if one is found, otherwise NULL.
280
239
  */
281
240
  const pm_encoding_t * pm_encoding_find(const uint8_t *start, const uint8_t *end);
282
241
 
@@ -0,0 +1,68 @@
1
+ /*
2
+ * This module provides functions for working with arbitrary-sized integers.
3
+ */
4
+ #ifndef PRISM_INTERNAL_INTEGER_H
5
+ #define PRISM_INTERNAL_INTEGER_H
6
+
7
+ #include "prism/buffer.h"
8
+ #include "prism/integer.h"
9
+
10
+ #include <stdint.h>
11
+
12
+ /*
13
+ * An enum controlling the base of an integer. It is expected that the base is
14
+ * already known before parsing the integer, even though it could be derived
15
+ * from the string itself.
16
+ */
17
+ typedef enum {
18
+ /* The default decimal base, with no prefix. Leading 0s will be ignored. */
19
+ PM_INTEGER_BASE_DEFAULT,
20
+
21
+ /* The binary base, indicated by a 0b or 0B prefix. */
22
+ PM_INTEGER_BASE_BINARY,
23
+
24
+ /* The octal base, indicated by a 0, 0o, or 0O prefix. */
25
+ PM_INTEGER_BASE_OCTAL,
26
+
27
+ /* The decimal base, indicated by a 0d, 0D, or empty prefix. */
28
+ PM_INTEGER_BASE_DECIMAL,
29
+
30
+ /* The hexadecimal base, indicated by a 0x or 0X prefix. */
31
+ PM_INTEGER_BASE_HEXADECIMAL,
32
+
33
+ /*
34
+ * An unknown base, in which case pm_integer_parse will derive it based on
35
+ * the content of the string. This is less efficient and does more
36
+ * comparisons, so if callers know the base ahead of time, they should use
37
+ * that instead.
38
+ */
39
+ PM_INTEGER_BASE_UNKNOWN
40
+ } pm_integer_base_t;
41
+
42
+ /*
43
+ * Parse an integer from a string. This assumes that the format of the integer
44
+ * has already been validated, as internal validation checks are not performed
45
+ * here.
46
+ */
47
+ void pm_integer_parse(pm_integer_t *integer, pm_integer_base_t base, const uint8_t *start, const uint8_t *end);
48
+
49
+ /*
50
+ * Compare two integers. This function returns -1 if the left integer is less
51
+ * than the right integer, 0 if they are equal, and 1 if the left integer is
52
+ * greater than the right integer.
53
+ */
54
+ int pm_integer_compare(const pm_integer_t *left, const pm_integer_t *right);
55
+
56
+ /*
57
+ * Reduce a ratio of integers to its simplest form.
58
+ *
59
+ * If either the numerator or denominator do not fit into a 32-bit integer, then
60
+ * this function is a no-op. In the future, we may consider reducing even the
61
+ * larger numbers, but for now we're going to keep it simple.
62
+ */
63
+ void pm_integers_reduce(pm_integer_t *numerator, pm_integer_t *denominator);
64
+
65
+ /* Convert an integer to a decimal string. */
66
+ void pm_integer_string(pm_buffer_t *buffer, const pm_integer_t *integer);
67
+
68
+ #endif
@@ -0,0 +1,16 @@
1
+ #ifndef PRISM_INTERNAL_ISINF_H
2
+ #define PRISM_INTERNAL_ISINF_H
3
+
4
+ /*
5
+ * isinf on POSIX systems accepts a float, a double, or a long double. But mingw
6
+ * didn't provide an isinf macro, only an isinf function that only accepts
7
+ * floats, so we need to use _finite instead.
8
+ */
9
+ #ifdef __MINGW64__
10
+ #include <float.h>
11
+ #define PRISM_ISINF(x) (!_finite(x))
12
+ #else
13
+ #define PRISM_ISINF(x) isinf(x)
14
+ #endif
15
+
16
+ #endif
@@ -0,0 +1,34 @@
1
+ #ifndef PRISM_INTERNAL_LINE_OFFSET_LIST_H
2
+ #define PRISM_INTERNAL_LINE_OFFSET_LIST_H
3
+
4
+ #include "prism/compiler/force_inline.h"
5
+
6
+ #include "prism/arena.h"
7
+ #include "prism/line_offset_list.h"
8
+
9
+ /* Initialize a new line offset list with the given capacity. */
10
+ void pm_line_offset_list_init(pm_arena_t *arena, pm_line_offset_list_t *list, size_t capacity);
11
+
12
+ /* Clear out the offsets that have been appended to the list. */
13
+ void pm_line_offset_list_clear(pm_line_offset_list_t *list);
14
+
15
+ /* Append a new offset to the list (slow path with resize). */
16
+ void pm_line_offset_list_append_slow(pm_arena_t *arena, pm_line_offset_list_t *list, uint32_t cursor);
17
+
18
+ /* Append a new offset to the list. */
19
+ static PRISM_FORCE_INLINE void
20
+ pm_line_offset_list_append(pm_arena_t *arena, pm_line_offset_list_t *list, uint32_t cursor) {
21
+ if (list->size < list->capacity) {
22
+ list->offsets[list->size++] = cursor;
23
+ } else {
24
+ pm_line_offset_list_append_slow(arena, list, cursor);
25
+ }
26
+ }
27
+
28
+ /*
29
+ * Returns the line of the given offset. If the offset is not in the list, the
30
+ * line of the closest offset less than the given offset is returned.
31
+ */
32
+ int32_t pm_line_offset_list_line(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line);
33
+
34
+ #endif
@@ -1,19 +1,9 @@
1
- /**
2
- * @file pm_list.h
3
- *
4
- * An abstract linked list.
5
- */
6
- #ifndef PRISM_LIST_H
7
- #define PRISM_LIST_H
1
+ #ifndef PRISM_INTERNAL_LIST_H
2
+ #define PRISM_INTERNAL_LIST_H
8
3
 
9
- #include "prism/defines.h"
10
-
11
- #include <stdbool.h>
12
4
  #include <stddef.h>
13
- #include <stdint.h>
14
- #include <stdlib.h>
15
5
 
16
- /**
6
+ /*
17
7
  * This struct represents an abstract linked list that provides common
18
8
  * functionality. It is meant to be used any time a linked list is necessary to
19
9
  * store data.
@@ -44,60 +34,29 @@
44
34
  * iteration and appending of new nodes.
45
35
  */
46
36
  typedef struct pm_list_node {
47
- /** A pointer to the next node in the list. */
37
+ /* A pointer to the next node in the list. */
48
38
  struct pm_list_node *next;
49
39
  } pm_list_node_t;
50
40
 
51
- /**
41
+ /*
52
42
  * This represents the overall linked list. It keeps a pointer to the head and
53
43
  * tail so that iteration is easy and pushing new nodes is easy.
54
44
  */
55
45
  typedef struct {
56
- /** The size of the list. */
46
+ /* The size of the list. */
57
47
  size_t size;
58
48
 
59
- /** A pointer to the head of the list. */
49
+ /* A pointer to the head of the list. */
60
50
  pm_list_node_t *head;
61
51
 
62
- /** A pointer to the tail of the list. */
52
+ /* A pointer to the tail of the list. */
63
53
  pm_list_node_t *tail;
64
54
  } pm_list_t;
65
55
 
66
- /**
67
- * Returns true if the given list is empty.
68
- *
69
- * @param list The list to check.
70
- * @return True if the given list is empty, otherwise false.
71
- *
72
- * \public \memberof pm_list_t
73
- */
74
- PRISM_EXPORTED_FUNCTION bool pm_list_empty_p(pm_list_t *list);
75
-
76
- /**
77
- * Returns the size of the list.
78
- *
79
- * @param list The list to check.
80
- * @return The size of the list.
81
- *
82
- * \public \memberof pm_list_t
83
- */
84
- PRISM_EXPORTED_FUNCTION size_t pm_list_size(pm_list_t *list);
56
+ /* Returns the size of the list. */
57
+ size_t pm_list_size(pm_list_t *list);
85
58
 
86
- /**
87
- * Append a node to the given list.
88
- *
89
- * @param list The list to append to.
90
- * @param node The node to append.
91
- */
59
+ /* Append a node to the given list. */
92
60
  void pm_list_append(pm_list_t *list, pm_list_node_t *node);
93
61
 
94
- /**
95
- * Deallocate the internal state of the given list.
96
- *
97
- * @param list The list to free.
98
- *
99
- * \public \memberof pm_list_t
100
- */
101
- PRISM_EXPORTED_FUNCTION void pm_list_free(pm_list_t *list);
102
-
103
62
  #endif
@@ -0,0 +1,23 @@
1
+ #ifndef PRISM_INTERNAL_MAGIC_COMMENTS_H
2
+ #define PRISM_INTERNAL_MAGIC_COMMENTS_H
3
+
4
+ #include "prism/magic_comments.h"
5
+
6
+ #include "prism/internal/list.h"
7
+
8
+ /*
9
+ * This is a node in the linked list of magic comments that we've found while
10
+ * parsing.
11
+ */
12
+ struct pm_magic_comment_t {
13
+ /* The embedded base node. */
14
+ pm_list_node_t node;
15
+
16
+ /* The key of the magic comment. */
17
+ pm_location_t key;
18
+
19
+ /* The value of the magic comment. */
20
+ pm_location_t value;
21
+ };
22
+
23
+ #endif
@@ -0,0 +1,15 @@
1
+ #ifndef PRISM_INTERNAL_MEMCHR_H
2
+ #define PRISM_INTERNAL_MEMCHR_H
3
+
4
+ #include "prism/internal/encoding.h"
5
+
6
+ #include <stddef.h>
7
+
8
+ /*
9
+ * We need to roll our own memchr to handle cases where the encoding changes and
10
+ * we need to search for a character in a buffer that could be the trailing byte
11
+ * of a multibyte character.
12
+ */
13
+ const void * pm_memchr(const void *source, int character, size_t number, bool encoding_changed, const pm_encoding_t *encoding);
14
+
15
+ #endif
@@ -0,0 +1,42 @@
1
+ #ifndef PRISM_INTERNAL_NODE_H
2
+ #define PRISM_INTERNAL_NODE_H
3
+
4
+ #include "prism/node.h"
5
+
6
+ #include "prism/compiler/force_inline.h"
7
+
8
+ #include "prism/arena.h"
9
+
10
+ /* The offset of the start of the given location. */
11
+ #define PM_LOCATION_START(location_) ((location_)->start)
12
+
13
+ /* The offset just past the end of the given location. */
14
+ #define PM_LOCATION_END(location_) ((location_)->start + (location_)->length)
15
+
16
+ /*
17
+ * Slow path for pm_node_list_append_inline: grow the list and append the node.
18
+ * Do not call directly — use pm_node_list_append_inline instead.
19
+ */
20
+ void pm_node_list_append_slow(pm_arena_t *arena, pm_node_list_t *list, pm_node_t *node);
21
+
22
+ /*
23
+ * Append a new node onto the end of the node list, handling the common case
24
+ * inline and growing the list through pm_node_list_append_slow. This is the
25
+ * version for prism's own code; others call the exported pm_node_list_append.
26
+ */
27
+ static PRISM_FORCE_INLINE void
28
+ pm_node_list_append_inline(pm_arena_t *arena, pm_node_list_t *list, pm_node_t *node) {
29
+ if (list->size < list->capacity) {
30
+ list->nodes[list->size++] = node;
31
+ } else {
32
+ pm_node_list_append_slow(arena, list, node);
33
+ }
34
+ }
35
+
36
+ /* Prepend a new node onto the beginning of the node list. */
37
+ void pm_node_list_prepend(pm_arena_t *arena, pm_node_list_t *list, pm_node_t *node);
38
+
39
+ /* Concatenate the given node list onto the end of the other node list. */
40
+ void pm_node_list_concat(pm_arena_t *arena, pm_node_list_t *list, pm_node_list_t *other);
41
+
42
+ #endif