jruby-prism-parser 0.23.0.pre.SNAPSHOT-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +401 -0
  3. data/CODE_OF_CONDUCT.md +76 -0
  4. data/CONTRIBUTING.md +62 -0
  5. data/LICENSE.md +7 -0
  6. data/Makefile +101 -0
  7. data/README.md +98 -0
  8. data/config.yml +2902 -0
  9. data/docs/build_system.md +91 -0
  10. data/docs/configuration.md +64 -0
  11. data/docs/cruby_compilation.md +27 -0
  12. data/docs/design.md +53 -0
  13. data/docs/encoding.md +121 -0
  14. data/docs/fuzzing.md +88 -0
  15. data/docs/heredocs.md +36 -0
  16. data/docs/javascript.md +118 -0
  17. data/docs/local_variable_depth.md +229 -0
  18. data/docs/mapping.md +117 -0
  19. data/docs/parser_translation.md +34 -0
  20. data/docs/parsing_rules.md +19 -0
  21. data/docs/releasing.md +98 -0
  22. data/docs/ripper.md +36 -0
  23. data/docs/ruby_api.md +43 -0
  24. data/docs/ruby_parser_translation.md +19 -0
  25. data/docs/serialization.md +209 -0
  26. data/docs/testing.md +55 -0
  27. data/ext/prism/api_node.c +5098 -0
  28. data/ext/prism/api_pack.c +267 -0
  29. data/ext/prism/extconf.rb +110 -0
  30. data/ext/prism/extension.c +1155 -0
  31. data/ext/prism/extension.h +18 -0
  32. data/include/prism/ast.h +5807 -0
  33. data/include/prism/defines.h +102 -0
  34. data/include/prism/diagnostic.h +339 -0
  35. data/include/prism/encoding.h +265 -0
  36. data/include/prism/node.h +57 -0
  37. data/include/prism/options.h +230 -0
  38. data/include/prism/pack.h +152 -0
  39. data/include/prism/parser.h +732 -0
  40. data/include/prism/prettyprint.h +26 -0
  41. data/include/prism/regexp.h +33 -0
  42. data/include/prism/util/pm_buffer.h +155 -0
  43. data/include/prism/util/pm_char.h +205 -0
  44. data/include/prism/util/pm_constant_pool.h +209 -0
  45. data/include/prism/util/pm_list.h +97 -0
  46. data/include/prism/util/pm_memchr.h +29 -0
  47. data/include/prism/util/pm_newline_list.h +93 -0
  48. data/include/prism/util/pm_state_stack.h +42 -0
  49. data/include/prism/util/pm_string.h +150 -0
  50. data/include/prism/util/pm_string_list.h +44 -0
  51. data/include/prism/util/pm_strncasecmp.h +32 -0
  52. data/include/prism/util/pm_strpbrk.h +46 -0
  53. data/include/prism/version.h +29 -0
  54. data/include/prism.h +289 -0
  55. data/jruby-prism.jar +0 -0
  56. data/lib/prism/compiler.rb +486 -0
  57. data/lib/prism/debug.rb +206 -0
  58. data/lib/prism/desugar_compiler.rb +207 -0
  59. data/lib/prism/dispatcher.rb +2150 -0
  60. data/lib/prism/dot_visitor.rb +4634 -0
  61. data/lib/prism/dsl.rb +785 -0
  62. data/lib/prism/ffi.rb +346 -0
  63. data/lib/prism/lex_compat.rb +908 -0
  64. data/lib/prism/mutation_compiler.rb +753 -0
  65. data/lib/prism/node.rb +17864 -0
  66. data/lib/prism/node_ext.rb +212 -0
  67. data/lib/prism/node_inspector.rb +68 -0
  68. data/lib/prism/pack.rb +224 -0
  69. data/lib/prism/parse_result/comments.rb +177 -0
  70. data/lib/prism/parse_result/newlines.rb +64 -0
  71. data/lib/prism/parse_result.rb +498 -0
  72. data/lib/prism/pattern.rb +250 -0
  73. data/lib/prism/serialize.rb +1354 -0
  74. data/lib/prism/translation/parser/compiler.rb +1838 -0
  75. data/lib/prism/translation/parser/lexer.rb +335 -0
  76. data/lib/prism/translation/parser/rubocop.rb +37 -0
  77. data/lib/prism/translation/parser.rb +178 -0
  78. data/lib/prism/translation/ripper.rb +577 -0
  79. data/lib/prism/translation/ruby_parser.rb +1521 -0
  80. data/lib/prism/translation.rb +11 -0
  81. data/lib/prism/version.rb +3 -0
  82. data/lib/prism/visitor.rb +495 -0
  83. data/lib/prism.rb +99 -0
  84. data/prism.gemspec +135 -0
  85. data/rbi/prism.rbi +7767 -0
  86. data/rbi/prism_static.rbi +207 -0
  87. data/sig/prism.rbs +4773 -0
  88. data/sig/prism_static.rbs +201 -0
  89. data/src/diagnostic.c +400 -0
  90. data/src/encoding.c +5132 -0
  91. data/src/node.c +2786 -0
  92. data/src/options.c +213 -0
  93. data/src/pack.c +493 -0
  94. data/src/prettyprint.c +8881 -0
  95. data/src/prism.c +18406 -0
  96. data/src/regexp.c +638 -0
  97. data/src/serialize.c +1554 -0
  98. data/src/token_type.c +700 -0
  99. data/src/util/pm_buffer.c +190 -0
  100. data/src/util/pm_char.c +318 -0
  101. data/src/util/pm_constant_pool.c +322 -0
  102. data/src/util/pm_list.c +49 -0
  103. data/src/util/pm_memchr.c +35 -0
  104. data/src/util/pm_newline_list.c +84 -0
  105. data/src/util/pm_state_stack.c +25 -0
  106. data/src/util/pm_string.c +203 -0
  107. data/src/util/pm_string_list.c +28 -0
  108. data/src/util/pm_strncasecmp.c +24 -0
  109. data/src/util/pm_strpbrk.c +180 -0
  110. metadata +156 -0
