prism 1.9.0 → 2.0.0.rc2
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 +4 -4
- data/CHANGELOG.md +88 -0
- data/CODE_OF_CONDUCT.md +1 -1
- data/LICENSE.md +1 -1
- data/Makefile +41 -12
- data/README.md +35 -97
- data/config.yml +174 -161
- data/docs/build_system.md +2 -2
- data/docs/configuration.md +5 -4
- data/docs/encoding.md +2 -2
- data/docs/fuzzing.md +4 -11
- data/docs/javascript.md +19 -4
- data/docs/mapping.md +1 -1
- data/docs/releasing.md +77 -5
- data/docs/relocation.md +2 -4
- data/docs/serialization.md +22 -24
- data/docs/testing.md +46 -29
- data/ext/prism/api_node.c +1461 -1401
- data/ext/prism/extconf.rb +3 -4
- data/ext/prism/extension.c +796 -422
- data/ext/prism/extension.h +3 -3
- data/include/prism/arena.h +37 -0
- data/include/prism/ast.h +2727 -610
- data/include/prism/buffer.h +52 -0
- data/include/prism/comments.h +55 -0
- data/include/prism/compiler/accel.h +26 -0
- data/include/prism/compiler/align.h +36 -0
- data/include/prism/compiler/assume.h +25 -0
- data/include/prism/compiler/bswap.h +46 -0
- data/include/prism/compiler/endianness.h +34 -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 +38 -403
- 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 +94 -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/{encoding.h → internal/encoding.h} +27 -68
- 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/{util/pm_list.h → internal/list.h} +11 -52
- 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 +1004 -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/{static_literals.h → internal/static_literals.h} +26 -47
- data/include/prism/internal/stringy.h +35 -0
- data/include/prism/{util/pm_strncasecmp.h → internal/strncasecmp.h} +3 -17
- data/include/prism/{util/pm_strpbrk.h → internal/strpbrk.h} +7 -20
- data/include/prism/internal/tokens.h +11 -0
- data/include/prism/internal/xxh3.h +16 -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 +18 -53
- data/include/prism/options.h +146 -280
- data/include/prism/parser.h +356 -867
- data/include/prism/prettyprint.h +6 -9
- 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 +74 -0
- data/include/prism/stringy.h +72 -0
- data/include/prism/version.h +12 -3
- data/include/prism.h +43 -320
- data/lib/prism/compiler.rb +319 -305
- data/lib/prism/desugar_compiler.rb +105 -34
- data/lib/prism/dispatcher.rb +646 -473
- data/lib/prism/dot_visitor.rb +592 -511
- data/lib/prism/dsl.rb +391 -25
- data/lib/prism/ffi.rb +258 -90
- data/lib/prism/inspect_visitor.rb +357 -325
- data/lib/prism/lex_compat.rb +254 -212
- data/lib/prism/mutation_compiler.rb +313 -305
- data/lib/prism/node.rb +20966 -6992
- data/lib/prism/node_ext.rb +180 -187
- data/lib/prism/node_find.rb +215 -0
- data/lib/prism/parse_result/errors.rb +7 -1
- data/lib/prism/parse_result/newlines.rb +276 -8
- data/lib/prism/parse_result.rb +468 -139
- data/lib/prism/pattern.rb +65 -20
- data/lib/prism/reflection.rb +23 -12
- data/lib/prism/relocation.rb +149 -87
- data/lib/prism/serialize.rb +3460 -539
- data/lib/prism/string_query.rb +24 -1
- data/lib/prism/translation/parser/builder.rb +10 -2
- data/lib/prism/translation/parser/compiler.rb +44 -52
- data/lib/prism/translation/parser/lexer.rb +41 -92
- data/lib/prism/translation/parser.rb +1 -1
- data/lib/prism/translation/parser_current.rb +1 -1
- data/lib/prism/translation/ripper/lexer.rb +8 -10
- data/lib/prism/translation/ripper/sexp.rb +2 -10
- data/lib/prism/translation/ripper/shim.rb +2 -0
- data/lib/prism/translation/ripper.rb +967 -209
- data/lib/prism/translation/ruby_parser.rb +73 -316
- data/lib/prism/translation.rb +2 -0
- data/lib/prism/visitor.rb +632 -5
- data/lib/prism.rb +79 -9
- data/prism.gemspec +128 -62
- 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 +14407 -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 +776 -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 +184 -0
- data/rbi/generated/prism/string_query.rbi +43 -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_versions.rbi +5 -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/{prism → generated/prism}/mutation_compiler.rbs +309 -4
- data/sig/generated/prism/node.rbs +20896 -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 +871 -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 +198 -0
- data/sig/generated/prism/string_query.rbs +43 -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/{util/pm_buffer.c → buffer.c} +53 -21
- data/src/{util/pm_char.c → char.c} +28 -57
- data/src/comments.c +454 -0
- data/src/constant_pool.c +406 -0
- data/src/diagnostic.c +97 -65
- data/src/encoding.c +8 -3
- data/src/errors_format.c +519 -0
- data/src/{util/pm_integer.c → integer.c} +33 -22
- data/src/json.c +5733 -0
- data/src/line_offset_list.c +100 -0
- data/src/list.c +24 -0
- data/src/{util/pm_memchr.c → memchr.c} +8 -6
- data/src/node.c +3504 -7674
- data/src/options.c +162 -49
- data/src/parser.c +367 -0
- data/src/prettyprint.c +421 -354
- data/src/prism.c +8402 -7161
- data/src/regexp.c +961 -45
- data/src/serialize.c +460 -424
- data/src/source.c +518 -0
- data/src/static_literals.c +111 -43
- data/src/string_query.c +180 -0
- data/src/stringy.c +91 -0
- data/src/{util/pm_strncasecmp.c → strncasecmp.c} +5 -4
- data/src/strpbrk.c +447 -0
- data/src/{token_type.c → tokens.c} +39 -18
- data/src/xxh3.c +292 -0
- metadata +128 -63
- data/ext/prism/api_pack.c +0 -276
- data/include/prism/defines.h +0 -260
- data/include/prism/pack.h +0 -163
- data/include/prism/regexp.h +0 -43
- data/include/prism/util/pm_buffer.h +0 -236
- data/include/prism/util/pm_char.h +0 -204
- data/include/prism/util/pm_constant_pool.h +0 -218
- data/include/prism/util/pm_integer.h +0 -130
- data/include/prism/util/pm_memchr.h +0 -29
- data/include/prism/util/pm_newline_list.h +0 -113
- data/include/prism/util/pm_string.h +0 -200
- data/lib/prism/pack.rb +0 -230
- data/lib/prism/parse_result/comments.rb +0 -188
- data/rbi/prism/compiler.rbi +0 -12
- data/rbi/prism/dsl.rbi +0 -524
- data/rbi/prism/inspect_visitor.rbi +0 -12
- data/rbi/prism/node.rbi +0 -8750
- data/rbi/prism/node_ext.rbi +0 -107
- data/rbi/prism/parse_result.rbi +0 -404
- data/rbi/prism/reflection.rbi +0 -58
- data/rbi/prism/string_query.rbi +0 -12
- data/rbi/prism/visitor.rbi +0 -473
- data/rbi/prism.rbi +0 -63
- data/sig/prism/compiler.rbs +0 -9
- data/sig/prism/dispatcher.rbs +0 -19
- data/sig/prism/dot_visitor.rbs +0 -6
- data/sig/prism/dsl.rbs +0 -351
- data/sig/prism/inspect_visitor.rbs +0 -22
- data/sig/prism/lex_compat.rbs +0 -10
- data/sig/prism/node.rbs +0 -4042
- data/sig/prism/node_ext.rbs +0 -149
- data/sig/prism/pack.rbs +0 -43
- data/sig/prism/parse_result/comments.rbs +0 -38
- data/sig/prism/parse_result.rbs +0 -197
- data/sig/prism/pattern.rbs +0 -13
- data/sig/prism/reflection.rbs +0 -50
- data/sig/prism/relocation.rbs +0 -185
- data/sig/prism/serialize.rbs +0 -8
- data/sig/prism/string_query.rbs +0 -11
- data/sig/prism/visitor.rbs +0 -169
- data/sig/prism.rbs +0 -272
- data/src/pack.c +0 -509
- data/src/util/pm_constant_pool.c +0 -342
- data/src/util/pm_list.c +0 -49
- data/src/util/pm_newline_list.c +0 -125
- data/src/util/pm_string.c +0 -381
- data/src/util/pm_strpbrk.c +0 -206
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
/*----------------------------------------------------------------------------*/
|
|
2
|
+
/* This file is generated by the templates/template.rb script and should not */
|
|
3
|
+
/* be modified manually. See */
|
|
4
|
+
/* templates/include/prism/internal/diagnostic.h.erb */
|
|
5
|
+
/* if you are looking to modify the */
|
|
6
|
+
/* template */
|
|
7
|
+
/*----------------------------------------------------------------------------*/
|
|
8
|
+
|
|
9
|
+
#ifndef PRISM_INTERNAL_DIAGNOSTIC_H
|
|
10
|
+
#define PRISM_INTERNAL_DIAGNOSTIC_H
|
|
11
|
+
|
|
12
|
+
#include "prism/internal/list.h"
|
|
13
|
+
|
|
14
|
+
#include "prism/arena.h"
|
|
15
|
+
#include "prism/diagnostic.h"
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* The diagnostic IDs of all of the diagnostics, used to communicate the types
|
|
19
|
+
* of errors between the parser and the user.
|
|
20
|
+
*/
|
|
21
|
+
typedef enum {
|
|
22
|
+
/* These are the error diagnostics. */
|
|
23
|
+
PM_ERR_ALIAS_ARGUMENT,
|
|
24
|
+
PM_ERR_ALIAS_ARGUMENT_NUMBERED_REFERENCE,
|
|
25
|
+
PM_ERR_AMPAMPEQ_MULTI_ASSIGN,
|
|
26
|
+
PM_ERR_ARGUMENT_AFTER_BLOCK,
|
|
27
|
+
PM_ERR_ARGUMENT_AFTER_FORWARDING_ELLIPSES,
|
|
28
|
+
PM_ERR_ARGUMENT_BARE_HASH,
|
|
29
|
+
PM_ERR_ARGUMENT_BLOCK_MULTI,
|
|
30
|
+
PM_ERR_ARGUMENT_CONFLICT_AMPERSAND,
|
|
31
|
+
PM_ERR_ARGUMENT_CONFLICT_STAR,
|
|
32
|
+
PM_ERR_ARGUMENT_CONFLICT_STAR_STAR,
|
|
33
|
+
PM_ERR_ARGUMENT_FORMAL_CLASS,
|
|
34
|
+
PM_ERR_ARGUMENT_FORMAL_CONSTANT,
|
|
35
|
+
PM_ERR_ARGUMENT_FORMAL_GLOBAL,
|
|
36
|
+
PM_ERR_ARGUMENT_FORMAL_IVAR,
|
|
37
|
+
PM_ERR_ARGUMENT_FORWARDING_UNBOUND,
|
|
38
|
+
PM_ERR_ARGUMENT_NO_FORWARDING_AMPERSAND,
|
|
39
|
+
PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES,
|
|
40
|
+
PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES_LAMBDA,
|
|
41
|
+
PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES_BLOCK,
|
|
42
|
+
PM_ERR_ARGUMENT_NO_FORWARDING_STAR,
|
|
43
|
+
PM_ERR_ARGUMENT_NO_FORWARDING_STAR_STAR,
|
|
44
|
+
PM_ERR_ARGUMENT_SPLAT_AFTER_ASSOC_SPLAT,
|
|
45
|
+
PM_ERR_ARGUMENT_SPLAT_AFTER_SPLAT,
|
|
46
|
+
PM_ERR_ARGUMENT_TERM_PAREN,
|
|
47
|
+
PM_ERR_ARGUMENT_UNEXPECTED_BLOCK,
|
|
48
|
+
PM_ERR_ARRAY_ELEMENT,
|
|
49
|
+
PM_ERR_ARRAY_EXPRESSION,
|
|
50
|
+
PM_ERR_ARRAY_EXPRESSION_AFTER_STAR,
|
|
51
|
+
PM_ERR_ARRAY_SEPARATOR,
|
|
52
|
+
PM_ERR_ARRAY_TERM,
|
|
53
|
+
PM_ERR_BEGIN_LONELY_ELSE,
|
|
54
|
+
PM_ERR_BEGIN_TERM,
|
|
55
|
+
PM_ERR_BEGIN_UPCASE_BRACE,
|
|
56
|
+
PM_ERR_BEGIN_UPCASE_TERM,
|
|
57
|
+
PM_ERR_BEGIN_UPCASE_TOPLEVEL,
|
|
58
|
+
PM_ERR_BLOCK_PARAM_LOCAL_VARIABLE,
|
|
59
|
+
PM_ERR_BLOCK_PARAM_PIPE_TERM,
|
|
60
|
+
PM_ERR_BLOCK_TERM_BRACE,
|
|
61
|
+
PM_ERR_BLOCK_TERM_END,
|
|
62
|
+
PM_ERR_CANNOT_PARSE_EXPRESSION,
|
|
63
|
+
PM_ERR_CANNOT_PARSE_STRING_PART,
|
|
64
|
+
PM_ERR_CASE_EXPRESSION_AFTER_CASE,
|
|
65
|
+
PM_ERR_CASE_EXPRESSION_AFTER_WHEN,
|
|
66
|
+
PM_ERR_CASE_MATCH_MISSING_PREDICATE,
|
|
67
|
+
PM_ERR_CASE_MISSING_CONDITIONS,
|
|
68
|
+
PM_ERR_CASE_TERM,
|
|
69
|
+
PM_ERR_CLASS_IN_METHOD,
|
|
70
|
+
PM_ERR_CLASS_NAME,
|
|
71
|
+
PM_ERR_CLASS_SUPERCLASS,
|
|
72
|
+
PM_ERR_CLASS_TERM,
|
|
73
|
+
PM_ERR_CLASS_UNEXPECTED_END,
|
|
74
|
+
PM_ERR_CLASS_VARIABLE_BARE,
|
|
75
|
+
PM_ERR_CONDITIONAL_ELSIF_PREDICATE,
|
|
76
|
+
PM_ERR_CONDITIONAL_IF_PREDICATE,
|
|
77
|
+
PM_ERR_CONDITIONAL_PREDICATE_TERM,
|
|
78
|
+
PM_ERR_CONDITIONAL_TERM,
|
|
79
|
+
PM_ERR_CONDITIONAL_TERM_ELSE,
|
|
80
|
+
PM_ERR_CONDITIONAL_UNLESS_PREDICATE,
|
|
81
|
+
PM_ERR_CONDITIONAL_UNTIL_PREDICATE,
|
|
82
|
+
PM_ERR_CONDITIONAL_WHILE_PREDICATE,
|
|
83
|
+
PM_ERR_CONSTANT_PATH_COLON_COLON_CONSTANT,
|
|
84
|
+
PM_ERR_DEF_ENDLESS,
|
|
85
|
+
PM_ERR_DEF_ENDLESS_PARAMETERS,
|
|
86
|
+
PM_ERR_DEF_ENDLESS_SETTER,
|
|
87
|
+
PM_ERR_DEF_ENDLESS_DO_BLOCK,
|
|
88
|
+
PM_ERR_DEF_NAME,
|
|
89
|
+
PM_ERR_DEF_PARAMS_TERM,
|
|
90
|
+
PM_ERR_DEF_PARAMS_TERM_PAREN,
|
|
91
|
+
PM_ERR_DEF_RECEIVER,
|
|
92
|
+
PM_ERR_DEF_RECEIVER_TERM,
|
|
93
|
+
PM_ERR_DEF_TERM,
|
|
94
|
+
PM_ERR_DEFINED_EXPRESSION,
|
|
95
|
+
PM_ERR_EMBDOC_TERM,
|
|
96
|
+
PM_ERR_EMBEXPR_END,
|
|
97
|
+
PM_ERR_EMBVAR_INVALID,
|
|
98
|
+
PM_ERR_END_UPCASE_BRACE,
|
|
99
|
+
PM_ERR_END_UPCASE_TERM,
|
|
100
|
+
PM_ERR_ESCAPE_INVALID_CONTROL,
|
|
101
|
+
PM_ERR_ESCAPE_INVALID_CONTROL_REPEAT,
|
|
102
|
+
PM_ERR_ESCAPE_INVALID_HEXADECIMAL,
|
|
103
|
+
PM_ERR_ESCAPE_INVALID_META,
|
|
104
|
+
PM_ERR_ESCAPE_INVALID_META_REPEAT,
|
|
105
|
+
PM_ERR_ESCAPE_INVALID_UNICODE,
|
|
106
|
+
PM_ERR_ESCAPE_INVALID_UNICODE_CM_FLAGS,
|
|
107
|
+
PM_ERR_ESCAPE_INVALID_UNICODE_LIST,
|
|
108
|
+
PM_ERR_ESCAPE_INVALID_UNICODE_LITERAL,
|
|
109
|
+
PM_ERR_ESCAPE_INVALID_UNICODE_LONG,
|
|
110
|
+
PM_ERR_ESCAPE_INVALID_UNICODE_SHORT,
|
|
111
|
+
PM_ERR_ESCAPE_INVALID_UNICODE_TERM,
|
|
112
|
+
PM_ERR_EXPECT_ARGUMENT,
|
|
113
|
+
PM_ERR_EXPECT_EOL_AFTER_STATEMENT,
|
|
114
|
+
PM_ERR_EXPECT_EXPRESSION_AFTER_AMPAMPEQ,
|
|
115
|
+
PM_ERR_EXPECT_EXPRESSION_AFTER_COMMA,
|
|
116
|
+
PM_ERR_EXPECT_EXPRESSION_AFTER_EQUAL,
|
|
117
|
+
PM_ERR_EXPECT_EXPRESSION_AFTER_LESS_LESS,
|
|
118
|
+
PM_ERR_EXPECT_EXPRESSION_AFTER_LPAREN,
|
|
119
|
+
PM_ERR_EXPECT_EXPRESSION_AFTER_OPERATOR,
|
|
120
|
+
PM_ERR_EXPECT_EXPRESSION_AFTER_PIPEPIPEEQ,
|
|
121
|
+
PM_ERR_EXPECT_EXPRESSION_AFTER_SPLAT,
|
|
122
|
+
PM_ERR_EXPECT_EXPRESSION_AFTER_SPLAT_HASH,
|
|
123
|
+
PM_ERR_EXPECT_EXPRESSION_AFTER_STAR,
|
|
124
|
+
PM_ERR_EXPECT_FOR_DELIMITER,
|
|
125
|
+
PM_ERR_EXPECT_IDENT_REQ_PARAMETER,
|
|
126
|
+
PM_ERR_EXPECT_IN_DELIMITER,
|
|
127
|
+
PM_ERR_EXPECT_LPAREN_AFTER_NOT_LPAREN,
|
|
128
|
+
PM_ERR_EXPECT_LPAREN_AFTER_NOT_OTHER,
|
|
129
|
+
PM_ERR_EXPECT_LPAREN_REQ_PARAMETER,
|
|
130
|
+
PM_ERR_EXPECT_MESSAGE,
|
|
131
|
+
PM_ERR_EXPECT_RBRACKET,
|
|
132
|
+
PM_ERR_EXPECT_RPAREN,
|
|
133
|
+
PM_ERR_EXPECT_RPAREN_AFTER_MULTI,
|
|
134
|
+
PM_ERR_EXPECT_RPAREN_REQ_PARAMETER,
|
|
135
|
+
PM_ERR_EXPECT_SINGLETON_CLASS_DELIMITER,
|
|
136
|
+
PM_ERR_EXPECT_STRING_CONTENT,
|
|
137
|
+
PM_ERR_EXPECT_WHEN_DELIMITER,
|
|
138
|
+
PM_ERR_EXPRESSION_BARE_HASH,
|
|
139
|
+
PM_ERR_EXPRESSION_NOT_WRITABLE,
|
|
140
|
+
PM_ERR_EXPRESSION_NOT_WRITABLE_ENCODING,
|
|
141
|
+
PM_ERR_EXPRESSION_NOT_WRITABLE_FALSE,
|
|
142
|
+
PM_ERR_EXPRESSION_NOT_WRITABLE_FILE,
|
|
143
|
+
PM_ERR_EXPRESSION_NOT_WRITABLE_LINE,
|
|
144
|
+
PM_ERR_EXPRESSION_NOT_WRITABLE_NIL,
|
|
145
|
+
PM_ERR_EXPRESSION_NOT_WRITABLE_NUMBERED,
|
|
146
|
+
PM_ERR_EXPRESSION_NOT_WRITABLE_SELF,
|
|
147
|
+
PM_ERR_EXPRESSION_NOT_WRITABLE_TRUE,
|
|
148
|
+
PM_ERR_FLOAT_PARSE,
|
|
149
|
+
PM_ERR_FOR_COLLECTION,
|
|
150
|
+
PM_ERR_FOR_IN,
|
|
151
|
+
PM_ERR_FOR_INDEX,
|
|
152
|
+
PM_ERR_FOR_TERM,
|
|
153
|
+
PM_ERR_GLOBAL_VARIABLE_BARE,
|
|
154
|
+
PM_ERR_HASH_EXPRESSION_AFTER_LABEL,
|
|
155
|
+
PM_ERR_HASH_KEY,
|
|
156
|
+
PM_ERR_HASH_ROCKET,
|
|
157
|
+
PM_ERR_HASH_TERM,
|
|
158
|
+
PM_ERR_HASH_VALUE,
|
|
159
|
+
PM_ERR_HEREDOC_IDENTIFIER,
|
|
160
|
+
PM_ERR_HEREDOC_TERM,
|
|
161
|
+
PM_ERR_INCOMPLETE_QUESTION_MARK,
|
|
162
|
+
PM_ERR_INCOMPLETE_VARIABLE_CLASS,
|
|
163
|
+
PM_ERR_INCOMPLETE_VARIABLE_CLASS_3_3,
|
|
164
|
+
PM_ERR_INCOMPLETE_VARIABLE_INSTANCE,
|
|
165
|
+
PM_ERR_INCOMPLETE_VARIABLE_INSTANCE_3_3,
|
|
166
|
+
PM_ERR_INSTANCE_VARIABLE_BARE,
|
|
167
|
+
PM_ERR_INVALID_BLOCK_EXIT,
|
|
168
|
+
PM_ERR_INVALID_CHARACTER,
|
|
169
|
+
PM_ERR_INVALID_COMMA,
|
|
170
|
+
PM_ERR_INVALID_ENCODING_MAGIC_COMMENT,
|
|
171
|
+
PM_ERR_INVALID_ESCAPE_CHARACTER,
|
|
172
|
+
PM_ERR_INVALID_FLOAT_EXPONENT,
|
|
173
|
+
PM_ERR_INVALID_LOCAL_VARIABLE_READ,
|
|
174
|
+
PM_ERR_INVALID_LOCAL_VARIABLE_WRITE,
|
|
175
|
+
PM_ERR_INVALID_MULTIBYTE_CHAR,
|
|
176
|
+
PM_ERR_INVALID_MULTIBYTE_CHARACTER,
|
|
177
|
+
PM_ERR_INVALID_MULTIBYTE_ESCAPE,
|
|
178
|
+
PM_ERR_INVALID_NUMBER_BINARY,
|
|
179
|
+
PM_ERR_INVALID_NUMBER_DECIMAL,
|
|
180
|
+
PM_ERR_INVALID_NUMBER_FRACTION,
|
|
181
|
+
PM_ERR_INVALID_NUMBER_HEXADECIMAL,
|
|
182
|
+
PM_ERR_INVALID_NUMBER_OCTAL,
|
|
183
|
+
PM_ERR_INVALID_NUMBER_UNDERSCORE_INNER,
|
|
184
|
+
PM_ERR_INVALID_NUMBER_UNDERSCORE_TRAILING,
|
|
185
|
+
PM_ERR_INVALID_PERCENT,
|
|
186
|
+
PM_ERR_INVALID_PERCENT_EOF,
|
|
187
|
+
PM_ERR_INVALID_PRINTABLE_CHARACTER,
|
|
188
|
+
PM_ERR_INVALID_RETRY_AFTER_ELSE,
|
|
189
|
+
PM_ERR_INVALID_RETRY_AFTER_ENSURE,
|
|
190
|
+
PM_ERR_INVALID_RETRY_WITHOUT_RESCUE,
|
|
191
|
+
PM_ERR_INVALID_SYMBOL,
|
|
192
|
+
PM_ERR_INVALID_VARIABLE_GLOBAL,
|
|
193
|
+
PM_ERR_INVALID_VARIABLE_GLOBAL_3_3,
|
|
194
|
+
PM_ERR_INVALID_YIELD,
|
|
195
|
+
PM_ERR_IT_NOT_ALLOWED_NUMBERED,
|
|
196
|
+
PM_ERR_IT_NOT_ALLOWED_ORDINARY,
|
|
197
|
+
PM_ERR_LAMBDA_OPEN,
|
|
198
|
+
PM_ERR_LAMBDA_TERM_BRACE,
|
|
199
|
+
PM_ERR_LAMBDA_TERM_END,
|
|
200
|
+
PM_ERR_LIST_I_LOWER_ELEMENT,
|
|
201
|
+
PM_ERR_LIST_I_LOWER_TERM,
|
|
202
|
+
PM_ERR_LIST_I_UPPER_ELEMENT,
|
|
203
|
+
PM_ERR_LIST_I_UPPER_TERM,
|
|
204
|
+
PM_ERR_LIST_W_LOWER_ELEMENT,
|
|
205
|
+
PM_ERR_LIST_W_LOWER_TERM,
|
|
206
|
+
PM_ERR_LIST_W_UPPER_ELEMENT,
|
|
207
|
+
PM_ERR_LIST_W_UPPER_TERM,
|
|
208
|
+
PM_ERR_MALLOC_FAILED,
|
|
209
|
+
PM_ERR_MIXED_ENCODING,
|
|
210
|
+
PM_ERR_MODULE_IN_METHOD,
|
|
211
|
+
PM_ERR_MODULE_NAME,
|
|
212
|
+
PM_ERR_MODULE_TERM,
|
|
213
|
+
PM_ERR_MULTI_ASSIGN_MULTI_SPLATS,
|
|
214
|
+
PM_ERR_MULTI_ASSIGN_UNEXPECTED_REST,
|
|
215
|
+
PM_ERR_NESTING_TOO_DEEP,
|
|
216
|
+
PM_ERR_NO_LOCAL_VARIABLE,
|
|
217
|
+
PM_ERR_NON_ASSOCIATIVE_OPERATOR,
|
|
218
|
+
PM_ERR_NOT_EXPRESSION,
|
|
219
|
+
PM_ERR_NUMBER_LITERAL_UNDERSCORE,
|
|
220
|
+
PM_ERR_NUMBERED_PARAMETER_INNER_BLOCK,
|
|
221
|
+
PM_ERR_NUMBERED_PARAMETER_IT,
|
|
222
|
+
PM_ERR_NUMBERED_PARAMETER_ORDINARY,
|
|
223
|
+
PM_ERR_NUMBERED_PARAMETER_OUTER_BLOCK,
|
|
224
|
+
PM_ERR_OPERATOR_MULTI_ASSIGN,
|
|
225
|
+
PM_ERR_OPERATOR_WRITE_ARGUMENTS,
|
|
226
|
+
PM_ERR_OPERATOR_WRITE_BLOCK,
|
|
227
|
+
PM_ERR_PARAMETER_ASSOC_SPLAT_MULTI,
|
|
228
|
+
PM_ERR_PARAMETER_BLOCK_MULTI,
|
|
229
|
+
PM_ERR_PARAMETER_CIRCULAR,
|
|
230
|
+
PM_ERR_PARAMETER_FORWARDING_AFTER_REST,
|
|
231
|
+
PM_ERR_PARAMETER_METHOD_NAME,
|
|
232
|
+
PM_ERR_PARAMETER_NAME_DUPLICATED,
|
|
233
|
+
PM_ERR_PARAMETER_NO_DEFAULT,
|
|
234
|
+
PM_ERR_PARAMETER_NO_DEFAULT_KW,
|
|
235
|
+
PM_ERR_PARAMETER_NUMBERED_RESERVED,
|
|
236
|
+
PM_ERR_PARAMETER_ORDER,
|
|
237
|
+
PM_ERR_PARAMETER_SPLAT_MULTI,
|
|
238
|
+
PM_ERR_PARAMETER_STAR,
|
|
239
|
+
PM_ERR_PARAMETER_UNEXPECTED_FWD,
|
|
240
|
+
PM_ERR_PARAMETER_UNEXPECTED_NO_KW,
|
|
241
|
+
PM_ERR_PARAMETER_WILD_LOOSE_COMMA,
|
|
242
|
+
PM_ERR_PATTERN_ARRAY_MULTIPLE_RESTS,
|
|
243
|
+
PM_ERR_PATTERN_CAPTURE_DUPLICATE,
|
|
244
|
+
PM_ERR_PATTERN_CAPTURE_IN_ALTERNATIVE,
|
|
245
|
+
PM_ERR_PATTERN_EXPRESSION_AFTER_BRACKET,
|
|
246
|
+
PM_ERR_PATTERN_EXPRESSION_AFTER_COMMA,
|
|
247
|
+
PM_ERR_PATTERN_EXPRESSION_AFTER_HROCKET,
|
|
248
|
+
PM_ERR_PATTERN_EXPRESSION_AFTER_IN,
|
|
249
|
+
PM_ERR_PATTERN_EXPRESSION_AFTER_KEY,
|
|
250
|
+
PM_ERR_PATTERN_EXPRESSION_AFTER_PAREN,
|
|
251
|
+
PM_ERR_PATTERN_EXPRESSION_AFTER_PIN,
|
|
252
|
+
PM_ERR_PATTERN_EXPRESSION_AFTER_PIPE,
|
|
253
|
+
PM_ERR_PATTERN_EXPRESSION_AFTER_RANGE,
|
|
254
|
+
PM_ERR_PATTERN_EXPRESSION_AFTER_REST,
|
|
255
|
+
PM_ERR_PATTERN_FIND_MISSING_INNER,
|
|
256
|
+
PM_ERR_PATTERN_HASH_IMPLICIT,
|
|
257
|
+
PM_ERR_PATTERN_HASH_KEY,
|
|
258
|
+
PM_ERR_PATTERN_HASH_KEY_DUPLICATE,
|
|
259
|
+
PM_ERR_PATTERN_HASH_KEY_INTERPOLATED,
|
|
260
|
+
PM_ERR_PATTERN_HASH_KEY_LABEL,
|
|
261
|
+
PM_ERR_PATTERN_HASH_KEY_LOCALS,
|
|
262
|
+
PM_ERR_PATTERN_IDENT_AFTER_HROCKET,
|
|
263
|
+
PM_ERR_PATTERN_LABEL_AFTER_COMMA,
|
|
264
|
+
PM_ERR_PATTERN_REST,
|
|
265
|
+
PM_ERR_PATTERN_TERM_BRACE,
|
|
266
|
+
PM_ERR_PATTERN_TERM_BRACKET,
|
|
267
|
+
PM_ERR_PATTERN_TERM_PAREN,
|
|
268
|
+
PM_ERR_PIPEPIPEEQ_MULTI_ASSIGN,
|
|
269
|
+
PM_ERR_REGEXP_ENCODING_OPTION_MISMATCH,
|
|
270
|
+
PM_ERR_REGEXP_ESCAPED_NON_ASCII_IN_UTF8,
|
|
271
|
+
PM_ERR_REGEXP_INCOMPAT_CHAR_ENCODING,
|
|
272
|
+
PM_ERR_REGEXP_INVALID_CHAR_PROPERTY,
|
|
273
|
+
PM_ERR_REGEXP_INVALID_UNICODE_RANGE,
|
|
274
|
+
PM_ERR_REGEXP_NON_ESCAPED_MBC,
|
|
275
|
+
PM_ERR_REGEXP_PARSE_ERROR,
|
|
276
|
+
PM_ERR_REGEXP_TERM,
|
|
277
|
+
PM_ERR_REGEXP_UNKNOWN_OPTIONS,
|
|
278
|
+
PM_ERR_REGEXP_UTF8_CHAR_NON_UTF8_REGEXP,
|
|
279
|
+
PM_ERR_RESCUE_EXPRESSION,
|
|
280
|
+
PM_ERR_RESCUE_MODIFIER_VALUE,
|
|
281
|
+
PM_ERR_RESCUE_TERM,
|
|
282
|
+
PM_ERR_RESCUE_VARIABLE,
|
|
283
|
+
PM_ERR_RETURN_INVALID,
|
|
284
|
+
PM_ERR_SCRIPT_NOT_FOUND,
|
|
285
|
+
PM_ERR_SINGLETON_FOR_LITERALS,
|
|
286
|
+
PM_ERR_STATEMENT_ALIAS,
|
|
287
|
+
PM_ERR_STATEMENT_POSTEXE_END,
|
|
288
|
+
PM_ERR_STATEMENT_PREEXE_BEGIN,
|
|
289
|
+
PM_ERR_STATEMENT_UNDEF,
|
|
290
|
+
PM_ERR_STRING_CONCATENATION,
|
|
291
|
+
PM_ERR_STRING_INTERPOLATED_TERM,
|
|
292
|
+
PM_ERR_STRING_LITERAL_EOF,
|
|
293
|
+
PM_ERR_STRING_LITERAL_TERM,
|
|
294
|
+
PM_ERR_SYMBOL_INVALID,
|
|
295
|
+
PM_ERR_SYMBOL_TERM_DYNAMIC,
|
|
296
|
+
PM_ERR_SYMBOL_TERM_INTERPOLATED,
|
|
297
|
+
PM_ERR_TERNARY_COLON,
|
|
298
|
+
PM_ERR_TERNARY_EXPRESSION_FALSE,
|
|
299
|
+
PM_ERR_TERNARY_EXPRESSION_TRUE,
|
|
300
|
+
PM_ERR_UNARY_DISALLOWED,
|
|
301
|
+
PM_ERR_UNARY_RECEIVER,
|
|
302
|
+
PM_ERR_UNDEF_ARGUMENT,
|
|
303
|
+
PM_ERR_UNEXPECTED_BLOCK_ARGUMENT,
|
|
304
|
+
PM_ERR_UNEXPECTED_INDEX_BLOCK,
|
|
305
|
+
PM_ERR_UNEXPECTED_INDEX_KEYWORDS,
|
|
306
|
+
PM_ERR_UNEXPECTED_LABEL,
|
|
307
|
+
PM_ERR_UNEXPECTED_MULTI_WRITE,
|
|
308
|
+
PM_ERR_UNEXPECTED_PARAMETER_DEFAULT_VALUE,
|
|
309
|
+
PM_ERR_UNEXPECTED_RANGE_OPERATOR,
|
|
310
|
+
PM_ERR_UNEXPECTED_SAFE_NAVIGATION,
|
|
311
|
+
PM_ERR_UNEXPECTED_TOKEN_CLOSE_CONTEXT,
|
|
312
|
+
PM_ERR_UNEXPECTED_TOKEN_IGNORE,
|
|
313
|
+
PM_ERR_UNTIL_TERM,
|
|
314
|
+
PM_ERR_VOID_EXPRESSION,
|
|
315
|
+
PM_ERR_WHILE_TERM,
|
|
316
|
+
PM_ERR_WRITE_TARGET_IN_METHOD,
|
|
317
|
+
PM_ERR_WRITE_TARGET_READONLY,
|
|
318
|
+
PM_ERR_WRITE_TARGET_UNEXPECTED,
|
|
319
|
+
PM_ERR_XSTRING_TERM,
|
|
320
|
+
|
|
321
|
+
/* These are the warning diagnostics. */
|
|
322
|
+
PM_WARN_AMBIGUOUS_BINARY_OPERATOR,
|
|
323
|
+
PM_WARN_AMBIGUOUS_FIRST_ARGUMENT_MINUS,
|
|
324
|
+
PM_WARN_AMBIGUOUS_FIRST_ARGUMENT_PLUS,
|
|
325
|
+
PM_WARN_AMBIGUOUS_PREFIX_AMPERSAND,
|
|
326
|
+
PM_WARN_AMBIGUOUS_PREFIX_STAR,
|
|
327
|
+
PM_WARN_AMBIGUOUS_PREFIX_STAR_STAR,
|
|
328
|
+
PM_WARN_AMBIGUOUS_SLASH,
|
|
329
|
+
PM_WARN_COMPARISON_AFTER_COMPARISON,
|
|
330
|
+
PM_WARN_DOT_DOT_DOT_EOL,
|
|
331
|
+
PM_WARN_EQUAL_IN_CONDITIONAL,
|
|
332
|
+
PM_WARN_EQUAL_IN_CONDITIONAL_3_3,
|
|
333
|
+
PM_WARN_END_IN_METHOD,
|
|
334
|
+
PM_WARN_DUPLICATED_HASH_KEY,
|
|
335
|
+
PM_WARN_DUPLICATED_WHEN_CLAUSE,
|
|
336
|
+
PM_WARN_FLOAT_OUT_OF_RANGE,
|
|
337
|
+
PM_WARN_IGNORED_FROZEN_STRING_LITERAL,
|
|
338
|
+
PM_WARN_INDENTATION_MISMATCH,
|
|
339
|
+
PM_WARN_INTEGER_IN_FLIP_FLOP,
|
|
340
|
+
PM_WARN_INVALID_CHARACTER,
|
|
341
|
+
PM_WARN_INVALID_MAGIC_COMMENT_VALUE,
|
|
342
|
+
PM_WARN_INVALID_NUMBERED_REFERENCE,
|
|
343
|
+
PM_WARN_KEYWORD_EOL,
|
|
344
|
+
PM_WARN_LITERAL_IN_CONDITION_DEFAULT,
|
|
345
|
+
PM_WARN_LITERAL_IN_CONDITION_VERBOSE,
|
|
346
|
+
PM_WARN_SHAREABLE_CONSTANT_VALUE_LINE,
|
|
347
|
+
PM_WARN_SHEBANG_CARRIAGE_RETURN,
|
|
348
|
+
PM_WARN_UNEXPECTED_CARRIAGE_RETURN,
|
|
349
|
+
PM_WARN_UNREACHABLE_STATEMENT,
|
|
350
|
+
PM_WARN_UNUSED_LOCAL_VARIABLE,
|
|
351
|
+
PM_WARN_VOID_STATEMENT,
|
|
352
|
+
} pm_diagnostic_id_t;
|
|
353
|
+
|
|
354
|
+
/*
|
|
355
|
+
* This struct represents a diagnostic generated during parsing.
|
|
356
|
+
*/
|
|
357
|
+
struct pm_diagnostic_t {
|
|
358
|
+
/* The embedded base node. */
|
|
359
|
+
pm_list_node_t node;
|
|
360
|
+
|
|
361
|
+
/* The location of the diagnostic in the source. */
|
|
362
|
+
pm_location_t location;
|
|
363
|
+
|
|
364
|
+
/* The ID of the diagnostic. */
|
|
365
|
+
pm_diagnostic_id_t diag_id;
|
|
366
|
+
|
|
367
|
+
/* The message associated with the diagnostic. */
|
|
368
|
+
const char *message;
|
|
369
|
+
|
|
370
|
+
/*
|
|
371
|
+
* The level of the diagnostic, see `pm_error_level_t` and
|
|
372
|
+
* `pm_warning_level_t` for possible values.
|
|
373
|
+
*/
|
|
374
|
+
uint8_t level;
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
/*
|
|
378
|
+
* Append a diagnostic to the given list of diagnostics that is using shared
|
|
379
|
+
* memory for its message.
|
|
380
|
+
*/
|
|
381
|
+
void pm_diagnostic_list_append(pm_arena_t *arena, pm_list_t *list, uint32_t start, uint32_t length, pm_diagnostic_id_t diag_id);
|
|
382
|
+
|
|
383
|
+
/*
|
|
384
|
+
* Append a diagnostic to the given list of diagnostics that is using a format
|
|
385
|
+
* string for its message.
|
|
386
|
+
*/
|
|
387
|
+
void pm_diagnostic_list_append_format(pm_arena_t *arena, pm_list_t *list, uint32_t start, uint32_t length, pm_diagnostic_id_t diag_id, ...);
|
|
388
|
+
|
|
389
|
+
#endif
|
|
@@ -1,128 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
144
|
-
|
|
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
|