yarp 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -8
  3. data/CONTRIBUTING.md +2 -2
  4. data/Makefile +5 -5
  5. data/README.md +11 -12
  6. data/config.yml +6 -2
  7. data/docs/build_system.md +21 -21
  8. data/docs/building.md +4 -4
  9. data/docs/configuration.md +25 -21
  10. data/docs/design.md +2 -2
  11. data/docs/encoding.md +17 -17
  12. data/docs/fuzzing.md +4 -4
  13. data/docs/heredocs.md +3 -3
  14. data/docs/mapping.md +94 -94
  15. data/docs/ripper.md +4 -4
  16. data/docs/ruby_api.md +11 -11
  17. data/docs/serialization.md +17 -16
  18. data/docs/testing.md +6 -6
  19. data/ext/prism/api_node.c +4725 -0
  20. data/ext/{yarp → prism}/api_pack.c +82 -82
  21. data/ext/{yarp → prism}/extconf.rb +13 -13
  22. data/ext/{yarp → prism}/extension.c +175 -168
  23. data/ext/prism/extension.h +18 -0
  24. data/include/prism/ast.h +1932 -0
  25. data/include/prism/defines.h +45 -0
  26. data/include/prism/diagnostic.h +231 -0
  27. data/include/{yarp/enc/yp_encoding.h → prism/enc/pm_encoding.h} +40 -40
  28. data/include/prism/node.h +41 -0
  29. data/include/prism/pack.h +141 -0
  30. data/include/{yarp → prism}/parser.h +143 -142
  31. data/include/prism/regexp.h +19 -0
  32. data/include/prism/unescape.h +48 -0
  33. data/include/prism/util/pm_buffer.h +51 -0
  34. data/include/{yarp/util/yp_char.h → prism/util/pm_char.h} +20 -20
  35. data/include/{yarp/util/yp_constant_pool.h → prism/util/pm_constant_pool.h} +26 -22
  36. data/include/{yarp/util/yp_list.h → prism/util/pm_list.h} +21 -21
  37. data/include/prism/util/pm_memchr.h +14 -0
  38. data/include/{yarp/util/yp_newline_list.h → prism/util/pm_newline_list.h} +11 -11
  39. data/include/prism/util/pm_state_stack.h +24 -0
  40. data/include/{yarp/util/yp_string.h → prism/util/pm_string.h} +20 -20
  41. data/include/prism/util/pm_string_list.h +25 -0
  42. data/include/{yarp/util/yp_strpbrk.h → prism/util/pm_strpbrk.h} +7 -7
  43. data/include/prism/version.h +4 -0
  44. data/include/prism.h +82 -0
  45. data/lib/prism/compiler.rb +465 -0
  46. data/lib/prism/debug.rb +157 -0
  47. data/lib/{yarp/desugar_visitor.rb → prism/desugar_compiler.rb} +4 -2
  48. data/lib/prism/dispatcher.rb +2051 -0
  49. data/lib/prism/dsl.rb +750 -0
  50. data/lib/{yarp → prism}/ffi.rb +66 -67
  51. data/lib/{yarp → prism}/lex_compat.rb +40 -43
  52. data/lib/{yarp/mutation_visitor.rb → prism/mutation_compiler.rb} +3 -3
  53. data/lib/{yarp → prism}/node.rb +2012 -2593
  54. data/lib/prism/node_ext.rb +55 -0
  55. data/lib/prism/node_inspector.rb +68 -0
  56. data/lib/{yarp → prism}/pack.rb +1 -1
  57. data/lib/{yarp → prism}/parse_result/comments.rb +1 -1
  58. data/lib/{yarp → prism}/parse_result/newlines.rb +1 -1
  59. data/lib/prism/parse_result.rb +266 -0
  60. data/lib/{yarp → prism}/pattern.rb +14 -14
  61. data/lib/{yarp → prism}/ripper_compat.rb +5 -5
  62. data/lib/{yarp → prism}/serialize.rb +12 -7
  63. data/lib/prism/visitor.rb +470 -0
  64. data/lib/prism.rb +64 -0
  65. data/lib/yarp.rb +2 -614
  66. data/src/diagnostic.c +213 -208
  67. data/src/enc/pm_big5.c +52 -0
  68. data/src/enc/pm_euc_jp.c +58 -0
  69. data/src/enc/{yp_gbk.c → pm_gbk.c} +16 -16
  70. data/src/enc/pm_shift_jis.c +56 -0
  71. data/src/enc/{yp_tables.c → pm_tables.c} +69 -69
  72. data/src/enc/{yp_unicode.c → pm_unicode.c} +40 -40
  73. data/src/enc/pm_windows_31j.c +56 -0
  74. data/src/node.c +1293 -1233
  75. data/src/pack.c +247 -247
  76. data/src/prettyprint.c +1479 -1479
  77. data/src/{yarp.c → prism.c} +5205 -5083
  78. data/src/regexp.c +132 -132
  79. data/src/serialize.c +1121 -1121
  80. data/src/token_type.c +169 -167
  81. data/src/unescape.c +106 -87
  82. data/src/util/pm_buffer.c +103 -0
  83. data/src/util/{yp_char.c → pm_char.c} +72 -72
  84. data/src/util/{yp_constant_pool.c → pm_constant_pool.c} +85 -64
  85. data/src/util/{yp_list.c → pm_list.c} +10 -10
  86. data/src/util/{yp_memchr.c → pm_memchr.c} +6 -4
  87. data/src/util/{yp_newline_list.c → pm_newline_list.c} +21 -21
  88. data/src/util/{yp_state_stack.c → pm_state_stack.c} +4 -4
  89. data/src/util/{yp_string.c → pm_string.c} +38 -38
  90. data/src/util/pm_string_list.c +29 -0
  91. data/src/util/{yp_strncasecmp.c → pm_strncasecmp.c} +1 -1
  92. data/src/util/{yp_strpbrk.c → pm_strpbrk.c} +8 -8
  93. data/yarp.gemspec +68 -59
  94. metadata +70 -61
  95. data/ext/yarp/api_node.c +0 -4728
  96. data/ext/yarp/extension.h +0 -18
  97. data/include/yarp/ast.h +0 -1929
  98. data/include/yarp/defines.h +0 -45
  99. data/include/yarp/diagnostic.h +0 -226
  100. data/include/yarp/node.h +0 -42
  101. data/include/yarp/pack.h +0 -141
  102. data/include/yarp/regexp.h +0 -19
  103. data/include/yarp/unescape.h +0 -44
  104. data/include/yarp/util/yp_buffer.h +0 -51
  105. data/include/yarp/util/yp_memchr.h +0 -14
  106. data/include/yarp/util/yp_state_stack.h +0 -24
  107. data/include/yarp/util/yp_string_list.h +0 -25
  108. data/include/yarp/version.h +0 -4
  109. data/include/yarp.h +0 -82
  110. data/src/enc/yp_big5.c +0 -52
  111. data/src/enc/yp_euc_jp.c +0 -58
  112. data/src/enc/yp_shift_jis.c +0 -56
  113. data/src/enc/yp_windows_31j.c +0 -56
  114. data/src/util/yp_buffer.c +0 -101
  115. data/src/util/yp_string_list.c +0 -29
data/src/diagnostic.c CHANGED
@@ -1,4 +1,4 @@
1
- #include "yarp/diagnostic.h"
1
+ #include "prism/diagnostic.h"
2
2
 