@@ -0,0 +1,190 @@
1
+ #include "prism/util/pm_buffer.h"
2
+
3
+ /**
4
+ * Return the size of the pm_buffer_t struct.
5
+ */
6
+ size_t
7
+ pm_buffer_sizeof(void) {
8
+ return sizeof(pm_buffer_t);
9
+ }
10
+
11
+ /**
12
+ * Initialize a pm_buffer_t with the given capacity.
13
+ */
14
+ bool
15
+ pm_buffer_init_capacity(pm_buffer_t *buffer, size_t capacity) {
16
+ buffer->length = 0;
17
+ buffer->capacity = capacity;
18
+
19
+ buffer->value = (char *) malloc(capacity);
20
+ return buffer->value != NULL;
21
+ }
22
+
23
+ /**
24
+ * Initialize a pm_buffer_t with its default values.
25
+ */
26
+ bool
27
+ pm_buffer_init(pm_buffer_t *buffer) {
28
+ return pm_buffer_init_capacity(buffer, 1024);
29
+ }
30
+
31
+ /**
32
+ * Return the value of the buffer.
33
+ */
34
+ char *
35
+ pm_buffer_value(pm_buffer_t *buffer) {
36
+ return buffer->value;
37
+ }
38
+
39
+ /**
40
+ * Return the length of the buffer.
41
+ */
42
+ size_t
43
+ pm_buffer_length(pm_buffer_t *buffer) {
44
+ return buffer->length;
45
+ }
46
+
47
+ /**
48
+ * Append the given amount of space to the buffer.
49
+ */
50
+ static inline void
51
+ pm_buffer_append_length(pm_buffer_t *buffer, size_t length) {
52
+ size_t next_length = buffer->length + length;
53
+
54
+ if (next_length > buffer->capacity) {
55
+ if (buffer->capacity == 0) {
56
+ buffer->capacity = 1;
57
+ }
58
+
59
+ while (next_length > buffer->capacity) {
60
+ buffer->capacity *= 2;
61
+ }
62
+
63
+ buffer->value = realloc(buffer->value, buffer->capacity);
64
+ }
65
+
66
+ buffer->length = next_length;
67
+ }
68
+
69
+ /**
70
+ * Append a generic pointer to memory to the buffer.
71
+ */
72
+ static inline void
73
+ pm_buffer_append(pm_buffer_t *buffer, const void *source, size_t length) {
74
+ size_t cursor = buffer->length;
75
+ pm_buffer_append_length(buffer, length);
76
+ memcpy(buffer->value + cursor, source, length);
77
+ }
78
+
79
+ /**
80
+ * Append the given amount of space as zeroes to the buffer.
81
+ */
82
+ void
83
+ pm_buffer_append_zeroes(pm_buffer_t *buffer, size_t length) {
84
+ size_t cursor = buffer->length;
85
+ pm_buffer_append_length(buffer, length);
86
+ memset(buffer->value + cursor, 0, length);
87
+ }
88
+
89
+ /**
90
+ * Append a formatted string to the buffer.
91
+ */
92
+ void
93
+ pm_buffer_append_format(pm_buffer_t *buffer, const char *format, ...) {
94
+ va_list arguments;
95
+ va_start(arguments, format);
96
+ int result = vsnprintf(NULL, 0, format, arguments);
97
+ va_end(arguments);
98
+
99
+ if (result < 0) return;
100
+ size_t length = (size_t) (result + 1);
101
+
102
+ size_t cursor = buffer->length;
103
+ pm_buffer_append_length(buffer, length);
104
+
105
+ va_start(arguments, format);
106
+ vsnprintf(buffer->value + cursor, length, format, arguments);
107
+ va_end(arguments);
108
+
109
+ buffer->length--;
110
+ }
111
+
112
+ /**
113
+ * Append a string to the buffer.
114
+ */
115
+ void
116
+ pm_buffer_append_string(pm_buffer_t *buffer, const char *value, size_t length) {
117
+ pm_buffer_append(buffer, value, length);
118
+ }
119
+
120
+ /**
121
+ * Append a list of bytes to the buffer.
122
+ */
123
+ void
124
+ pm_buffer_append_bytes(pm_buffer_t *buffer, const uint8_t *value, size_t length) {
125
+ pm_buffer_append(buffer, (const char *) value, length);
126
+ }
127
+
128
+ /**
129
+ * Append a single byte to the buffer.
130
+ */
131
+ void
132
+ pm_buffer_append_byte(pm_buffer_t *buffer, uint8_t value) {
133
+ const void *source = &value;
134
+ pm_buffer_append(buffer, source, sizeof(uint8_t));
135
+ }
136
+
137
+ /**
138
+ * Append a 32-bit unsigned integer to the buffer as a variable-length integer.
139
+ */
140
+ void
141
+ pm_buffer_append_varuint(pm_buffer_t *buffer, uint32_t value) {
142
+ if (value < 128) {
143
+ pm_buffer_append_byte(buffer, (uint8_t) value);
144
+ } else {
145
+ uint32_t n = value;
146
+ while (n >= 128) {
147
+ pm_buffer_append_byte(buffer, (uint8_t) (n | 128));
148
+ n >>= 7;
149
+ }
150
+ pm_buffer_append_byte(buffer, (uint8_t) n);
151
+ }
152
+ }
153
+
154
+ /**
155
+ * Append a 32-bit signed integer to the buffer as a variable-length integer.
156
+ */
157
+ void
158
+ pm_buffer_append_varsint(pm_buffer_t *buffer, int32_t value) {
159
+ uint32_t unsigned_int = ((uint32_t)(value) << 1) ^ ((uint32_t)(value >> 31));
160
+ pm_buffer_append_varuint(buffer, unsigned_int);
161
+ }
162
+
163
+ /**
164
+ * Prepend the given string to the buffer.
165
+ */
166
+ void
167
+ pm_buffer_prepend_string(pm_buffer_t *buffer, const char *value, size_t length) {
168
+ size_t cursor = buffer->length;
169
+ pm_buffer_append_length(buffer, length);
170
+ memmove(buffer->value + length, buffer->value, cursor);
171
+ memcpy(buffer->value, value, length);
172
+ }
173
+
174
+ /**
175
+ * Concatenate one buffer onto another.
176
+ */
177
+ void
178
+ pm_buffer_concat(pm_buffer_t *destination, const pm_buffer_t *source) {
179
+ if (source->length > 0) {
180
+ pm_buffer_append(destination, source->value, source->length);
181
+ }
182
+ }
183
+
184
+ /**
185
+ * Free the memory associated with the buffer.
186
+ */
187
+ void
188
+ pm_buffer_free(pm_buffer_t *buffer) {
189
+ free(buffer->value);
190
+ }
@@ -0,0 +1,318 @@
1
+ #include "prism/util/pm_char.h"
2
+
3
+ #define PRISM_CHAR_BIT_WHITESPACE (1 << 0)
4
+ #define PRISM_CHAR_BIT_INLINE_WHITESPACE (1 << 1)
5
+ #define PRISM_CHAR_BIT_REGEXP_OPTION (1 << 2)
6
+
7
+ #define PRISM_NUMBER_BIT_BINARY_DIGIT (1 << 0)
8
+ #define PRISM_NUMBER_BIT_BINARY_NUMBER (1 << 1)
9
+ #define PRISM_NUMBER_BIT_OCTAL_DIGIT (1 << 2)
10
+ #define PRISM_NUMBER_BIT_OCTAL_NUMBER (1 << 3)
11
+ #define PRISM_NUMBER_BIT_DECIMAL_DIGIT (1 << 4)
12
+ #define PRISM_NUMBER_BIT_DECIMAL_NUMBER (1 << 5)
13
+ #define PRISM_NUMBER_BIT_HEXADECIMAL_DIGIT (1 << 6)
14
+ #define PRISM_NUMBER_BIT_HEXADECIMAL_NUMBER (1 << 7)
15
+
16
+ static const uint8_t pm_byte_table[256] = {
17
+ // 0 1 2 3 4 5 6 7 8 9 A B C D E F
18
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 3, 3, 3, 0, 0, // 0x
19
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
20
+ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 2x
21
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3x
22
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
23
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 5x
24
+ 0, 0, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, 0, 4, 4, 4, // 6x
25
+ 0, 0, 0, 4, 0, 4, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, // 7x
26
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
27
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
28
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Ax
29
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Bx
30
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Cx
31
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Dx
32
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Ex
33
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Fx
34
+ };
35
+
36
+ static const uint8_t pm_number_table[256] = {
37
+ // 0 1 2 3 4 5 6 7 8 9 A B C D E F
38
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x
39
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 1x
40
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 2x
41
+ 0xff, 0xff, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 3x
42
+ 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 4x
43
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, // 5x
44
+ 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 6x
45
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 7x
46
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 8x
47
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 9x
48
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Ax
49
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Bx
50
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Cx
51
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Dx
52
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Ex
53
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Fx
54
+ };
55
+
56
+ /**
57
+ * Returns the number of characters at the start of the string that match the
58
+ * given kind. Disallows searching past the given maximum number of characters.
59
+ */
60
+ static inline size_t
61
+ pm_strspn_char_kind(const uint8_t *string, ptrdiff_t length, uint8_t kind) {
62
+ if (length <= 0) return 0;
63
+
64
+ size_t size = 0;
65
+ size_t maximum = (size_t) length;
66
+
67
+ while (size < maximum && (pm_byte_table[string[size]] & kind)) size++;
68
+ return size;
69
+ }
70
+
71
+ /**
72
+ * Returns the number of characters at the start of the string that are
73
+ * whitespace. Disallows searching past the given maximum number of characters.
74
+ */
75
+ size_t
76
+ pm_strspn_whitespace(const uint8_t *string, ptrdiff_t length) {
77
+ return pm_strspn_char_kind(string, length, PRISM_CHAR_BIT_WHITESPACE);
78
+ }
79
+
80
+ /**
81
+ * Returns the number of characters at the start of the string that are
82
+ * whitespace while also tracking the location of each newline. Disallows
83
+ * searching past the given maximum number of characters.
84
+ */
85
+ size_t
86
+ pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_newline_list_t *newline_list) {
87
+ if (length <= 0) return 0;
88
+
89
+ size_t size = 0;
90
+ size_t maximum = (size_t) length;
91
+
92
+ while (size < maximum && (pm_byte_table[string[size]] & PRISM_CHAR_BIT_WHITESPACE)) {
93
+ if (string[size] == '\n') {
94
+ pm_newline_list_append(newline_list, string + size);
95
+ }
96
+
97
+ size++;
98
+ }
99
+
100
+ return size;
101
+ }
102
+
103
+ /**
104
+ * Returns the number of characters at the start of the string that are inline
105
+ * whitespace. Disallows searching past the given maximum number of characters.
106
+ */
107
+ size_t
108
+ pm_strspn_inline_whitespace(const uint8_t *string, ptrdiff_t length) {
109
+ return pm_strspn_char_kind(string, length, PRISM_CHAR_BIT_INLINE_WHITESPACE);
110
+ }
111
+
112
+ /**
113
+ * Returns the number of characters at the start of the string that are regexp
114
+ * options. Disallows searching past the given maximum number of characters.
115
+ */
116
+ size_t
117
+ pm_strspn_regexp_option(const uint8_t *string, ptrdiff_t length) {
118
+ return pm_strspn_char_kind(string, length, PRISM_CHAR_BIT_REGEXP_OPTION);
119
+ }
120
+
121
+ /**
122
+ * Returns true if the given character matches the given kind.
123
+ */
124
+ static inline bool
125
+ pm_char_is_char_kind(const uint8_t b, uint8_t kind) {
126
+ return (pm_byte_table[b] & kind) != 0;
127
+ }
128
+
129
+ /**
130
+ * Returns true if the given character is a whitespace character.
131
+ */
132
+ bool
133
+ pm_char_is_whitespace(const uint8_t b) {
134
+ return pm_char_is_char_kind(b, PRISM_CHAR_BIT_WHITESPACE);
135
+ }
136
+
137
+ /**
138
+ * Returns true if the given character is an inline whitespace character.
139
+ */
140
+ bool
141
+ pm_char_is_inline_whitespace(const uint8_t b) {
142
+ return pm_char_is_char_kind(b, PRISM_CHAR_BIT_INLINE_WHITESPACE);
143
+ }
144
+
145
+ /**
146
+ * Scan through the string and return the number of characters at the start of
147
+ * the string that match the given kind. Disallows searching past the given
148
+ * maximum number of characters.
149
+ */
150
+ static inline size_t
151
+ pm_strspn_number_kind(const uint8_t *string, ptrdiff_t length, uint8_t kind) {
152
+ if (length <= 0) return 0;
153
+
154
+ size_t size = 0;
155
+ size_t maximum = (size_t) length;
156
+
157
+ while (size < maximum && (pm_number_table[string[size]] & kind)) size++;
158
+ return size;
159
+ }
160
+
161
+ /**
162
+ * Scan through the string and return the number of characters at the start of
163
+ * the string that match the given kind. Disallows searching past the given
164
+ * maximum number of characters.
165
+ *
166
+ * Additionally, report the location of the last invalid underscore character
167
+ * found in the string through the out invalid parameter.
168
+ */
169
+ static inline size_t
170
+ pm_strspn_number_kind_underscores(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid, uint8_t kind) {
171
+ if (length <= 0) return 0;
172
+
173
+ size_t size = 0;
174
+ size_t maximum = (size_t) length;
175
+
176
+ bool underscore = false;
177
+ while (size < maximum && (pm_number_table[string[size]] & kind)) {
178
+ if (string[size] == '_') {
179
+ if (underscore) *invalid = string + size;
180
+ underscore = true;
181
+ } else {
182
+ underscore = false;
183
+ }
184
+
185
+ size++;
186
+ }
187
+
188
+ if (string[size - 1] == '_') *invalid = string + size - 1;
189
+ return size;
190
+ }
191
+
192
+ /**
193
+ * Returns the number of characters at the start of the string that are binary
194
+ * digits or underscores. Disallows searching past the given maximum number of
195
+ * characters.
196
+ *
197
+ * If multiple underscores are found in a row or if an underscore is
198
+ * found at the end of the number, then the invalid pointer is set to the index
199
+ * of the first invalid underscore.
200
+ */
201
+ size_t
202
+ pm_strspn_binary_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid) {
203
+ return pm_strspn_number_kind_underscores(string, length, invalid, PRISM_NUMBER_BIT_BINARY_NUMBER);
204
+ }
205
+
206
+ /**
207
+ * Returns the number of characters at the start of the string that are octal
208
+ * digits or underscores. Disallows searching past the given maximum number of
209
+ * characters.
210
+ *
211
+ * If multiple underscores are found in a row or if an underscore is
212
+ * found at the end of the number, then the invalid pointer is set to the index
213
+ * of the first invalid underscore.
214
+ */
215
+ size_t
216
+ pm_strspn_octal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid) {
217
+ return pm_strspn_number_kind_underscores(string, length, invalid, PRISM_NUMBER_BIT_OCTAL_NUMBER);
218
+ }
219
+
220
+ /**
221
+ * Returns the number of characters at the start of the string that are decimal
222
+ * digits. Disallows searching past the given maximum number of characters.
223
+ */
224
+ size_t
225
+ pm_strspn_decimal_digit(const uint8_t *string, ptrdiff_t length) {
226
+ return pm_strspn_number_kind(string, length, PRISM_NUMBER_BIT_DECIMAL_DIGIT);
227
+ }
228
+
229
+ /**
230
+ * Returns the number of characters at the start of the string that are decimal
231
+ * digits or underscores. Disallows searching past the given maximum number of
232
+ * characters.
233
+ *
234
+ * If multiple underscores are found in a row or if an underscore is
235
+ * found at the end of the number, then the invalid pointer is set to the index
236
+ * of the first invalid underscore
237
+ */
238
+ size_t
239
+ pm_strspn_decimal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid) {
240
+ return pm_strspn_number_kind_underscores(string, length, invalid, PRISM_NUMBER_BIT_DECIMAL_NUMBER);
241
+ }
242
+
243
+ /**
244
+ * Returns the number of characters at the start of the string that are
245
+ * hexadecimal digits. Disallows searching past the given maximum number of
246
+ * characters.
247
+ */
248
+ size_t
249
+ pm_strspn_hexadecimal_digit(const uint8_t *string, ptrdiff_t length) {
250
+ return pm_strspn_number_kind(string, length, PRISM_NUMBER_BIT_HEXADECIMAL_DIGIT);
251
+ }
252
+
253
+ /**
254
+ * Returns the number of characters at the start of the string that are
255
+ * hexadecimal digits or underscores. Disallows searching past the given maximum
256
+ * number of characters.
257
+ *
258
+ * If multiple underscores are found in a row or if an underscore is
259
+ * found at the end of the number, then the invalid pointer is set to the index
260
+ * of the first invalid underscore.
261
+ */
262
+ size_t
263
+ pm_strspn_hexadecimal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid) {
264
+ return pm_strspn_number_kind_underscores(string, length, invalid, PRISM_NUMBER_BIT_HEXADECIMAL_NUMBER);
265
+ }
266
+
267
+ /**
268
+ * Returns true if the given character matches the given kind.
269
+ */
270
+ static inline bool
271
+ pm_char_is_number_kind(const uint8_t b, uint8_t kind) {
272
+ return (pm_number_table[b] & kind) != 0;
273
+ }
274
+
275
+ /**
276
+ * Returns true if the given character is a binary digit.
277
+ */
278
+ bool
279
+ pm_char_is_binary_digit(const uint8_t b) {
280
+ return pm_char_is_number_kind(b, PRISM_NUMBER_BIT_BINARY_DIGIT);
281
+ }
282
+
283
+ /**
284
+ * Returns true if the given character is an octal digit.
285
+ */
286
+ bool
287
+ pm_char_is_octal_digit(const uint8_t b) {
288
+ return pm_char_is_number_kind(b, PRISM_NUMBER_BIT_OCTAL_DIGIT);
289
+ }
290
+
291
+ /**
292
+ * Returns true if the given character is a decimal digit.
293
+ */
294
+ bool
295
+ pm_char_is_decimal_digit(const uint8_t b) {
296
+ return pm_char_is_number_kind(b, PRISM_NUMBER_BIT_DECIMAL_DIGIT);
297
+ }
298
+
299
+ /**
300
+ * Returns true if the given character is a hexadecimal digit.
301
+ */
302
+ bool
303
+ pm_char_is_hexadecimal_digit(const uint8_t b) {
304
+ return pm_char_is_number_kind(b, PRISM_NUMBER_BIT_HEXADECIMAL_DIGIT);
305
+ }
306
+
307
+ #undef PRISM_CHAR_BIT_WHITESPACE
308
+ #undef PRISM_CHAR_BIT_INLINE_WHITESPACE
309
+ #undef PRISM_CHAR_BIT_REGEXP_OPTION
310
+
311
+ #undef PRISM_NUMBER_BIT_BINARY_DIGIT
312
+ #undef PRISM_NUMBER_BIT_BINARY_NUMBER
313
+ #undef PRISM_NUMBER_BIT_OCTAL_DIGIT
314
+ #undef PRISM_NUMBER_BIT_OCTAL_NUMBER
315
+ #undef PRISM_NUMBER_BIT_DECIMAL_DIGIT
316
+ #undef PRISM_NUMBER_BIT_DECIMAL_NUMBER
317
+ #undef PRISM_NUMBER_BIT_HEXADECIMAL_NUMBER
318
+ #undef PRISM_NUMBER_BIT_HEXADECIMAL_DIGIT