Skip to content

Commit 54b72f0

Browse files
committed
1 parent 36ef931 commit 54b72f0

File tree

19 files changed

+4175
-1798
lines changed

19 files changed

+4175
-1798
lines changed

src/main/c/yarp/include/prism/ast.h

Lines changed: 163 additions & 138 deletions
Large diffs are not rendered by default.

src/main/c/yarp/include/prism/diagnostic.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ typedef struct {
3030

3131
/** The message associated with the diagnostic. */
3232
const char *message;
33+
34+
/**
35+
* Whether or not the memory related to the message of this diagnostic is
36+
* owned by this diagnostic. If it is, it needs to be freed when the
37+
* diagnostic is freed.
38+
*/
39+
bool owned;
3340
} pm_diagnostic_t;
3441

3542
/**
@@ -40,12 +47,14 @@ typedef enum {
4047
PM_ERR_ALIAS_ARGUMENT,
4148
PM_ERR_AMPAMPEQ_MULTI_ASSIGN,
4249
PM_ERR_ARGUMENT_AFTER_BLOCK,
50+
PM_ERR_ARGUMENT_AFTER_FORWARDING_ELLIPSES,
4351
PM_ERR_ARGUMENT_BARE_HASH,
4452
PM_ERR_ARGUMENT_BLOCK_MULTI,
4553
PM_ERR_ARGUMENT_FORMAL_CLASS,
4654
PM_ERR_ARGUMENT_FORMAL_CONSTANT,
4755
PM_ERR_ARGUMENT_FORMAL_GLOBAL,
4856
PM_ERR_ARGUMENT_FORMAL_IVAR,
57+
PM_ERR_ARGUMENT_FORWARDING_UNBOUND,
4958
PM_ERR_ARGUMENT_NO_FORWARDING_AMP,
5059
PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES,
5160
PM_ERR_ARGUMENT_NO_FORWARDING_STAR,
@@ -71,6 +80,7 @@ typedef enum {
7180
PM_ERR_CANNOT_PARSE_STRING_PART,
7281
PM_ERR_CASE_EXPRESSION_AFTER_CASE,
7382
PM_ERR_CASE_EXPRESSION_AFTER_WHEN,
83+
PM_ERR_CASE_MATCH_MISSING_PREDICATE,
7484
PM_ERR_CASE_MISSING_CONDITIONS,
7585
PM_ERR_CASE_TERM,
7686
PM_ERR_CLASS_IN_METHOD,
@@ -216,6 +226,10 @@ typedef enum {
216226
PM_ERR_RESCUE_TERM,
217227
PM_ERR_RESCUE_VARIABLE,
218228
PM_ERR_RETURN_INVALID,
229+
PM_ERR_STATEMENT_ALIAS,
230+
PM_ERR_STATEMENT_POSTEXE_END,
231+
PM_ERR_STATEMENT_PREEXE_BEGIN,
232+
PM_ERR_STATEMENT_UNDEF,
219233
PM_ERR_STRING_CONCATENATION,
220234
PM_ERR_STRING_INTERPOLATED_TERM,
221235
PM_ERR_STRING_LITERAL_TERM,
@@ -240,13 +254,15 @@ typedef enum {
240254
PM_WARN_AMBIGUOUS_FIRST_ARGUMENT_PLUS,
241255
PM_WARN_AMBIGUOUS_PREFIX_STAR,
242256
PM_WARN_AMBIGUOUS_SLASH,
257+
PM_WARN_END_IN_METHOD,
243258

244259
/* This must be the last member. */
245260
PM_DIAGNOSTIC_ID_LEN,
246261
} pm_diagnostic_id_t;
247262

248263
/**
249-
* Append a diagnostic to the given list of diagnostics.
264+
* Append a diagnostic to the given list of diagnostics that is using shared
265+
* memory for its message.
250266
*
251267
* @param list The list to append to.
252268
* @param start The start of the diagnostic.
@@ -256,6 +272,19 @@ typedef enum {
256272
*/
257273
bool pm_diagnostic_list_append(pm_list_t *list, const uint8_t *start, const uint8_t *end, pm_diagnostic_id_t diag_id);
258274

