prism 2.0.0.rc1-x86_64-linux-gnu
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.
- checksums.yaml +7 -0
- data/BSDmakefile +58 -0
- data/CHANGELOG.md +870 -0
- data/CODE_OF_CONDUCT.md +76 -0
- data/CONTRIBUTING.md +58 -0
- data/LICENSE.md +7 -0
- data/Makefile +145 -0
- data/README.md +81 -0
- data/config.yml +4752 -0
- data/docs/build_system.md +119 -0
- data/docs/configuration.md +69 -0
- data/docs/cruby_compilation.md +27 -0
- data/docs/design.md +53 -0
- data/docs/encoding.md +121 -0
- data/docs/fuzzing.md +81 -0
- data/docs/heredocs.md +36 -0
- data/docs/javascript.md +133 -0
- data/docs/local_variable_depth.md +229 -0
- data/docs/mapping.md +117 -0
- data/docs/parser_translation.md +24 -0
- data/docs/parsing_rules.md +22 -0
- data/docs/releasing.md +147 -0
- data/docs/relocation.md +32 -0
- data/docs/ripper_translation.md +63 -0
- data/docs/ruby_api.md +45 -0
- data/docs/ruby_parser_translation.md +19 -0
- data/docs/serialization.md +230 -0
- data/docs/testing.md +72 -0
- data/ext/prism/api_node.c +7005 -0
- data/ext/prism/extconf.rb +126 -0
- data/ext/prism/extension.c +1783 -0
- data/ext/prism/extension.h +19 -0
- data/include/prism/arena.h +37 -0
- data/include/prism/ast.h +10371 -0
- data/include/prism/buffer.h +52 -0
- data/include/prism/comments.h +55 -0
- data/include/prism/compiler/accel.h +24 -0
- data/include/prism/compiler/align.h +36 -0
- data/include/prism/compiler/assume.h +25 -0
- data/include/prism/compiler/exported.h +24 -0
- data/include/prism/compiler/fallthrough.h +22 -0
- data/include/prism/compiler/filesystem.h +32 -0
- data/include/prism/compiler/flex_array.h +19 -0
- data/include/prism/compiler/force_inline.h +21 -0
- data/include/prism/compiler/format.h +25 -0
- data/include/prism/compiler/inline.h +17 -0
- data/include/prism/compiler/nodiscard.h +22 -0
- data/include/prism/compiler/nonnull.h +18 -0
- data/include/prism/compiler/unused.h +18 -0
- data/include/prism/constant_pool.h +81 -0
- data/include/prism/diagnostic.h +93 -0
- data/include/prism/errors_format.h +53 -0
- data/include/prism/excludes.h +29 -0
- data/include/prism/integer.h +41 -0
- data/include/prism/internal/allocator.h +68 -0
- data/include/prism/internal/allocator_debug.h +88 -0
- data/include/prism/internal/arena.h +108 -0
- data/include/prism/internal/bit.h +42 -0
- data/include/prism/internal/buffer.h +91 -0
- data/include/prism/internal/char.h +145 -0
- data/include/prism/internal/comments.h +53 -0
- data/include/prism/internal/constant_pool.h +152 -0
- data/include/prism/internal/diagnostic.h +389 -0
- data/include/prism/internal/encoding.h +242 -0
- data/include/prism/internal/integer.h +68 -0
- data/include/prism/internal/isinf.h +16 -0
- data/include/prism/internal/line_offset_list.h +34 -0
- data/include/prism/internal/list.h +62 -0
- data/include/prism/internal/magic_comments.h +23 -0
- data/include/prism/internal/memchr.h +15 -0
- data/include/prism/internal/node.h +38 -0
- data/include/prism/internal/options.h +232 -0
- data/include/prism/internal/parser.h +984 -0
- data/include/prism/internal/regexp.h +26 -0
- data/include/prism/internal/serialize.h +39 -0
- data/include/prism/internal/source.h +72 -0
- data/include/prism/internal/static_literals.h +100 -0
- data/include/prism/internal/stringy.h +35 -0
- data/include/prism/internal/strncasecmp.h +18 -0
- data/include/prism/internal/strpbrk.h +33 -0
- data/include/prism/internal/tokens.h +11 -0
- data/include/prism/json.h +32 -0
- data/include/prism/line_offset_list.h +61 -0
- data/include/prism/magic_comments.h +35 -0
- data/include/prism/node.h +94 -0
- data/include/prism/options.h +354 -0
- data/include/prism/parser.h +404 -0
- data/include/prism/prettyprint.h +31 -0
- data/include/prism/serialize.h +115 -0
- data/include/prism/source.h +155 -0
- data/include/prism/stream.h +28 -0
- data/include/prism/string_query.h +63 -0
- data/include/prism/stringy.h +72 -0
- data/include/prism/version.h +38 -0
- data/include/prism.h +131 -0
- data/lib/prism/3.3/prism.so +0 -0
- data/lib/prism/3.4/prism.so +0 -0
- data/lib/prism/4.0/prism.so +0 -0
- data/lib/prism/compiler.rb +815 -0
- data/lib/prism/desugar_compiler.rb +463 -0
- data/lib/prism/dispatcher.rb +2383 -0
- data/lib/prism/dot_visitor.rb +4848 -0
- data/lib/prism/dsl.rb +1369 -0
- data/lib/prism/ffi.rb +740 -0
- data/lib/prism/inspect_visitor.rb +2425 -0
- data/lib/prism/lex_compat.rb +953 -0
- data/lib/prism/mutation_compiler.rb +780 -0
- data/lib/prism/node.rb +33204 -0
- data/lib/prism/node_ext.rb +504 -0
- data/lib/prism/node_find.rb +215 -0
- data/lib/prism/parse_result/errors.rb +72 -0
- data/lib/prism/parse_result/newlines.rb +423 -0
- data/lib/prism/parse_result.rb +1221 -0
- data/lib/prism/pattern.rb +314 -0
- data/lib/prism/polyfill/append_as_bytes.rb +15 -0
- data/lib/prism/polyfill/byteindex.rb +13 -0
- data/lib/prism/polyfill/scan_byte.rb +14 -0
- data/lib/prism/polyfill/unpack1.rb +14 -0
- data/lib/prism/polyfill/warn.rb +36 -0
- data/lib/prism/reflection.rb +427 -0
- data/lib/prism/relocation.rb +567 -0
- data/lib/prism/serialize.rb +5308 -0
- data/lib/prism/string_query.rb +46 -0
- data/lib/prism/translation/parser/builder.rb +70 -0
- data/lib/prism/translation/parser/compiler.rb +2226 -0
- data/lib/prism/translation/parser/lexer.rb +769 -0
- data/lib/prism/translation/parser.rb +376 -0
- data/lib/prism/translation/parser_current.rb +26 -0
- data/lib/prism/translation/parser_versions.rb +36 -0
- data/lib/prism/translation/ripper/filter.rb +53 -0
- data/lib/prism/translation/ripper/lexer.rb +133 -0
- data/lib/prism/translation/ripper/sexp.rb +118 -0
- data/lib/prism/translation/ripper/shim.rb +7 -0
- data/lib/prism/translation/ripper.rb +4278 -0
- data/lib/prism/translation/ruby_parser.rb +1721 -0
- data/lib/prism/translation.rb +20 -0
- data/lib/prism/visitor.rb +1440 -0
- data/lib/prism.rb +168 -0
- data/prism.gemspec +234 -0
- data/rbi/generated/prism/compiler.rbi +489 -0
- data/rbi/generated/prism/desugar_compiler.rbi +306 -0
- data/rbi/generated/prism/dispatcher.rbi +1138 -0
- data/rbi/generated/prism/dot_visitor.rbi +618 -0
- data/rbi/generated/prism/dsl.rbi +751 -0
- data/rbi/generated/prism/inspect_visitor.rbi +503 -0
- data/rbi/generated/prism/lex_compat.rbi +162 -0
- data/rbi/generated/prism/mutation_compiler.rbi +464 -0
- data/rbi/generated/prism/node.rbi +13681 -0
- data/rbi/generated/prism/node_ext.rbi +259 -0
- data/rbi/generated/prism/node_find.rbi +79 -0
- data/rbi/generated/prism/parse_result/errors.rbi +21 -0
- data/rbi/generated/prism/parse_result/newlines.rbi +208 -0
- data/rbi/generated/prism/parse_result.rbi +764 -0
- data/rbi/generated/prism/pattern.rbi +134 -0
- data/rbi/generated/prism/reflection.rbi +89 -0
- data/rbi/generated/prism/relocation.rbi +329 -0
- data/rbi/generated/prism/serialize.rbi +181 -0
- data/rbi/generated/prism/string_query.rbi +36 -0
- data/rbi/generated/prism/translation.rbi +7 -0
- data/rbi/generated/prism/visitor.rbi +650 -0
- data/rbi/generated/prism.rbi +86 -0
- data/rbi/prism/translation/parser.rbi +11 -0
- data/rbi/prism/translation/parser_versions.rbi +28 -0
- data/rbi/prism/translation/ripper.rbi +15 -0
- data/rbi/rubyvm/node_find.rbi +14 -0
- data/sig/generated/prism/compiler.rbs +492 -0
- data/sig/generated/prism/desugar_compiler.rbs +305 -0
- data/sig/generated/prism/dispatcher.rbs +1292 -0
- data/sig/generated/prism/dot_visitor.rbs +635 -0
- data/sig/generated/prism/dsl.rbs +928 -0
- data/sig/generated/prism/inspect_visitor.rbs +509 -0
- data/sig/generated/prism/lex_compat.rbs +166 -0
- data/sig/generated/prism/mutation_compiler.rbs +464 -0
- data/sig/generated/prism/node.rbs +20160 -0
- data/sig/generated/prism/node_ext.rbs +290 -0
- data/sig/generated/prism/node_find.rbs +90 -0
- data/sig/generated/prism/parse_result/errors.rbs +22 -0
- data/sig/generated/prism/parse_result/newlines.rbs +223 -0
- data/sig/generated/prism/parse_result.rbs +859 -0
- data/sig/generated/prism/pattern.rbs +156 -0
- data/sig/generated/prism/reflection.rbs +101 -0
- data/sig/generated/prism/relocation.rbs +428 -0
- data/sig/generated/prism/serialize.rbs +195 -0
- data/sig/generated/prism/string_query.rbs +36 -0
- data/sig/generated/prism/translation.rbs +8 -0
- data/sig/generated/prism/visitor.rbs +1111 -0
- data/sig/generated/prism.rbs +84 -0
- data/sig/manifest.yaml +2 -0
- data/src/arena.c +117 -0
- data/src/buffer.c +380 -0
- data/src/char.c +289 -0
- data/src/comments.c +454 -0
- data/src/constant_pool.c +406 -0
- data/src/diagnostic.c +886 -0
- data/src/encoding.c +5345 -0
- data/src/errors_format.c +519 -0
- data/src/integer.c +681 -0
- data/src/json.c +5733 -0
- data/src/line_offset_list.c +100 -0
- data/src/list.c +24 -0
- data/src/memchr.c +37 -0
- data/src/node.c +4515 -0
- data/src/options.c +451 -0
- data/src/parser.c +349 -0
- data/src/prettyprint.c +9024 -0
- data/src/prism.c +23739 -0
- data/src/regexp.c +1706 -0
- data/src/serialize.c +2309 -0
- data/src/source.c +518 -0
- data/src/static_literals.c +685 -0
- data/src/string_query.c +166 -0
- data/src/stringy.c +91 -0
- data/src/strncasecmp.c +37 -0
- data/src/strpbrk.c +447 -0
- data/src/tokens.c +724 -0
- metadata +259 -0
data/src/char.c
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
#include "prism/internal/char.h"
|
|
2
|
+
|
|
3
|
+
#include "prism/compiler/inline.h"
|
|
4
|
+
#include "prism/internal/line_offset_list.h"
|
|
5
|
+
|
|
6
|
+
#define PRISM_CHAR_BIT_REGEXP_OPTION (1 << 2)
|
|
7
|
+
|
|
8
|
+
#define PRISM_NUMBER_BIT_BINARY_DIGIT (1 << 0)
|
|
9
|
+
#define PRISM_NUMBER_BIT_BINARY_NUMBER (1 << 1)
|
|
10
|
+
#define PRISM_NUMBER_BIT_OCTAL_DIGIT (1 << 2)
|
|
11
|
+
#define PRISM_NUMBER_BIT_OCTAL_NUMBER (1 << 3)
|
|
12
|
+
#define PRISM_NUMBER_BIT_DECIMAL_DIGIT (1 << 4)
|
|
13
|
+
#define PRISM_NUMBER_BIT_DECIMAL_NUMBER (1 << 5)
|
|
14
|
+
#define PRISM_NUMBER_BIT_HEXADECIMAL_DIGIT (1 << 6)
|
|
15
|
+
#define PRISM_NUMBER_BIT_HEXADECIMAL_NUMBER (1 << 7)
|
|
16
|
+
|
|
17
|
+
const uint8_t pm_byte_table[256] = {
|
|
18
|
+
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
|
|
19
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 3, 3, 3, 0, 0, // 0x
|
|
20
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
|
|
21
|
+
3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 2x
|
|
22
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3x
|
|
23
|
+
0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, // 4x
|
|
24
|
+
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, // 5x
|
|
25
|
+
0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, // 6x
|
|
26
|
+
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, // 7x
|
|
27
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
|
|
28
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
|
|
29
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Ax
|
|
30
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Bx
|
|
31
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Cx
|
|
32
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Dx
|
|
33
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Ex
|
|
34
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Fx
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
static const uint8_t pm_number_table[256] = {
|
|
38
|
+
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
|
|
39
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x
|
|
40
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 1x
|
|
41
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 2x
|
|
42
|
+
0xff, 0xff, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 3x
|
|
43
|
+
0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 4x
|
|
44
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, // 5x
|
|
45
|
+
0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 6x
|
|
46
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 7x
|
|
47
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 8x
|
|
48
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 9x
|
|
49
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Ax
|
|
50
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Bx
|
|
51
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Cx
|
|
52
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Dx
|
|
53
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Ex
|
|
54
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Fx
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Returns the number of characters at the start of the string that match the
|
|
59
|
+
* given kind. Disallows searching past the given maximum number of characters.
|
|
60
|
+
*/
|
|
61
|
+
static PRISM_INLINE size_t
|
|
62
|
+
pm_strspn_char_kind(const uint8_t *string, ptrdiff_t length, uint8_t kind) {
|
|
63
|
+
if (length <= 0) return 0;
|
|
64
|
+
|
|
65
|
+
size_t size = 0;
|
|
66
|
+
size_t maximum = (size_t) length;
|
|
67
|
+
|
|
68
|
+
while (size < maximum && (pm_byte_table[string[size]] & kind)) size++;
|
|
69
|
+
return size;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Returns the number of characters at the start of the string that are
|
|
74
|
+
* whitespace. Disallows searching past the given maximum number of characters.
|
|
75
|
+
*/
|
|
76
|
+
size_t
|
|
77
|
+
pm_strspn_whitespace(const uint8_t *string, ptrdiff_t length) {
|
|
78
|
+
return pm_strspn_char_kind(string, length, PRISM_CHAR_BIT_WHITESPACE);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Returns the number of characters at the end of the string that are
|
|
83
|
+
* whitespace. Disallows searching past the given maximum number of characters.
|
|
84
|
+
*/
|
|
85
|
+
size_t
|
|
86
|
+
pm_strrspn_whitespace(const uint8_t *string, ptrdiff_t length) {
|
|
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[maximum - size - 1]] & PRISM_CHAR_BIT_WHITESPACE)) size++;
|
|
93
|
+
return size;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Returns the number of characters at the start of the string that are
|
|
98
|
+
* whitespace while also tracking the location of each newline. Disallows
|
|
99
|
+
* searching past the given maximum number of characters.
|
|
100
|
+
*/
|
|
101
|
+
size_t
|
|
102
|
+
pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_arena_t *arena, pm_line_offset_list_t *line_offsets, uint32_t start_offset) {
|
|
103
|
+
if (length <= 0) return 0;
|
|
104
|
+
|
|
105
|
+
uint32_t size = 0;
|
|
106
|
+
uint32_t maximum = (uint32_t) length;
|
|
107
|
+
|
|
108
|
+
while (size < maximum && (pm_byte_table[string[size]] & PRISM_CHAR_BIT_WHITESPACE)) {
|
|
109
|
+
if (string[size] == '\n') {
|
|
110
|
+
pm_line_offset_list_append(arena, line_offsets, start_offset + size + 1);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
size++;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return size;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Returns the number of characters at the start of the string that are regexp
|
|
121
|
+
* options. Disallows searching past the given maximum number of characters.
|
|
122
|
+
*/
|
|
123
|
+
size_t
|
|
124
|
+
pm_strspn_regexp_option(const uint8_t *string, ptrdiff_t length) {
|
|
125
|
+
return pm_strspn_char_kind(string, length, PRISM_CHAR_BIT_REGEXP_OPTION);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Scan through the string and return the number of characters at the start of
|
|
131
|
+
* the string that match the given kind. Disallows searching past the given
|
|
132
|
+
* maximum number of characters.
|
|
133
|
+
*/
|
|
134
|
+
static PRISM_INLINE size_t
|
|
135
|
+
pm_strspn_number_kind(const uint8_t *string, ptrdiff_t length, uint8_t kind) {
|
|
136
|
+
if (length <= 0) return 0;
|
|
137
|
+
|
|
138
|
+
size_t size = 0;
|
|
139
|
+
size_t maximum = (size_t) length;
|
|
140
|
+
|
|
141
|
+
while (size < maximum && (pm_number_table[string[size]] & kind)) size++;
|
|
142
|
+
return size;
|
|
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
|
+
* Additionally, report the location of the last invalid underscore character
|
|
151
|
+
* found in the string through the out invalid parameter.
|
|
152
|
+
*/
|
|
153
|
+
static PRISM_INLINE size_t
|
|
154
|
+
pm_strspn_number_kind_underscores(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid, uint8_t kind) {
|
|
155
|
+
if (length <= 0) return 0;
|
|
156
|
+
|
|
157
|
+
size_t size = 0;
|
|
158
|
+
size_t maximum = (size_t) length;
|
|
159
|
+
|
|
160
|
+
bool underscore = false;
|
|
161
|
+
while (size < maximum && (pm_number_table[string[size]] & kind)) {
|
|
162
|
+
if (string[size] == '_') {
|
|
163
|
+
if (underscore) *invalid = string + size;
|
|
164
|
+
underscore = true;
|
|
165
|
+
} else {
|
|
166
|
+
underscore = false;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
size++;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (size > 0 && string[size - 1] == '_') *invalid = string + size - 1;
|
|
173
|
+
return size;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Returns the number of characters at the start of the string that are binary
|
|
178
|
+
* digits or underscores. Disallows searching past the given maximum number of
|
|
179
|
+
* characters.
|
|
180
|
+
*
|
|
181
|
+
* If multiple underscores are found in a row or if an underscore is
|
|
182
|
+
* found at the end of the number, then the invalid pointer is set to the index
|
|
183
|
+
* of the first invalid underscore.
|
|
184
|
+
*/
|
|
185
|
+
size_t
|
|
186
|
+
pm_strspn_binary_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid) {
|
|
187
|
+
return pm_strspn_number_kind_underscores(string, length, invalid, PRISM_NUMBER_BIT_BINARY_NUMBER);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Returns the number of characters at the start of the string that are octal
|
|
192
|
+
* digits or underscores. Disallows searching past the given maximum number of
|
|
193
|
+
* characters.
|
|
194
|
+
*
|
|
195
|
+
* If multiple underscores are found in a row or if an underscore is
|
|
196
|
+
* found at the end of the number, then the invalid pointer is set to the index
|
|
197
|
+
* of the first invalid underscore.
|
|
198
|
+
*/
|
|
199
|
+
size_t
|
|
200
|
+
pm_strspn_octal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid) {
|
|
201
|
+
return pm_strspn_number_kind_underscores(string, length, invalid, PRISM_NUMBER_BIT_OCTAL_NUMBER);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Returns the number of characters at the start of the string that are decimal
|
|
206
|
+
* digits. Disallows searching past the given maximum number of characters.
|
|
207
|
+
*/
|
|
208
|
+
size_t
|
|
209
|
+
pm_strspn_decimal_digit(const uint8_t *string, ptrdiff_t length) {
|
|
210
|
+
return pm_strspn_number_kind(string, length, PRISM_NUMBER_BIT_DECIMAL_DIGIT);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Returns the number of characters at the start of the string that are decimal
|
|
215
|
+
* digits or underscores. Disallows searching past the given maximum number of
|
|
216
|
+
* characters.
|
|
217
|
+
*
|
|
218
|
+
* If multiple underscores are found in a row or if an underscore is
|
|
219
|
+
* found at the end of the number, then the invalid pointer is set to the index
|
|
220
|
+
* of the first invalid underscore
|
|
221
|
+
*/
|
|
222
|
+
size_t
|
|
223
|
+
pm_strspn_decimal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid) {
|
|
224
|
+
return pm_strspn_number_kind_underscores(string, length, invalid, PRISM_NUMBER_BIT_DECIMAL_NUMBER);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Returns the number of characters at the start of the string that are
|
|
229
|
+
* hexadecimal digits. Disallows searching past the given maximum number of
|
|
230
|
+
* characters.
|
|
231
|
+
*/
|
|
232
|
+
size_t
|
|
233
|
+
pm_strspn_hexadecimal_digit(const uint8_t *string, ptrdiff_t length) {
|
|
234
|
+
return pm_strspn_number_kind(string, length, PRISM_NUMBER_BIT_HEXADECIMAL_DIGIT);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Returns the number of characters at the start of the string that are
|
|
239
|
+
* hexadecimal digits or underscores. Disallows searching past the given maximum
|
|
240
|
+
* number of characters.
|
|
241
|
+
*
|
|
242
|
+
* If multiple underscores are found in a row or if an underscore is
|
|
243
|
+
* found at the end of the number, then the invalid pointer is set to the index
|
|
244
|
+
* of the first invalid underscore.
|
|
245
|
+
*/
|
|
246
|
+
size_t
|
|
247
|
+
pm_strspn_hexadecimal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid) {
|
|
248
|
+
return pm_strspn_number_kind_underscores(string, length, invalid, PRISM_NUMBER_BIT_HEXADECIMAL_NUMBER);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Returns true if the given character matches the given kind.
|
|
253
|
+
*/
|
|
254
|
+
static PRISM_INLINE bool
|
|
255
|
+
pm_char_is_number_kind(const uint8_t b, uint8_t kind) {
|
|
256
|
+
return (pm_number_table[b] & kind) != 0;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Returns true if the given character is a binary digit.
|
|
261
|
+
*/
|
|
262
|
+
bool
|
|
263
|
+
pm_char_is_binary_digit(const uint8_t b) {
|
|
264
|
+
return pm_char_is_number_kind(b, PRISM_NUMBER_BIT_BINARY_DIGIT);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Returns true if the given character is an octal digit.
|
|
269
|
+
*/
|
|
270
|
+
bool
|
|
271
|
+
pm_char_is_octal_digit(const uint8_t b) {
|
|
272
|
+
return pm_char_is_number_kind(b, PRISM_NUMBER_BIT_OCTAL_DIGIT);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Returns true if the given character is a decimal digit.
|
|
277
|
+
*/
|
|
278
|
+
bool
|
|
279
|
+
pm_char_is_decimal_digit(const uint8_t b) {
|
|
280
|
+
return pm_char_is_number_kind(b, PRISM_NUMBER_BIT_DECIMAL_DIGIT);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Returns true if the given character is a hexadecimal digit.
|
|
285
|
+
*/
|
|
286
|
+
bool
|
|
287
|
+
pm_char_is_hexadecimal_digit(const uint8_t b) {
|
|
288
|
+
return pm_char_is_number_kind(b, PRISM_NUMBER_BIT_HEXADECIMAL_DIGIT);
|
|
289
|
+
}
|