3
3
  /*
4
4
  ## Message composition
@@ -39,7 +39,7 @@
39
39
  - e.g., "`*` splat argument" is clearer and more complete than "splat argument" or "`*` argument"
40
40
 
41
41
 
42
- ## Error names (YP_ERR_*)
42
+ ## Error names (PM_ERR_*)
43
43
 
44
44
  - When appropriate, prefer node name to token name.
45
45
  - e.g., prefer "SPLAT" to "STAR" in the context of argument parsing.
@@ -48,210 +48,215 @@
48
48
  - Try to order the words in the name from more general to more specific,
49
49
  - e.g., "INVALID_NUMBER_DECIMAL" is better than "DECIMAL_INVALID_NUMBER".
50
50
  - When in doubt, look for similar patterns and name them so that they are grouped when lexically
51
- sorted. See YP_ERR_ARGUMENT_NO_FORWARDING_* for an example.
51
+ sorted. See PM_ERR_ARGUMENT_NO_FORWARDING_* for an example.
52
52
  */
53
53
 
54
- static const char* const diagnostic_messages[YP_DIAGNOSTIC_ID_LEN] = {
55
- [YP_ERR_ALIAS_ARGUMENT] = "Invalid argument being passed to `alias`; expected a bare word, symbol, constant, or global variable",
56
- [YP_ERR_AMPAMPEQ_MULTI_ASSIGN] = "Unexpected `&&=` in a multiple assignment",
57
- [YP_ERR_ARGUMENT_AFTER_BLOCK] = "Unexpected argument after a block argument",
58
- [YP_ERR_ARGUMENT_BARE_HASH] = "Unexpected bare hash argument",
59
- [YP_ERR_ARGUMENT_BLOCK_MULTI] = "Multiple block arguments; only one block is allowed",
60
- [YP_ERR_ARGUMENT_FORMAL_CLASS] = "Invalid formal argument; formal argument cannot be a class variable",
61
- [YP_ERR_ARGUMENT_FORMAL_CONSTANT] = "Invalid formal argument; formal argument cannot be a constant",
62
- [YP_ERR_ARGUMENT_FORMAL_GLOBAL] = "Invalid formal argument; formal argument cannot be a global variable",
63
- [YP_ERR_ARGUMENT_FORMAL_IVAR] = "Invalid formal argument; formal argument cannot be an instance variable",
64
- [YP_ERR_ARGUMENT_NO_FORWARDING_AMP] = "Unexpected `&` when the parent method is not forwarding",
65
- [YP_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES] = "Unexpected `...` when the parent method is not forwarding",
66
- [YP_ERR_ARGUMENT_NO_FORWARDING_STAR] = "Unexpected `*` when the parent method is not forwarding",
67
- [YP_ERR_ARGUMENT_SPLAT_AFTER_ASSOC_SPLAT] = "Unexpected `*` splat argument after a `**` keyword splat argument",
68
- [YP_ERR_ARGUMENT_SPLAT_AFTER_SPLAT] = "Unexpected `*` splat argument after a `*` splat argument",
69
- [YP_ERR_ARGUMENT_TERM_PAREN] = "Expected a `)` to close the arguments",
70
- [YP_ERR_ARGUMENT_UNEXPECTED_BLOCK] = "Unexpected `{` after a method call without parenthesis",
71
- [YP_ERR_ARRAY_ELEMENT] = "Expected an element for the array",
72
- [YP_ERR_ARRAY_EXPRESSION] = "Expected an expression for the array element",
73
- [YP_ERR_ARRAY_EXPRESSION_AFTER_STAR] = "Expected an expression after `*` in the array",
74
- [YP_ERR_ARRAY_SEPARATOR] = "Expected a `,` separator for the array elements",
75
- [YP_ERR_ARRAY_TERM] = "Expected a `]` to close the array",
76
- [YP_ERR_BEGIN_LONELY_ELSE] = "Unexpected `else` in `begin` block; a `rescue` clause must precede `else`",
77
- [YP_ERR_BEGIN_TERM] = "Expected an `end` to close the `begin` statement",
78
- [YP_ERR_BEGIN_UPCASE_BRACE] = "Expected a `{` after `BEGIN`",
79
- [YP_ERR_BEGIN_UPCASE_TERM] = "Expected a `}` to close the `BEGIN` statement",
80
- [YP_ERR_BLOCK_PARAM_LOCAL_VARIABLE] = "Expected a local variable name in the block parameters",
81
- [YP_ERR_BLOCK_PARAM_PIPE_TERM] = "Expected the block parameters to end with `|`",
82
- [YP_ERR_BLOCK_TERM_BRACE] = "Expected a block beginning with `{` to end with `}`",
83
- [YP_ERR_BLOCK_TERM_END] = "Expected a block beginning with `do` to end with `end`",
84
- [YP_ERR_CANNOT_PARSE_EXPRESSION] = "Cannot parse the expression",
85
- [YP_ERR_CANNOT_PARSE_STRING_PART] = "Cannot parse the string part",
86
- [YP_ERR_CASE_EXPRESSION_AFTER_CASE] = "Expected an expression after `case`",
87
- [YP_ERR_CASE_EXPRESSION_AFTER_WHEN] = "Expected an expression after `when`",
88
- [YP_ERR_CASE_MISSING_CONDITIONS] = "Expected a `when` or `in` clause after `case`",
89
- [YP_ERR_CASE_TERM] = "Expected an `end` to close the `case` statement",
90
- [YP_ERR_CLASS_IN_METHOD] = "Unexpected class definition in a method body",
91
- [YP_ERR_CLASS_NAME] = "Expected a constant name after `class`",
92
- [YP_ERR_CLASS_SUPERCLASS] = "Expected a superclass after `<`",
93
- [YP_ERR_CLASS_TERM] = "Expected an `end` to close the `class` statement",
94
- [YP_ERR_CONDITIONAL_ELSIF_PREDICATE] = "Expected a predicate expression for the `elsif` statement",
95
- [YP_ERR_CONDITIONAL_IF_PREDICATE] = "Expected a predicate expression for the `if` statement",
96
- [YP_ERR_CONDITIONAL_TERM] = "Expected an `end` to close the conditional clause",
97
- [YP_ERR_CONDITIONAL_TERM_ELSE] = "Expected an `end` to close the `else` clause",
98
- [YP_ERR_CONDITIONAL_UNLESS_PREDICATE] = "Expected a predicate expression for the `unless` statement",
99
- [YP_ERR_CONDITIONAL_UNTIL_PREDICATE] = "Expected a predicate expression for the `until` statement",
100
- [YP_ERR_CONDITIONAL_WHILE_PREDICATE] = "Expected a predicate expression for the `while` statement",
101
- [YP_ERR_CONSTANT_PATH_COLON_COLON_CONSTANT] = "Expected a constant after the `::` operator",
102
- [YP_ERR_DEF_ENDLESS] = "Could not parse the endless method body",
103
- [YP_ERR_DEF_ENDLESS_SETTER] = "Invalid method name; a setter method cannot be defined in an endless method definition",
104
- [YP_ERR_DEF_NAME] = "Expected a method name",
105
- [YP_ERR_DEF_NAME_AFTER_RECEIVER] = "Expected a method name after the receiver",
106
- [YP_ERR_DEF_PARAMS_TERM] = "Expected a delimiter to close the parameters",
107
- [YP_ERR_DEF_PARAMS_TERM_PAREN] = "Expected a `)` to close the parameters",
108
- [YP_ERR_DEF_RECEIVER] = "Expected a receiver for the method definition",
109
- [YP_ERR_DEF_RECEIVER_TERM] = "Expected a `.` or `::` after the receiver in a method definition",
110
- [YP_ERR_DEF_TERM] = "Expected an `end` to close the `def` statement",
111
- [YP_ERR_DEFINED_EXPRESSION] = "Expected an expression after `defined?`",
112
- [YP_ERR_EMBDOC_TERM] = "Could not find a terminator for the embedded document",
113
- [YP_ERR_EMBEXPR_END] = "Expected a `}` to close the embedded expression",
114
- [YP_ERR_EMBVAR_INVALID] = "Invalid embedded variable",
115
- [YP_ERR_END_UPCASE_BRACE] = "Expected a `{` after `END`",
116
- [YP_ERR_END_UPCASE_TERM] = "Expected a `}` to close the `END` statement",
117
- [YP_ERR_ESCAPE_INVALID_CONTROL] = "Invalid control escape sequence",
118
- [YP_ERR_ESCAPE_INVALID_CONTROL_REPEAT] = "Invalid control escape sequence; control cannot be repeated",
119
- [YP_ERR_ESCAPE_INVALID_HEXADECIMAL] = "Invalid hexadecimal escape sequence",
120
- [YP_ERR_ESCAPE_INVALID_META] = "Invalid meta escape sequence",
121
- [YP_ERR_ESCAPE_INVALID_META_REPEAT] = "Invalid meta escape sequence; meta cannot be repeated",
122
- [YP_ERR_ESCAPE_INVALID_UNICODE] = "Invalid Unicode escape sequence",
123
- [YP_ERR_ESCAPE_INVALID_UNICODE_CM_FLAGS] = "Invalid Unicode escape sequence; Unicode cannot be combined with control or meta flags",
124
- [YP_ERR_ESCAPE_INVALID_UNICODE_LITERAL] = "Invalid Unicode escape sequence; multiple codepoints are not allowed in a character literal",
125
- [YP_ERR_ESCAPE_INVALID_UNICODE_LONG] = "Invalid Unicode escape sequence; maximum length is 6 digits",
126
- [YP_ERR_ESCAPE_INVALID_UNICODE_TERM] = "Invalid Unicode escape sequence; needs closing `}`",
127
- [YP_ERR_EXPECT_ARGUMENT] = "Expected an argument",
128
- [YP_ERR_EXPECT_EOL_AFTER_STATEMENT] = "Expected a newline or semicolon after the statement",
129
- [YP_ERR_EXPECT_EXPRESSION_AFTER_AMPAMPEQ] = "Expected an expression after `&&=`",
130
- [YP_ERR_EXPECT_EXPRESSION_AFTER_PIPEPIPEEQ] = "Expected an expression after `||=`",
131
- [YP_ERR_EXPECT_EXPRESSION_AFTER_COMMA] = "Expected an expression after `,`",
132
- [YP_ERR_EXPECT_EXPRESSION_AFTER_EQUAL] = "Expected an expression after `=`",
133
- [YP_ERR_EXPECT_EXPRESSION_AFTER_LESS_LESS] = "Expected an expression after `<<`",
134
- [YP_ERR_EXPECT_EXPRESSION_AFTER_LPAREN] = "Expected an expression after `(`",
135
- [YP_ERR_EXPECT_EXPRESSION_AFTER_OPERATOR] = "Expected an expression after the operator",
136
- [YP_ERR_EXPECT_EXPRESSION_AFTER_SPLAT] = "Expected an expression after `*` splat in an argument",
137
- [YP_ERR_EXPECT_EXPRESSION_AFTER_SPLAT_HASH] = "Expected an expression after `**` in a hash",
138
- [YP_ERR_EXPECT_EXPRESSION_AFTER_STAR] = "Expected an expression after `*`",
139
- [YP_ERR_EXPECT_IDENT_REQ_PARAMETER] = "Expected an identifier for the required parameter",
140
- [YP_ERR_EXPECT_LPAREN_REQ_PARAMETER] = "Expected a `(` to start a required parameter",
141
- [YP_ERR_EXPECT_RBRACKET] = "Expected a matching `]`",
142
- [YP_ERR_EXPECT_RPAREN] = "Expected a matching `)`",
143
- [YP_ERR_EXPECT_RPAREN_AFTER_MULTI] = "Expected a `)` after multiple assignment",
144
- [YP_ERR_EXPECT_RPAREN_REQ_PARAMETER] = "Expected a `)` to end a required parameter",
145
- [YP_ERR_EXPECT_STRING_CONTENT] = "Expected string content after opening string delimiter",
146
- [YP_ERR_EXPECT_WHEN_DELIMITER] = "Expected a delimiter after the predicates of a `when` clause",
147
- [YP_ERR_EXPRESSION_BARE_HASH] = "Unexpected bare hash in expression",
148
- [YP_ERR_FOR_COLLECTION] = "Expected a collection after the `in` in a `for` statement",
149
- [YP_ERR_FOR_INDEX] = "Expected an index after `for`",
150
- [YP_ERR_FOR_IN] = "Expected an `in` after the index in a `for` statement",
151
- [YP_ERR_FOR_TERM] = "Expected an `end` to close the `for` loop",
152
- [YP_ERR_HASH_EXPRESSION_AFTER_LABEL] = "Expected an expression after the label in a hash",
153
- [YP_ERR_HASH_KEY] = "Expected a key in the hash literal",
154
- [YP_ERR_HASH_ROCKET] = "Expected a `=>` between the hash key and value",
155
- [YP_ERR_HASH_TERM] = "Expected a `}` to close the hash literal",
156
- [YP_ERR_HASH_VALUE] = "Expected a value in the hash literal",
157
- [YP_ERR_HEREDOC_TERM] = "Could not find a terminator for the heredoc",
158
- [YP_ERR_INCOMPLETE_QUESTION_MARK] = "Incomplete expression at `?`",
159
- [YP_ERR_INCOMPLETE_VARIABLE_CLASS] = "Incomplete class variable",
160
- [YP_ERR_INCOMPLETE_VARIABLE_INSTANCE] = "Incomplete instance variable",
161
- [YP_ERR_INVALID_ENCODING_MAGIC_COMMENT] = "Unknown or invalid encoding in the magic comment",
162
- [YP_ERR_INVALID_FLOAT_EXPONENT] = "Invalid exponent",
163
- [YP_ERR_INVALID_NUMBER_BINARY] = "Invalid binary number",
164
- [YP_ERR_INVALID_NUMBER_DECIMAL] = "Invalid decimal number",
165
- [YP_ERR_INVALID_NUMBER_HEXADECIMAL] = "Invalid hexadecimal number",
166
- [YP_ERR_INVALID_NUMBER_OCTAL] = "Invalid octal number",
167
- [YP_ERR_INVALID_NUMBER_UNDERSCORE] = "Invalid underscore placement in number",
168
- [YP_ERR_INVALID_PERCENT] = "Invalid `%` token", // TODO WHAT?
169
- [YP_ERR_INVALID_TOKEN] = "Invalid token", // TODO WHAT?
170
- [YP_ERR_INVALID_VARIABLE_GLOBAL] = "Invalid global variable",
171
- [YP_ERR_LAMBDA_OPEN] = "Expected a `do` keyword or a `{` to open the lambda block",
172
- [YP_ERR_LAMBDA_TERM_BRACE] = "Expected a lambda block beginning with `{` to end with `}`",
173
- [YP_ERR_LAMBDA_TERM_END] = "Expected a lambda block beginning with `do` to end with `end`",
174
- [YP_ERR_LIST_I_LOWER_ELEMENT] = "Expected a symbol in a `%i` list",
175
- [YP_ERR_LIST_I_LOWER_TERM] = "Expected a closing delimiter for the `%i` list",
176
- [YP_ERR_LIST_I_UPPER_ELEMENT] = "Expected a symbol in a `%I` list",
177
- [YP_ERR_LIST_I_UPPER_TERM] = "Expected a closing delimiter for the `%I` list",
178
- [YP_ERR_LIST_W_LOWER_ELEMENT] = "Expected a string in a `%w` list",
179
- [YP_ERR_LIST_W_LOWER_TERM] = "Expected a closing delimiter for the `%w` list",
180
- [YP_ERR_LIST_W_UPPER_ELEMENT] = "Expected a string in a `%W` list",
181
- [YP_ERR_LIST_W_UPPER_TERM] = "Expected a closing delimiter for the `%W` list",
182
- [YP_ERR_MALLOC_FAILED] = "Failed to allocate memory",
183
- [YP_ERR_MODULE_IN_METHOD] = "Unexpected module definition in a method body",
184
- [YP_ERR_MODULE_NAME] = "Expected a constant name after `module`",
185
- [YP_ERR_MODULE_TERM] = "Expected an `end` to close the `module` statement",
186
- [YP_ERR_MULTI_ASSIGN_MULTI_SPLATS] = "Multiple splats in multiple assignment",
187
- [YP_ERR_NOT_EXPRESSION] = "Expected an expression after `not`",
188
- [YP_ERR_NUMBER_LITERAL_UNDERSCORE] = "Number literal ending with a `_`",
189
- [YP_ERR_NUMBERED_PARAMETER_NOT_ALLOWED] = "Numbered parameters are not allowed alongside explicit parameters",
190
- [YP_ERR_NUMBERED_PARAMETER_OUTER_SCOPE] = "Numbered parameter is already used in outer scope",
191
- [YP_ERR_OPERATOR_MULTI_ASSIGN] = "Unexpected operator for a multiple assignment",
192
- [YP_ERR_OPERATOR_WRITE_BLOCK] = "Unexpected operator after a call with a block",
193
- [YP_ERR_PARAMETER_ASSOC_SPLAT_MULTI] = "Unexpected multiple `**` splat parameters",
194
- [YP_ERR_PARAMETER_BLOCK_MULTI] = "Multiple block parameters; only one block is allowed",
195
- [YP_ERR_PARAMETER_NAME_REPEAT] = "Repeated parameter name",
196
- [YP_ERR_PARAMETER_NO_DEFAULT] = "Expected a default value for the parameter",
197
- [YP_ERR_PARAMETER_NO_DEFAULT_KW] = "Expected a default value for the keyword parameter",
198
- [YP_ERR_PARAMETER_NUMBERED_RESERVED] = "Token reserved for a numbered parameter",
199
- [YP_ERR_PARAMETER_ORDER] = "Unexpected parameter order",
200
- [YP_ERR_PARAMETER_SPLAT_MULTI] = "Unexpected multiple `*` splat parameters",
201
- [YP_ERR_PARAMETER_STAR] = "Unexpected parameter `*`",
202
- [YP_ERR_PARAMETER_WILD_LOOSE_COMMA] = "Unexpected `,` in parameters",
203
- [YP_ERR_PATTERN_EXPRESSION_AFTER_BRACKET] = "Expected a pattern expression after the `[` operator",
204
- [YP_ERR_PATTERN_EXPRESSION_AFTER_COMMA] = "Expected a pattern expression after `,`",
205
- [YP_ERR_PATTERN_EXPRESSION_AFTER_HROCKET] = "Expected a pattern expression after `=>`",
206
- [YP_ERR_PATTERN_EXPRESSION_AFTER_IN] = "Expected a pattern expression after the `in` keyword",
207
- [YP_ERR_PATTERN_EXPRESSION_AFTER_KEY] = "Expected a pattern expression after the key",
208
- [YP_ERR_PATTERN_EXPRESSION_AFTER_PAREN] = "Expected a pattern expression after the `(` operator",
209
- [YP_ERR_PATTERN_EXPRESSION_AFTER_PIN] = "Expected a pattern expression after the `^` pin operator",
210
- [YP_ERR_PATTERN_EXPRESSION_AFTER_PIPE] = "Expected a pattern expression after the `|` operator",
211
- [YP_ERR_PATTERN_EXPRESSION_AFTER_RANGE] = "Expected a pattern expression after the range operator",
212
- [YP_ERR_PATTERN_HASH_KEY] = "Expected a key in the hash pattern",
213
- [YP_ERR_PATTERN_HASH_KEY_LABEL] = "Expected a label as the key in the hash pattern", // TODO // THIS // AND // ABOVE // IS WEIRD
214
- [YP_ERR_PATTERN_IDENT_AFTER_HROCKET] = "Expected an identifier after the `=>` operator",
215
- [YP_ERR_PATTERN_LABEL_AFTER_COMMA] = "Expected a label after the `,` in the hash pattern",
216
- [YP_ERR_PATTERN_REST] = "Unexpected rest pattern",
217
- [YP_ERR_PATTERN_TERM_BRACE] = "Expected a `}` to close the pattern expression",
218
- [YP_ERR_PATTERN_TERM_BRACKET] = "Expected a `]` to close the pattern expression",
219
- [YP_ERR_PATTERN_TERM_PAREN] = "Expected a `)` to close the pattern expression",
220
- [YP_ERR_PIPEPIPEEQ_MULTI_ASSIGN] = "Unexpected `||=` in a multiple assignment",
221
- [YP_ERR_REGEXP_TERM] = "Expected a closing delimiter for the regular expression",
222
- [YP_ERR_RESCUE_EXPRESSION] = "Expected a rescued expression",
223
- [YP_ERR_RESCUE_MODIFIER_VALUE] = "Expected a value after the `rescue` modifier",
224
- [YP_ERR_RESCUE_TERM] = "Expected a closing delimiter for the `rescue` clause",
225
- [YP_ERR_RESCUE_VARIABLE] = "Expected an exception variable after `=>` in a rescue statement",
226
- [YP_ERR_RETURN_INVALID] = "Invalid `return` in a class or module body",
227
- [YP_ERR_STRING_CONCATENATION] = "Expected a string for concatenation",
228
- [YP_ERR_STRING_INTERPOLATED_TERM] = "Expected a closing delimiter for the interpolated string",
229
- [YP_ERR_STRING_LITERAL_TERM] = "Expected a closing delimiter for the string literal",
230
- [YP_ERR_SYMBOL_INVALID] = "Invalid symbol", // TODO expected symbol? yarp.c ~9719
231
- [YP_ERR_SYMBOL_TERM_DYNAMIC] = "Expected a closing delimiter for the dynamic symbol",
232
- [YP_ERR_SYMBOL_TERM_INTERPOLATED] = "Expected a closing delimiter for the interpolated symbol",
233
- [YP_ERR_TERNARY_COLON] = "Expected a `:` after the true expression of a ternary operator",
234
- [YP_ERR_TERNARY_EXPRESSION_FALSE] = "Expected an expression after `:` in the ternary operator",
235
- [YP_ERR_TERNARY_EXPRESSION_TRUE] = "Expected an expression after `?` in the ternary operator",
236
- [YP_ERR_UNDEF_ARGUMENT] = "Invalid argument being passed to `undef`; expected a bare word, constant, or symbol argument",
237
- [YP_ERR_UNARY_RECEIVER_BANG] = "Expected a receiver for unary `!`",
238
- [YP_ERR_UNARY_RECEIVER_MINUS] = "Expected a receiver for unary `-`",
239
- [YP_ERR_UNARY_RECEIVER_PLUS] = "Expected a receiver for unary `+`",
240
- [YP_ERR_UNARY_RECEIVER_TILDE] = "Expected a receiver for unary `~`",
241
- [YP_ERR_UNTIL_TERM] = "Expected an `end` to close the `until` statement",
242
- [YP_ERR_WHILE_TERM] = "Expected an `end` to close the `while` statement",
243
- [YP_ERR_WRITE_TARGET_READONLY] = "Immutable variable as a write target",
244
- [YP_ERR_WRITE_TARGET_UNEXPECTED] = "Unexpected write target",
245
- [YP_ERR_XSTRING_TERM] = "Expected a closing delimiter for the `%x` or backtick string",
246
- [YP_WARN_AMBIGUOUS_FIRST_ARGUMENT_MINUS] = "Ambiguous first argument; put parentheses or a space even after `-` operator",
247
- [YP_WARN_AMBIGUOUS_FIRST_ARGUMENT_PLUS] = "Ambiguous first argument; put parentheses or a space even after `+` operator",
248
- [YP_WARN_AMBIGUOUS_PREFIX_STAR] = "Ambiguous `*` has been interpreted as an argument prefix",
249
- [YP_WARN_AMBIGUOUS_SLASH] = "Ambiguous `/`; wrap regexp in parentheses or add a space after `/` operator",
54
+ static const char* const diagnostic_messages[PM_DIAGNOSTIC_ID_LEN] = {
55
+ [PM_ERR_ALIAS_ARGUMENT] = "Invalid argument being passed to `alias`; expected a bare word, symbol, constant, or global variable",
56
+ [PM_ERR_AMPAMPEQ_MULTI_ASSIGN] = "Unexpected `&&=` in a multiple assignment",
57
+ [PM_ERR_ARGUMENT_AFTER_BLOCK] = "Unexpected argument after a block argument",
58
+ [PM_ERR_ARGUMENT_BARE_HASH] = "Unexpected bare hash argument",
59
+ [PM_ERR_ARGUMENT_BLOCK_MULTI] = "Multiple block arguments; only one block is allowed",
60
+ [PM_ERR_ARGUMENT_FORMAL_CLASS] = "Invalid formal argument; formal argument cannot be a class variable",
61
+ [PM_ERR_ARGUMENT_FORMAL_CONSTANT] = "Invalid formal argument; formal argument cannot be a constant",
62
+ [PM_ERR_ARGUMENT_FORMAL_GLOBAL] = "Invalid formal argument; formal argument cannot be a global variable",
63
+ [PM_ERR_ARGUMENT_FORMAL_IVAR] = "Invalid formal argument; formal argument cannot be an instance variable",
64
+ [PM_ERR_ARGUMENT_NO_FORWARDING_AMP] = "Unexpected `&` when the parent method is not forwarding",
65
+ [PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES] = "Unexpected `...` when the parent method is not forwarding",
66
+ [PM_ERR_ARGUMENT_NO_FORWARDING_STAR] = "Unexpected `*` when the parent method is not forwarding",
67
+ [PM_ERR_ARGUMENT_SPLAT_AFTER_ASSOC_SPLAT] = "Unexpected `*` splat argument after a `**` keyword splat argument",
68
+ [PM_ERR_ARGUMENT_SPLAT_AFTER_SPLAT] = "Unexpected `*` splat argument after a `*` splat argument",
69
+ [PM_ERR_ARGUMENT_TERM_PAREN] = "Expected a `)` to close the arguments",
70
+ [PM_ERR_ARGUMENT_UNEXPECTED_BLOCK] = "Unexpected `{` after a method call without parenthesis",
71
+ [PM_ERR_ARRAY_ELEMENT] = "Expected an element for the array",
72
+ [PM_ERR_ARRAY_EXPRESSION] = "Expected an expression for the array element",
73
+ [PM_ERR_ARRAY_EXPRESSION_AFTER_STAR] = "Expected an expression after `*` in the array",
74
+ [PM_ERR_ARRAY_SEPARATOR] = "Expected a `,` separator for the array elements",
75
+ [PM_ERR_ARRAY_TERM] = "Expected a `]` to close the array",
76
+ [PM_ERR_BEGIN_LONELY_ELSE] = "Unexpected `else` in `begin` block; a `rescue` clause must precede `else`",
77
+ [PM_ERR_BEGIN_TERM] = "Expected an `end` to close the `begin` statement",
78
+ [PM_ERR_BEGIN_UPCASE_BRACE] = "Expected a `{` after `BEGIN`",
79
+ [PM_ERR_BEGIN_UPCASE_TERM] = "Expected a `}` to close the `BEGIN` statement",
80
+ [PM_ERR_BEGIN_UPCASE_TOPLEVEL] = "BEGIN is permitted only at toplevel",
81
+ [PM_ERR_BLOCK_PARAM_LOCAL_VARIABLE] = "Expected a local variable name in the block parameters",
82
+ [PM_ERR_BLOCK_PARAM_PIPE_TERM] = "Expected the block parameters to end with `|`",
83
+ [PM_ERR_BLOCK_TERM_BRACE] = "Expected a block beginning with `{` to end with `}`",
84
+ [PM_ERR_BLOCK_TERM_END] = "Expected a block beginning with `do` to end with `end`",
85
+ [PM_ERR_CANNOT_PARSE_EXPRESSION] = "Cannot parse the expression",
86
+ [PM_ERR_CANNOT_PARSE_STRING_PART] = "Cannot parse the string part",
87
+ [PM_ERR_CASE_EXPRESSION_AFTER_CASE] = "Expected an expression after `case`",
88
+ [PM_ERR_CASE_EXPRESSION_AFTER_WHEN] = "Expected an expression after `when`",
89
+ [PM_ERR_CASE_MISSING_CONDITIONS] = "Expected a `when` or `in` clause after `case`",
90
+ [PM_ERR_CASE_TERM] = "Expected an `end` to close the `case` statement",
91
+ [PM_ERR_CLASS_IN_METHOD] = "Unexpected class definition in a method body",
92
+ [PM_ERR_CLASS_NAME] = "Expected a constant name after `class`",
93
+ [PM_ERR_CLASS_SUPERCLASS] = "Expected a superclass after `<`",
94
+ [PM_ERR_CLASS_TERM] = "Expected an `end` to close the `class` statement",
95
+ [PM_ERR_CLASS_UNEXPECTED_END] = "Unexpected `end`, expecting ';' or '\n'",
96
+ [PM_ERR_CONDITIONAL_ELSIF_PREDICATE] = "Expected a predicate expression for the `elsif` statement",
97
+ [PM_ERR_CONDITIONAL_IF_PREDICATE] = "Expected a predicate expression for the `if` statement",
98
+ [PM_ERR_CONDITIONAL_PREDICATE_TERM] = "Expected `then` or `;` or '\n'",
99
+ [PM_ERR_CONDITIONAL_TERM] = "Expected an `end` to close the conditional clause",
100
+ [PM_ERR_CONDITIONAL_TERM_ELSE] = "Expected an `end` to close the `else` clause",
101
+ [PM_ERR_CONDITIONAL_UNLESS_PREDICATE] = "Expected a predicate expression for the `unless` statement",
102
+ [PM_ERR_CONDITIONAL_UNTIL_PREDICATE] = "Expected a predicate expression for the `until` statement",
103
+ [PM_ERR_CONDITIONAL_WHILE_PREDICATE] = "Expected a predicate expression for the `while` statement",
104
+ [PM_ERR_CONSTANT_PATH_COLON_COLON_CONSTANT] = "Expected a constant after the `::` operator",
105
+ [PM_ERR_DEF_ENDLESS] = "Could not parse the endless method body",
106
+ [PM_ERR_DEF_ENDLESS_SETTER] = "Invalid method name; a setter method cannot be defined in an endless method definition",
107
+ [PM_ERR_DEF_NAME] = "Expected a method name",
108
+ [PM_ERR_DEF_NAME_AFTER_RECEIVER] = "Expected a method name after the receiver",
109
+ [PM_ERR_DEF_PARAMS_TERM] = "Expected a delimiter to close the parameters",
110
+ [PM_ERR_DEF_PARAMS_TERM_PAREN] = "Expected a `)` to close the parameters",
111
+ [PM_ERR_DEF_RECEIVER] = "Expected a receiver for the method definition",
112
+ [PM_ERR_DEF_RECEIVER_TERM] = "Expected a `.` or `::` after the receiver in a method definition",
113
+ [PM_ERR_DEF_TERM] = "Expected an `end` to close the `def` statement",
114
+ [PM_ERR_DEFINED_EXPRESSION] = "Expected an expression after `defined?`",
115
+ [PM_ERR_EMBDOC_TERM] = "Could not find a terminator for the embedded document",
116
+ [PM_ERR_EMBEXPR_END] = "Expected a `}` to close the embedded expression",
117
+ [PM_ERR_EMBVAR_INVALID] = "Invalid embedded variable",
118
+ [PM_ERR_END_UPCASE_BRACE] = "Expected a `{` after `END`",
119
+ [PM_ERR_END_UPCASE_TERM] = "Expected a `}` to close the `END` statement",
120
+ [PM_ERR_ESCAPE_INVALID_CONTROL] = "Invalid control escape sequence",
121
+ [PM_ERR_ESCAPE_INVALID_CONTROL_REPEAT] = "Invalid control escape sequence; control cannot be repeated",
122
+ [PM_ERR_ESCAPE_INVALID_HEXADECIMAL] = "Invalid hexadecimal escape sequence",
123
+ [PM_ERR_ESCAPE_INVALID_META] = "Invalid meta escape sequence",
124
+ [PM_ERR_ESCAPE_INVALID_META_REPEAT] = "Invalid meta escape sequence; meta cannot be repeated",
125
+ [PM_ERR_ESCAPE_INVALID_UNICODE] = "Invalid Unicode escape sequence",
126
+ [PM_ERR_ESCAPE_INVALID_UNICODE_CM_FLAGS] = "Invalid Unicode escape sequence; Unicode cannot be combined with control or meta flags",
127
+ [PM_ERR_ESCAPE_INVALID_UNICODE_LITERAL] = "Invalid Unicode escape sequence; multiple codepoints are not allowed in a character literal",
128
+ [PM_ERR_ESCAPE_INVALID_UNICODE_LONG] = "Invalid Unicode escape sequence; maximum length is 6 digits",
129
+ [PM_ERR_ESCAPE_INVALID_UNICODE_TERM] = "Invalid Unicode escape sequence; needs closing `}`",
130
+ [PM_ERR_EXPECT_ARGUMENT] = "Expected an argument",
131
+ [PM_ERR_EXPECT_EOL_AFTER_STATEMENT] = "Expected a newline or semicolon after the statement",
132
+ [PM_ERR_EXPECT_EXPRESSION_AFTER_AMPAMPEQ] = "Expected an expression after `&&=`",
133
+ [PM_ERR_EXPECT_EXPRESSION_AFTER_PIPEPIPEEQ] = "Expected an expression after `||=`",
134
+ [PM_ERR_EXPECT_EXPRESSION_AFTER_COMMA] = "Expected an expression after `,`",
135
+ [PM_ERR_EXPECT_EXPRESSION_AFTER_EQUAL] = "Expected an expression after `=`",
136
+ [PM_ERR_EXPECT_EXPRESSION_AFTER_LESS_LESS] = "Expected an expression after `<<`",
137
+ [PM_ERR_EXPECT_EXPRESSION_AFTER_LPAREN] = "Expected an expression after `(`",
138
+ [PM_ERR_EXPECT_EXPRESSION_AFTER_OPERATOR] = "Expected an expression after the operator",
139
+ [PM_ERR_EXPECT_EXPRESSION_AFTER_SPLAT] = "Expected an expression after `*` splat in an argument",
140
+ [PM_ERR_EXPECT_EXPRESSION_AFTER_SPLAT_HASH] = "Expected an expression after `**` in a hash",
141
+ [PM_ERR_EXPECT_EXPRESSION_AFTER_STAR] = "Expected an expression after `*`",
142
+ [PM_ERR_EXPECT_IDENT_REQ_PARAMETER] = "Expected an identifier for the required parameter",
143
+ [PM_ERR_EXPECT_LPAREN_REQ_PARAMETER] = "Expected a `(` to start a required parameter",
144
+ [PM_ERR_EXPECT_RBRACKET] = "Expected a matching `]`",
145
+ [PM_ERR_EXPECT_RPAREN] = "Expected a matching `)`",
146
+ [PM_ERR_EXPECT_RPAREN_AFTER_MULTI] = "Expected a `)` after multiple assignment",
147
+ [PM_ERR_EXPECT_RPAREN_REQ_PARAMETER] = "Expected a `)` to end a required parameter",
148
+ [PM_ERR_EXPECT_STRING_CONTENT] = "Expected string content after opening string delimiter",
149
+ [PM_ERR_EXPECT_WHEN_DELIMITER] = "Expected a delimiter after the predicates of a `when` clause",
150
+ [PM_ERR_EXPRESSION_BARE_HASH] = "Unexpected bare hash in expression",
151
+ [PM_ERR_FOR_COLLECTION] = "Expected a collection after the `in` in a `for` statement",
152
+ [PM_ERR_FOR_INDEX] = "Expected an index after `for`",
153
+ [PM_ERR_FOR_IN] = "Expected an `in` after the index in a `for` statement",
154
+ [PM_ERR_FOR_TERM] = "Expected an `end` to close the `for` loop",
155
+ [PM_ERR_HASH_EXPRESSION_AFTER_LABEL] = "Expected an expression after the label in a hash",
156
+ [PM_ERR_HASH_KEY] = "Expected a key in the hash literal",
157
+ [PM_ERR_HASH_ROCKET] = "Expected a `=>` between the hash key and value",
158
+ [PM_ERR_HASH_TERM] = "Expected a `}` to close the hash literal",
159
+ [PM_ERR_HASH_VALUE] = "Expected a value in the hash literal",
160
+ [PM_ERR_HEREDOC_TERM] = "Could not find a terminator for the heredoc",
161
+ [PM_ERR_INCOMPLETE_QUESTION_MARK] = "Incomplete expression at `?`",
162
+ [PM_ERR_INCOMPLETE_VARIABLE_CLASS] = "Incomplete class variable",
163
+ [PM_ERR_INCOMPLETE_VARIABLE_INSTANCE] = "Incomplete instance variable",
164
+ [PM_ERR_INVALID_ENCODING_MAGIC_COMMENT] = "Unknown or invalid encoding in the magic comment",
165
+ [PM_ERR_INVALID_FLOAT_EXPONENT] = "Invalid exponent",
166
+ [PM_ERR_INVALID_NUMBER_BINARY] = "Invalid binary number",
167
+ [PM_ERR_INVALID_NUMBER_DECIMAL] = "Invalid decimal number",
168
+ [PM_ERR_INVALID_NUMBER_HEXADECIMAL] = "Invalid hexadecimal number",
169
+ [PM_ERR_INVALID_NUMBER_OCTAL] = "Invalid octal number",
170
+ [PM_ERR_INVALID_NUMBER_UNDERSCORE] = "Invalid underscore placement in number",
171
+ [PM_ERR_INVALID_PERCENT] = "Invalid `%` token", // TODO WHAT?
172
+ [PM_ERR_INVALID_TOKEN] = "Invalid token", // TODO WHAT?
173
+ [PM_ERR_INVALID_VARIABLE_GLOBAL] = "Invalid global variable",
174
+ [PM_ERR_LAMBDA_OPEN] = "Expected a `do` keyword or a `{` to open the lambda block",
175
+ [PM_ERR_LAMBDA_TERM_BRACE] = "Expected a lambda block beginning with `{` to end with `}`",
176
+ [PM_ERR_LAMBDA_TERM_END] = "Expected a lambda block beginning with `do` to end with `end`",
177
+ [PM_ERR_LIST_I_LOWER_ELEMENT] = "Expected a symbol in a `%i` list",
178
+ [PM_ERR_LIST_I_LOWER_TERM] = "Expected a closing delimiter for the `%i` list",
179
+ [PM_ERR_LIST_I_UPPER_ELEMENT] = "Expected a symbol in a `%I` list",
180
+ [PM_ERR_LIST_I_UPPER_TERM] = "Expected a closing delimiter for the `%I` list",
181
+ [PM_ERR_LIST_W_LOWER_ELEMENT] = "Expected a string in a `%w` list",
182
+ [PM_ERR_LIST_W_LOWER_TERM] = "Expected a closing delimiter for the `%w` list",
183
+ [PM_ERR_LIST_W_UPPER_ELEMENT] = "Expected a string in a `%W` list",
184
+ [PM_ERR_LIST_W_UPPER_TERM] = "Expected a closing delimiter for the `%W` list",
185
+ [PM_ERR_MALLOC_FAILED] = "Failed to allocate memory",
186
+ [PM_ERR_MODULE_IN_METHOD] = "Unexpected module definition in a method body",
187
+ [PM_ERR_MODULE_NAME] = "Expected a constant name after `module`",
188
+ [PM_ERR_MODULE_TERM] = "Expected an `end` to close the `module` statement",
189
+ [PM_ERR_MULTI_ASSIGN_MULTI_SPLATS] = "Multiple splats in multiple assignment",
190
+ [PM_ERR_NOT_EXPRESSION] = "Expected an expression after `not`",
191
+ [PM_ERR_NUMBER_LITERAL_UNDERSCORE] = "Number literal ending with a `_`",
192
+ [PM_ERR_NUMBERED_PARAMETER_NOT_ALLOWED] = "Numbered parameters are not allowed alongside explicit parameters",
193
+ [PM_ERR_NUMBERED_PARAMETER_OUTER_SCOPE] = "Numbered parameter is already used in outer scope",
194
+ [PM_ERR_OPERATOR_MULTI_ASSIGN] = "Unexpected operator for a multiple assignment",
195
+ [PM_ERR_OPERATOR_WRITE_BLOCK] = "Unexpected operator after a call with a block",
196
+ [PM_ERR_PARAMETER_ASSOC_SPLAT_MULTI] = "Unexpected multiple `**` splat parameters",
197
+ [PM_ERR_PARAMETER_BLOCK_MULTI] = "Multiple block parameters; only one block is allowed",
198
+ [PM_ERR_PARAMETER_METHOD_NAME] = "Unexpected name for a parameter",
199
+ [PM_ERR_PARAMETER_NAME_REPEAT] = "Repeated parameter name",
200
+ [PM_ERR_PARAMETER_NO_DEFAULT] = "Expected a default value for the parameter",
201
+ [PM_ERR_PARAMETER_NO_DEFAULT_KW] = "Expected a default value for the keyword parameter",
202
+ [PM_ERR_PARAMETER_NUMBERED_RESERVED] = "Token reserved for a numbered parameter",
203
+ [PM_ERR_PARAMETER_ORDER] = "Unexpected parameter order",
204
+ [PM_ERR_PARAMETER_SPLAT_MULTI] = "Unexpected multiple `*` splat parameters",
205
+ [PM_ERR_PARAMETER_STAR] = "Unexpected parameter `*`",
206
+ [PM_ERR_PARAMETER_UNEXPECTED_FWD] = "Unexpected `...` in parameters",
207
+ [PM_ERR_PARAMETER_WILD_LOOSE_COMMA] = "Unexpected `,` in parameters",
208
+ [PM_ERR_PATTERN_EXPRESSION_AFTER_BRACKET] = "Expected a pattern expression after the `[` operator",
209
+ [PM_ERR_PATTERN_EXPRESSION_AFTER_COMMA] = "Expected a pattern expression after `,`",
210
+ [PM_ERR_PATTERN_EXPRESSION_AFTER_HROCKET] = "Expected a pattern expression after `=>`",
211
+ [PM_ERR_PATTERN_EXPRESSION_AFTER_IN] = "Expected a pattern expression after the `in` keyword",
212
+ [PM_ERR_PATTERN_EXPRESSION_AFTER_KEY] = "Expected a pattern expression after the key",
213
+ [PM_ERR_PATTERN_EXPRESSION_AFTER_PAREN] = "Expected a pattern expression after the `(` operator",
214
+ [PM_ERR_PATTERN_EXPRESSION_AFTER_PIN] = "Expected a pattern expression after the `^` pin operator",
215
+ [PM_ERR_PATTERN_EXPRESSION_AFTER_PIPE] = "Expected a pattern expression after the `|` operator",
216
+ [PM_ERR_PATTERN_EXPRESSION_AFTER_RANGE] = "Expected a pattern expression after the range operator",
217
+ [PM_ERR_PATTERN_HASH_KEY] = "Expected a key in the hash pattern",
218
+ [PM_ERR_PATTERN_HASH_KEY_LABEL] = "Expected a label as the key in the hash pattern", // TODO // THIS // AND // ABOVE // IS WEIRD
219
+ [PM_ERR_PATTERN_IDENT_AFTER_HROCKET] = "Expected an identifier after the `=>` operator",
220
+ [PM_ERR_PATTERN_LABEL_AFTER_COMMA] = "Expected a label after the `,` in the hash pattern",
221
+ [PM_ERR_PATTERN_REST] = "Unexpected rest pattern",
222
+ [PM_ERR_PATTERN_TERM_BRACE] = "Expected a `}` to close the pattern expression",
223
+ [PM_ERR_PATTERN_TERM_BRACKET] = "Expected a `]` to close the pattern expression",
224
+ [PM_ERR_PATTERN_TERM_PAREN] = "Expected a `)` to close the pattern expression",
225
+ [PM_ERR_PIPEPIPEEQ_MULTI_ASSIGN] = "Unexpected `||=` in a multiple assignment",
226
+ [PM_ERR_REGEXP_TERM] = "Expected a closing delimiter for the regular expression",
227
+ [PM_ERR_RESCUE_EXPRESSION] = "Expected a rescued expression",
228
+ [PM_ERR_RESCUE_MODIFIER_VALUE] = "Expected a value after the `rescue` modifier",
229
+ [PM_ERR_RESCUE_TERM] = "Expected a closing delimiter for the `rescue` clause",
230
+ [PM_ERR_RESCUE_VARIABLE] = "Expected an exception variable after `=>` in a rescue statement",
231
+ [PM_ERR_RETURN_INVALID] = "Invalid `return` in a class or module body",
232
+ [PM_ERR_STRING_CONCATENATION] = "Expected a string for concatenation",
233
+ [PM_ERR_STRING_INTERPOLATED_TERM] = "Expected a closing delimiter for the interpolated string",
234
+ [PM_ERR_STRING_LITERAL_TERM] = "Expected a closing delimiter for the string literal",
235
+ [PM_ERR_SYMBOL_INVALID] = "Invalid symbol", // TODO expected symbol? prism.c ~9719
236
+ [PM_ERR_SYMBOL_TERM_DYNAMIC] = "Expected a closing delimiter for the dynamic symbol",
237
+ [PM_ERR_SYMBOL_TERM_INTERPOLATED] = "Expected a closing delimiter for the interpolated symbol",
238
+ [PM_ERR_TERNARY_COLON] = "Expected a `:` after the true expression of a ternary operator",
239
+ [PM_ERR_TERNARY_EXPRESSION_FALSE] = "Expected an expression after `:` in the ternary operator",
240
+ [PM_ERR_TERNARY_EXPRESSION_TRUE] = "Expected an expression after `?` in the ternary operator",
241
+ [PM_ERR_UNDEF_ARGUMENT] = "Invalid argument being passed to `undef`; expected a bare word, constant, or symbol argument",
242
+ [PM_ERR_UNARY_RECEIVER_BANG] = "Expected a receiver for unary `!`",
243
+ [PM_ERR_UNARY_RECEIVER_MINUS] = "Expected a receiver for unary `-`",
244
+ [PM_ERR_UNARY_RECEIVER_PLUS] = "Expected a receiver for unary `+`",
245
+ [PM_ERR_UNARY_RECEIVER_TILDE] = "Expected a receiver for unary `~`",
246
+ [PM_ERR_UNTIL_TERM] = "Expected an `end` to close the `until` statement",
247
+ [PM_ERR_WHILE_TERM] = "Expected an `end` to close the `while` statement",
248
+ [PM_ERR_WRITE_TARGET_READONLY] = "Immutable variable as a write target",
249
+ [PM_ERR_WRITE_TARGET_UNEXPECTED] = "Unexpected write target",
250
+ [PM_ERR_XSTRING_TERM] = "Expected a closing delimiter for the `%x` or backtick string",
251
+ [PM_WARN_AMBIGUOUS_FIRST_ARGUMENT_MINUS] = "Ambiguous first argument; put parentheses or a space even after `-` operator",
252
+ [PM_WARN_AMBIGUOUS_FIRST_ARGUMENT_PLUS] = "Ambiguous first argument; put parentheses or a space even after `+` operator",
253
+ [PM_WARN_AMBIGUOUS_PREFIX_STAR] = "Ambiguous `*` has been interpreted as an argument prefix",
254
+ [PM_WARN_AMBIGUOUS_SLASH] = "Ambiguous `/`; wrap regexp in parentheses or add a space after `/` operator",
250
255
  };
251
256
 
252
257
  static const char*
253
- yp_diagnostic_message(yp_diagnostic_id_t diag_id) {
254
- assert(diag_id < YP_DIAGNOSTIC_ID_LEN);
258
+ pm_diagnostic_message(pm_diagnostic_id_t diag_id) {
259
+ assert(diag_id < PM_DIAGNOSTIC_ID_LEN);
255
260
  const char *message = diagnostic_messages[diag_id];
256
261
  assert(message);
257
262
  return message;
@@ -259,24 +264,24 @@ yp_diagnostic_message(yp_diagnostic_id_t diag_id) {
259
264
 
260
265
  // Append an error to the given list of diagnostic.
261
266
  bool
262
- yp_diagnostic_list_append(yp_list_t *list, const uint8_t *start, const uint8_t *end, yp_diagnostic_id_t diag_id) {
263
- yp_diagnostic_t *diagnostic = (yp_diagnostic_t *) malloc(sizeof(yp_diagnostic_t));
267
+ pm_diagnostic_list_append(pm_list_t *list, const uint8_t *start, const uint8_t *end, pm_diagnostic_id_t diag_id) {
268
+ pm_diagnostic_t *diagnostic = (pm_diagnostic_t *) malloc(sizeof(pm_diagnostic_t));
264
269
  if (diagnostic == NULL) return false;
265
270
 
266
- *diagnostic = (yp_diagnostic_t) { .start = start, .end = end, .message = yp_diagnostic_message(diag_id) };
267
- yp_list_append(list, (yp_list_node_t *) diagnostic);
271
+ *diagnostic = (pm_diagnostic_t) { .start = start, .end = end, .message = pm_diagnostic_message(diag_id) };
272
+ pm_list_append(list, (pm_list_node_t *) diagnostic);
268
273
  return true;
269
274
  }
270
275
 
271
276
  // Deallocate the internal state of the given diagnostic list.
272
277
  void
273
- yp_diagnostic_list_free(yp_list_t *list) {
274
- yp_list_node_t *node, *next;
278
+ pm_diagnostic_list_free(pm_list_t *list) {
279
+ pm_list_node_t *node, *next;
275
280
 
276
281
  for (node = list->head; node != NULL; node = next) {
277
282
  next = node->next;
278
283
 
279
- yp_diagnostic_t *diagnostic = (yp_diagnostic_t *) node;
284
+ pm_diagnostic_t *diagnostic = (pm_diagnostic_t *) node;
280
285
  free(diagnostic);
281
286
  }
282
287
  }
data/src/enc/pm_big5.c ADDED
@@ -0,0 +1,52 @@
1
+ #include "prism/enc/pm_encoding.h"
2
+
3
+ static size_t
4
+ pm_encoding_big5_char_width(const uint8_t *b, ptrdiff_t n) {
5
+ // These are the single byte characters.
6
+ if (*b < 0x80) {
7
+ return 1;
8
+ }
9
+
10
+ // These are the double byte characters.
11
+ if ((n > 1) && (b[0] >= 0xA1 && b[0] <= 0xFE) && (b[1] >= 0x40 && b[1] <= 0xFE)) {
12
+ return 2;
13
+ }
14
+
15
+ return 0;
16
+ }
17
+
18
+ static size_t
19
+ pm_encoding_big5_alpha_char(const uint8_t *b, ptrdiff_t n) {
20
+ if (pm_encoding_big5_char_width(b, n) == 1) {
21
+ return pm_encoding_ascii_alpha_char(b, n);
22
+ } else {
23
+ return 0;
24
+ }
25
+ }
26
+
27
+ static size_t
28
+ pm_encoding_big5_alnum_char(const uint8_t *b, ptrdiff_t n) {
29
+ if (pm_encoding_big5_char_width(b, n) == 1) {
30
+ return pm_encoding_ascii_alnum_char(b, n);
31
+ } else {
32
+ return 0;
33
+ }
34
+ }
35
+
36
+ static bool
37
+ pm_encoding_big5_isupper_char(const uint8_t *b, ptrdiff_t n) {
38
+ if (pm_encoding_big5_char_width(b, n) == 1) {
39
+ return pm_encoding_ascii_isupper_char(b, n);
40
+ } else {
41
+ return false;
42
+ }
43
+ }
44
+
45
+ pm_encoding_t pm_encoding_big5 = {
46
+ .name = "big5",
47
+ .char_width = pm_encoding_big5_char_width,
48
+ .alnum_char = pm_encoding_big5_alnum_char,
49
+ .alpha_char = pm_encoding_big5_alpha_char,
50
+ .isupper_char = pm_encoding_big5_isupper_char,
51
+ .multibyte = true
52
+ };