275+
/**
276+
* Append a diagnostic to the given list of diagnostics that is using a format
277+
* string for its message.
278+
*
279+
* @param list The list to append to.
280+
* @param start The start of the diagnostic.
281+
* @param end The end of the diagnostic.
282+
* @param diag_id The diagnostic ID.
283+
* @param ... The arguments to the format string for the message.
284+
* @return Whether the diagnostic was successfully appended.
285+
*/
286+
bool pm_diagnostic_list_append_format(pm_list_t *list, const uint8_t *start, const uint8_t *end, pm_diagnostic_id_t diag_id, ...);
287+
259288
/**
260289
* Deallocate the internal state of the given diagnostic list.
261290
*

src/main/c/yarp/include/prism/enc/pm_encoding.h

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,31 @@ extern const uint8_t pm_encoding_unicode_table[256];
158158
extern pm_encoding_t pm_encoding_ascii;
159159
extern pm_encoding_t pm_encoding_ascii_8bit;
160160
extern pm_encoding_t pm_encoding_big5;
161+
extern pm_encoding_t pm_encoding_big5_hkscs;
162+
extern pm_encoding_t pm_encoding_big5_uao;
163+
extern pm_encoding_t pm_encoding_cp51932;
164+
extern pm_encoding_t pm_encoding_cp850;
165+
extern pm_encoding_t pm_encoding_cp852;
166+
extern pm_encoding_t pm_encoding_cp855;
167+
extern pm_encoding_t pm_encoding_cp949;
161168
extern pm_encoding_t pm_encoding_euc_jp;
169+
extern pm_encoding_t pm_encoding_gb1988;
162170
extern pm_encoding_t pm_encoding_gbk;
171+
extern pm_encoding_t pm_encoding_ibm437;
172+
extern pm_encoding_t pm_encoding_ibm720;
173+
extern pm_encoding_t pm_encoding_ibm737;
174+
extern pm_encoding_t pm_encoding_ibm775;
175+
extern pm_encoding_t pm_encoding_ibm852;
176+
extern pm_encoding_t pm_encoding_ibm855;
177+
extern pm_encoding_t pm_encoding_ibm857;
178+
extern pm_encoding_t pm_encoding_ibm860;
179+
extern pm_encoding_t pm_encoding_ibm861;
180+
extern pm_encoding_t pm_encoding_ibm862;
181+
extern pm_encoding_t pm_encoding_ibm863;
182+
extern pm_encoding_t pm_encoding_ibm864;
183+
extern pm_encoding_t pm_encoding_ibm865;
184+
extern pm_encoding_t pm_encoding_ibm866;
185+
extern pm_encoding_t pm_encoding_ibm869;
163186
extern pm_encoding_t pm_encoding_iso_8859_1;
164187
extern pm_encoding_t pm_encoding_iso_8859_2;
165188
extern pm_encoding_t pm_encoding_iso_8859_3;
@@ -176,11 +199,31 @@ extern pm_encoding_t pm_encoding_iso_8859_14;
176199
extern pm_encoding_t pm_encoding_iso_8859_15;
177200
extern pm_encoding_t pm_encoding_iso_8859_16;
178201
extern pm_encoding_t pm_encoding_koi8_r;
202+
extern pm_encoding_t pm_encoding_koi8_u;
203+
extern pm_encoding_t pm_encoding_mac_cent_euro;
204+
extern pm_encoding_t pm_encoding_mac_croatian;
205+
extern pm_encoding_t pm_encoding_mac_cyrillic;
206+
extern pm_encoding_t pm_encoding_mac_greek;
207+
extern pm_encoding_t pm_encoding_mac_iceland;
208+
extern pm_encoding_t pm_encoding_mac_roman;
209+
extern pm_encoding_t pm_encoding_mac_romania;
210+
extern pm_encoding_t pm_encoding_mac_thai;
211+
extern pm_encoding_t pm_encoding_mac_turkish;
212+
extern pm_encoding_t pm_encoding_mac_ukraine;
179213
extern pm_encoding_t pm_encoding_shift_jis;
214+
extern pm_encoding_t pm_encoding_tis_620;
180215
extern pm_encoding_t pm_encoding_utf_8;
181216
extern pm_encoding_t pm_encoding_utf8_mac;
182-
extern pm_encoding_t pm_encoding_windows_31j;
217+
extern pm_encoding_t pm_encoding_windows_1250;
183218
extern pm_encoding_t pm_encoding_windows_1251;
184219
extern pm_encoding_t pm_encoding_windows_1252;
220+
extern pm_encoding_t pm_encoding_windows_1253;
221+
extern pm_encoding_t pm_encoding_windows_1254;
222+
extern pm_encoding_t pm_encoding_windows_1255;
223+
extern pm_encoding_t pm_encoding_windows_1256;
224+
extern pm_encoding_t pm_encoding_windows_1257;
225+
extern pm_encoding_t pm_encoding_windows_1258;
226+
extern pm_encoding_t pm_encoding_windows_31j;
227+
extern pm_encoding_t pm_encoding_windows_874;
185228

186229
#endif

src/main/c/yarp/include/prism/version.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
/**
1515
* The minor version of the Prism library as an int.
1616
*/
17-
#define PRISM_VERSION_MINOR 17
17+
#define PRISM_VERSION_MINOR 18
1818

1919
/**
2020
* The patch version of the Prism library as an int.
2121
*/
22-
#define PRISM_VERSION_PATCH 1
22+
#define PRISM_VERSION_PATCH 0
2323

2424
/**
2525
* The version of the Prism library as a constant string.
2626
*/
27-
#define PRISM_VERSION "0.17.1"
27+
#define PRISM_VERSION "0.18.0"
2828

2929
#endif

src/main/c/yarp/src/diagnostic.c

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ static const char* const diagnostic_messages[PM_DIAGNOSTIC_ID_LEN] = {
5454
[PM_ERR_ALIAS_ARGUMENT] = "Invalid argument being passed to `alias`; expected a bare word, symbol, constant, or global variable",
5555
[PM_ERR_AMPAMPEQ_MULTI_ASSIGN] = "Unexpected `&&=` in a multiple assignment",
5656
[PM_ERR_ARGUMENT_AFTER_BLOCK] = "Unexpected argument after a block argument",
57+
[PM_ERR_ARGUMENT_AFTER_FORWARDING_ELLIPSES] = "Unexpected argument after `...`",
5758
[PM_ERR_ARGUMENT_BARE_HASH] = "Unexpected bare hash argument",
5859
[PM_ERR_ARGUMENT_BLOCK_MULTI] = "Multiple block arguments; only one block is allowed",
5960
[PM_ERR_ARGUMENT_FORMAL_CLASS] = "Invalid formal argument; formal argument cannot be a class variable",
6061
[PM_ERR_ARGUMENT_FORMAL_CONSTANT] = "Invalid formal argument; formal argument cannot be a constant",
6162
[PM_ERR_ARGUMENT_FORMAL_GLOBAL] = "Invalid formal argument; formal argument cannot be a global variable",
6263
[PM_ERR_ARGUMENT_FORMAL_IVAR] = "Invalid formal argument; formal argument cannot be an instance variable",
64+
[PM_ERR_ARGUMENT_FORWARDING_UNBOUND] = "Unexpected `...` in an non-parenthesized call",
6365
[PM_ERR_ARGUMENT_NO_FORWARDING_AMP] = "Unexpected `&` when the parent method is not forwarding",
6466
[PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES] = "Unexpected `...` when the parent method is not forwarding",
6567
[PM_ERR_ARGUMENT_NO_FORWARDING_STAR] = "Unexpected `*` when the parent method is not forwarding",
@@ -85,6 +87,7 @@ static const char* const diagnostic_messages[PM_DIAGNOSTIC_ID_LEN] = {
8587
[PM_ERR_CANNOT_PARSE_STRING_PART] = "Cannot parse the string part",
8688
[PM_ERR_CASE_EXPRESSION_AFTER_CASE] = "Expected an expression after `case`",
8789
[PM_ERR_CASE_EXPRESSION_AFTER_WHEN] = "Expected an expression after `when`",
90+
[PM_ERR_CASE_MATCH_MISSING_PREDICATE] = "Expected a predicate for a case matching statement",
8891
[PM_ERR_CASE_MISSING_CONDITIONS] = "Expected a `when` or `in` clause after `case`",
8992
[PM_ERR_CASE_TERM] = "Expected an `end` to close the `case` statement",
9093
[PM_ERR_CLASS_IN_METHOD] = "Unexpected class definition in a method body",
@@ -199,7 +202,7 @@ static const char* const diagnostic_messages[PM_DIAGNOSTIC_ID_LEN] = {
199202
[PM_ERR_PARAMETER_NAME_REPEAT] = "Repeated parameter name",
200203
[PM_ERR_PARAMETER_NO_DEFAULT] = "Expected a default value for the parameter",
201204
[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",
205+
[PM_ERR_PARAMETER_NUMBERED_RESERVED] = "%.2s is reserved for a numbered parameter",
203206
[PM_ERR_PARAMETER_ORDER] = "Unexpected parameter order",
204207
[PM_ERR_PARAMETER_SPLAT_MULTI] = "Unexpected multiple `*` splat parameters",
205208
[PM_ERR_PARAMETER_STAR] = "Unexpected parameter `*`",
@@ -229,6 +232,10 @@ static const char* const diagnostic_messages[PM_DIAGNOSTIC_ID_LEN] = {
229232
[PM_ERR_RESCUE_TERM] = "Expected a closing delimiter for the `rescue` clause",
230233
[PM_ERR_RESCUE_VARIABLE] = "Expected an exception variable after `=>` in a rescue statement",
231234
[PM_ERR_RETURN_INVALID] = "Invalid `return` in a class or module body",
235+
[PM_ERR_STATEMENT_ALIAS] = "Unexpected an `alias` at a non-statement position",
236+
[PM_ERR_STATEMENT_POSTEXE_END] = "Unexpected an `END` at a non-statement position",
237+
[PM_ERR_STATEMENT_PREEXE_BEGIN] = "Unexpected a `BEGIN` at a non-statement position",
238+
[PM_ERR_STATEMENT_UNDEF] = "Unexpected an `undef` at a non-statement position",
232239
[PM_ERR_STRING_CONCATENATION] = "Expected a string for concatenation",
233240
[PM_ERR_STRING_INTERPOLATED_TERM] = "Expected a closing delimiter for the interpolated string",
234241
[PM_ERR_STRING_LITERAL_TERM] = "Expected a closing delimiter for the string literal",
@@ -253,13 +260,16 @@ static const char* const diagnostic_messages[PM_DIAGNOSTIC_ID_LEN] = {
253260
[PM_WARN_AMBIGUOUS_FIRST_ARGUMENT_PLUS] = "Ambiguous first argument; put parentheses or a space even after `+` operator",
254261
[PM_WARN_AMBIGUOUS_PREFIX_STAR] = "Ambiguous `*` has been interpreted as an argument prefix",
255262
[PM_WARN_AMBIGUOUS_SLASH] = "Ambiguous `/`; wrap regexp in parentheses or add a space after `/` operator",
263+
[PM_WARN_END_IN_METHOD] = "END in method; use at_exit",
256264
};
257265

258266
static const char*
259267
pm_diagnostic_message(pm_diagnostic_id_t diag_id) {
260268
assert(diag_id < PM_DIAGNOSTIC_ID_LEN);
269+
261270
const char *message = diagnostic_messages[diag_id];
262271
assert(message);
272+
263273
return message;
264274
}
265275

@@ -271,7 +281,57 @@ pm_diagnostic_list_append(pm_list_t *list, const uint8_t *start, const uint8_t *
271281
pm_diagnostic_t *diagnostic = (pm_diagnostic_t *) calloc(sizeof(pm_diagnostic_t), 1);
272282
if (diagnostic == NULL) return false;
273283

274-
*diagnostic = (pm_diagnostic_t) { .start = start, .end = end, .message = pm_diagnostic_message(diag_id) };
284+
*diagnostic = (pm_diagnostic_t) {
285+
.start = start,
286+
.end = end,
287+
.message = pm_diagnostic_message(diag_id),
288+
.owned = false
289+
};
290+
291+
pm_list_append(list, (pm_list_node_t *) diagnostic);
292+
return true;
293+
}
294+
295+
/**
296+
* Append a diagnostic to the given list of diagnostics that is using a format
297+
* string for its message.
298+
*/
299+
bool
300+
pm_diagnostic_list_append_format(pm_list_t *list, const uint8_t *start, const uint8_t *end, pm_diagnostic_id_t diag_id, ...) {
301+
va_list arguments;
302+
va_start(arguments, diag_id);
303+
304+
const char *format = pm_diagnostic_message(diag_id);
305+
int result = vsnprintf(NULL, 0, format, arguments);
306+
va_end(arguments);
307+
308+
if (result < 0) {
309+
return false;
310+
}
311+
312+
pm_diagnostic_t *diagnostic = (pm_diagnostic_t *) calloc(sizeof(pm_diagnostic_t), 1);
313+
if (diagnostic == NULL) {
314+
return false;
315+
}
316+
317+
size_t length = (size_t) (result + 1);
318+
char *message = (char *) malloc(length);
319+
if (message == NULL) {
320+
free(diagnostic);
321+
return false;
322+
}
323+
324+
va_start(arguments, diag_id);
325+
vsnprintf(message, length, format, arguments);
326+
va_end(arguments);
327+
328+
*diagnostic = (pm_diagnostic_t) {
329+
.start = start,
330+
.end = end,
331+
.message = message,
332+
.owned = true
333+
};
334+
275335
pm_list_append(list, (pm_list_node_t *) diagnostic);
276336
return true;
277337
}
@@ -285,8 +345,9 @@ pm_diagnostic_list_free(pm_list_t *list) {
285345

286346
for (node = list->head; node != NULL; node = next) {
287347
next = node->next;
288-
289348
pm_diagnostic_t *diagnostic = (pm_diagnostic_t *) node;
349+
350+
if (diagnostic->owned) free((void *) diagnostic->message);
290351
free(diagnostic);
291352
}
292353
}

src/main/c/yarp/src/enc/pm_big5.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ pm_encoding_big5_char_width(const uint8_t *b, ptrdiff_t n) {
1515
return 0;
1616
}
1717

18+
static size_t
19+
pm_encoding_big5_star_char_width(const uint8_t *b, ptrdiff_t n) {
20+
// These are the single byte characters.
21+
if (*b < 0x80) {
22+
return 1;
23+
}
24+
25+
// These are the double byte characters.
26+
if ((n > 1) && (b[0] >= 0x87 && b[0] <= 0xFE) &&
27+
((b[1] >= 0x40 && b[1] <= 0x7E) || (b[1] >= 0xA1 && b[1] <= 0xFE))) {
28+
return 2;
29+
}
30+
31+
return 0;
32+
}
33+
1834
static size_t
1935
pm_encoding_big5_alpha_char(const uint8_t *b, ptrdiff_t n) {
2036
if (pm_encoding_big5_char_width(b, n) == 1) {
@@ -24,6 +40,15 @@ pm_encoding_big5_alpha_char(const uint8_t *b, ptrdiff_t n) {
2440
}
2541
}
2642

43+
static size_t
44+
pm_encoding_big5_star_alpha_char(const uint8_t *b, ptrdiff_t n) {
45+
if (pm_encoding_big5_star_char_width(b, n) == 1) {
46+
return pm_encoding_ascii_alpha_char(b, n);
47+
} else {
48+
return 0;
49+
}
50+
}
51+
2752
static size_t
2853
pm_encoding_big5_alnum_char(const uint8_t *b, ptrdiff_t n) {
2954
if (pm_encoding_big5_char_width(b, n) == 1) {
@@ -33,6 +58,15 @@ pm_encoding_big5_alnum_char(const uint8_t *b, ptrdiff_t n) {
3358
}
3459
}
3560

61+
static size_t
62+
pm_encoding_big5_star_alnum_char(const uint8_t *b, ptrdiff_t n) {
63+
if (pm_encoding_big5_star_char_width(b, n) == 1) {
64+
return pm_encoding_ascii_alnum_char(b, n);
65+
} else {
66+
return 0;
67+
}
68+
}
69+
3670
static bool
3771
pm_encoding_big5_isupper_char(const uint8_t *b, ptrdiff_t n) {
3872
if (pm_encoding_big5_char_width(b, n) == 1) {
@@ -42,6 +76,15 @@ pm_encoding_big5_isupper_char(const uint8_t *b, ptrdiff_t n) {
4276
}
4377
}
4478

79+
static bool
80+
pm_encoding_big5_star_isupper_char(const uint8_t *b, ptrdiff_t n) {
81+
if (pm_encoding_big5_star_char_width(b, n) == 1) {
82+
return pm_encoding_ascii_isupper_char(b, n);
83+
} else {
84+
return false;
85+
}
86+
}
87+
4588
/** Big5 encoding */
4689
pm_encoding_t pm_encoding_big5 = {
4790
.name = "big5",
@@ -51,3 +94,23 @@ pm_encoding_t pm_encoding_big5 = {
5194
.isupper_char = pm_encoding_big5_isupper_char,
5295
.multibyte = true
5396
};
97+
98+
/** Big5-HKSCS encoding */
99+
pm_encoding_t pm_encoding_big5_hkscs = {
100+
.name = "big5-hkscs",
101+
.char_width = pm_encoding_big5_star_char_width,
102+
.alnum_char = pm_encoding_big5_star_alnum_char,
103+
.alpha_char = pm_encoding_big5_star_alpha_char,
104+
.isupper_char = pm_encoding_big5_star_isupper_char,
105+
.multibyte = true
106+
};
107+
108+
/** Big5-UAO encoding */
109+
pm_encoding_t pm_encoding_big5_uao = {
110+
.name = "big5-uao",
111+
.char_width = pm_encoding_big5_star_char_width,
112+
.alnum_char = pm_encoding_big5_star_alnum_char,
113+
.alpha_char = pm_encoding_big5_star_alpha_char,
114+
.isupper_char = pm_encoding_big5_star_isupper_char,
115+
.multibyte = true
116+
};

0 commit comments

Comments
 (0)