yarp 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -8
- data/CONTRIBUTING.md +2 -2
- data/Makefile +5 -5
- data/README.md +11 -12
- data/config.yml +6 -2
- data/docs/build_system.md +21 -21
- data/docs/building.md +4 -4
- data/docs/configuration.md +25 -21
- data/docs/design.md +2 -2
- data/docs/encoding.md +17 -17
- data/docs/fuzzing.md +4 -4
- data/docs/heredocs.md +3 -3
- data/docs/mapping.md +94 -94
- data/docs/ripper.md +4 -4
- data/docs/ruby_api.md +11 -11
- data/docs/serialization.md +17 -16
- data/docs/testing.md +6 -6
- data/ext/prism/api_node.c +4725 -0
- data/ext/{yarp → prism}/api_pack.c +82 -82
- data/ext/{yarp → prism}/extconf.rb +13 -13
- data/ext/{yarp → prism}/extension.c +175 -168
- data/ext/prism/extension.h +18 -0
- data/include/prism/ast.h +1932 -0
- data/include/prism/defines.h +45 -0
- data/include/prism/diagnostic.h +231 -0
- data/include/{yarp/enc/yp_encoding.h → prism/enc/pm_encoding.h} +40 -40
- data/include/prism/node.h +41 -0
- data/include/prism/pack.h +141 -0
- data/include/{yarp → prism}/parser.h +143 -142
- data/include/prism/regexp.h +19 -0
- data/include/prism/unescape.h +48 -0
- data/include/prism/util/pm_buffer.h +51 -0
- data/include/{yarp/util/yp_char.h → prism/util/pm_char.h} +20 -20
- data/include/{yarp/util/yp_constant_pool.h → prism/util/pm_constant_pool.h} +26 -22
- data/include/{yarp/util/yp_list.h → prism/util/pm_list.h} +21 -21
- data/include/prism/util/pm_memchr.h +14 -0
- data/include/{yarp/util/yp_newline_list.h → prism/util/pm_newline_list.h} +11 -11
- data/include/prism/util/pm_state_stack.h +24 -0
- data/include/{yarp/util/yp_string.h → prism/util/pm_string.h} +20 -20
- data/include/prism/util/pm_string_list.h +25 -0
- data/include/{yarp/util/yp_strpbrk.h → prism/util/pm_strpbrk.h} +7 -7
- data/include/prism/version.h +4 -0
- data/include/prism.h +82 -0
- data/lib/prism/compiler.rb +465 -0
- data/lib/prism/debug.rb +157 -0
- data/lib/{yarp/desugar_visitor.rb → prism/desugar_compiler.rb} +4 -2
- data/lib/prism/dispatcher.rb +2051 -0
- data/lib/prism/dsl.rb +750 -0
- data/lib/{yarp → prism}/ffi.rb +66 -67
- data/lib/{yarp → prism}/lex_compat.rb +40 -43
- data/lib/{yarp/mutation_visitor.rb → prism/mutation_compiler.rb} +3 -3
- data/lib/{yarp → prism}/node.rb +2012 -2593
- data/lib/prism/node_ext.rb +55 -0
- data/lib/prism/node_inspector.rb +68 -0
- data/lib/{yarp → prism}/pack.rb +1 -1
- data/lib/{yarp → prism}/parse_result/comments.rb +1 -1
- data/lib/{yarp → prism}/parse_result/newlines.rb +1 -1
- data/lib/prism/parse_result.rb +266 -0
- data/lib/{yarp → prism}/pattern.rb +14 -14
- data/lib/{yarp → prism}/ripper_compat.rb +5 -5
- data/lib/{yarp → prism}/serialize.rb +12 -7
- data/lib/prism/visitor.rb +470 -0
- data/lib/prism.rb +64 -0
- data/lib/yarp.rb +2 -614
- data/src/diagnostic.c +213 -208
- data/src/enc/pm_big5.c +52 -0
- data/src/enc/pm_euc_jp.c +58 -0
- data/src/enc/{yp_gbk.c → pm_gbk.c} +16 -16
- data/src/enc/pm_shift_jis.c +56 -0
- data/src/enc/{yp_tables.c → pm_tables.c} +69 -69
- data/src/enc/{yp_unicode.c → pm_unicode.c} +40 -40
- data/src/enc/pm_windows_31j.c +56 -0
- data/src/node.c +1293 -1233
- data/src/pack.c +247 -247
- data/src/prettyprint.c +1479 -1479
- data/src/{yarp.c → prism.c} +5205 -5083
- data/src/regexp.c +132 -132
- data/src/serialize.c +1121 -1121
- data/src/token_type.c +169 -167
- data/src/unescape.c +106 -87
- data/src/util/pm_buffer.c +103 -0
- data/src/util/{yp_char.c → pm_char.c} +72 -72
- data/src/util/{yp_constant_pool.c → pm_constant_pool.c} +85 -64
- data/src/util/{yp_list.c → pm_list.c} +10 -10
- data/src/util/{yp_memchr.c → pm_memchr.c} +6 -4
- data/src/util/{yp_newline_list.c → pm_newline_list.c} +21 -21
- data/src/util/{yp_state_stack.c → pm_state_stack.c} +4 -4
- data/src/util/{yp_string.c → pm_string.c} +38 -38
- data/src/util/pm_string_list.c +29 -0
- data/src/util/{yp_strncasecmp.c → pm_strncasecmp.c} +1 -1
- data/src/util/{yp_strpbrk.c → pm_strpbrk.c} +8 -8
- data/yarp.gemspec +68 -59
- metadata +70 -61
- data/ext/yarp/api_node.c +0 -4728
- data/ext/yarp/extension.h +0 -18
- data/include/yarp/ast.h +0 -1929
- data/include/yarp/defines.h +0 -45
- data/include/yarp/diagnostic.h +0 -226
- data/include/yarp/node.h +0 -42
- data/include/yarp/pack.h +0 -141
- data/include/yarp/regexp.h +0 -19
- data/include/yarp/unescape.h +0 -44
- data/include/yarp/util/yp_buffer.h +0 -51
- data/include/yarp/util/yp_memchr.h +0 -14
- data/include/yarp/util/yp_state_stack.h +0 -24
- data/include/yarp/util/yp_string_list.h +0 -25
- data/include/yarp/version.h +0 -4
- data/include/yarp.h +0 -82
- data/src/enc/yp_big5.c +0 -52
- data/src/enc/yp_euc_jp.c +0 -58
- data/src/enc/yp_shift_jis.c +0 -56
- data/src/enc/yp_windows_31j.c +0 -56
- data/src/util/yp_buffer.c +0 -101
- data/src/util/yp_string_list.c +0 -29
@@ -1,9 +1,9 @@
|
|
1
|
-
#include "
|
1
|
+
#include "prism/util/pm_newline_list.h"
|
2
2
|
|
3
3
|
// Initialize a new newline list with the given capacity. Returns true if the
|
4
4
|
// allocation of the offsets succeeds, otherwise returns false.
|
5
5
|
bool
|
6
|
-
|
6
|
+
pm_newline_list_init(pm_newline_list_t *list, const uint8_t *start, size_t capacity) {
|
7
7
|
list->offsets = (size_t *) calloc(capacity, sizeof(size_t));
|
8
8
|
if (list->offsets == NULL) return false;
|
9
9
|
|
@@ -23,7 +23,7 @@ yp_newline_list_init(yp_newline_list_t *list, const uint8_t *start, size_t capac
|
|
23
23
|
// Append a new offset to the newline list. Returns true if the reallocation of
|
24
24
|
// the offsets succeeds (if one was necessary), otherwise returns false.
|
25
25
|
bool
|
26
|
-
|
26
|
+
pm_newline_list_append(pm_newline_list_t *list, const uint8_t *cursor) {
|
27
27
|
if (list->size == list->capacity) {
|
28
28
|
size_t *original_offsets = list->offsets;
|
29
29
|
|
@@ -46,17 +46,17 @@ yp_newline_list_append(yp_newline_list_t *list, const uint8_t *cursor) {
|
|
46
46
|
|
47
47
|
// Conditionally append a new offset to the newline list, if the value passed in is a newline.
|
48
48
|
bool
|
49
|
-
|
49
|
+
pm_newline_list_check_append(pm_newline_list_t *list, const uint8_t *cursor) {
|
50
50
|
if (*cursor != '\n') {
|
51
51
|
return true;
|
52
52
|
}
|
53
|
-
return
|
53
|
+
return pm_newline_list_append(list, cursor);
|
54
54
|
}
|
55
55
|
|
56
56
|
// Returns the line and column of the given offset, assuming we don't have any
|
57
57
|
// information about the previous index that we found.
|
58
|
-
static
|
59
|
-
|
58
|
+
static pm_line_column_t
|
59
|
+
pm_newline_list_line_column_search(pm_newline_list_t *list, size_t offset) {
|
60
60
|
size_t left = 0;
|
61
61
|
size_t right = list->size - 1;
|
62
62
|
|
@@ -64,7 +64,7 @@ yp_newline_list_line_column_search(yp_newline_list_t *list, size_t offset) {
|
|
64
64
|
size_t mid = left + (right - left) / 2;
|
65
65
|
|
66
66
|
if (list->offsets[mid] == offset) {
|
67
|
-
return ((
|
67
|
+
return ((pm_line_column_t) { mid, 0 });
|
68
68
|
}
|
69
69
|
|
70
70
|
if (list->offsets[mid] < offset) {
|
@@ -74,13 +74,13 @@ yp_newline_list_line_column_search(yp_newline_list_t *list, size_t offset) {
|
|
74
74
|
}
|
75
75
|
}
|
76
76
|
|
77
|
-
return ((
|
77
|
+
return ((pm_line_column_t) { left - 1, offset - list->offsets[left - 1] });
|
78
78
|
}
|
79
79
|
|
80
80
|
// Returns the line and column of the given offset, assuming we know the last
|
81
81
|
// index that we found.
|
82
|
-
static
|
83
|
-
|
82
|
+
static pm_line_column_t
|
83
|
+
pm_newline_list_line_column_scan(pm_newline_list_t *list, size_t offset) {
|
84
84
|
if (offset > list->last_offset) {
|
85
85
|
size_t index = list->last_index;
|
86
86
|
while (index < list->size && list->offsets[index] < offset) {
|
@@ -88,10 +88,10 @@ yp_newline_list_line_column_scan(yp_newline_list_t *list, size_t offset) {
|
|
88
88
|
}
|
89
89
|
|
90
90
|
if (index == list->size) {
|
91
|
-
return ((
|
91
|
+
return ((pm_line_column_t) { index - 1, offset - list->offsets[index - 1] });
|
92
92
|
}
|
93
93
|
|
94
|
-
return ((
|
94
|
+
return ((pm_line_column_t) { index, 0 });
|
95
95
|
} else {
|
96
96
|
size_t index = list->last_index;
|
97
97
|
while (index > 0 && list->offsets[index] > offset) {
|
@@ -99,26 +99,26 @@ yp_newline_list_line_column_scan(yp_newline_list_t *list, size_t offset) {
|
|
99
99
|
}
|
100
100
|
|
101
101
|
if (index == 0) {
|
102
|
-
return ((
|
102
|
+
return ((pm_line_column_t) { 0, offset });
|
103
103
|
}
|
104
104
|
|
105
|
-
return ((
|
105
|
+
return ((pm_line_column_t) { index, offset - list->offsets[index - 1] });
|
106
106
|
}
|
107
107
|
}
|
108
108
|
|
109
109
|
// Returns the line and column of the given offset. If the offset is not in the
|
110
110
|
// list, the line and column of the closest offset less than the given offset
|
111
111
|
// are returned.
|
112
|
-
|
113
|
-
|
112
|
+
pm_line_column_t
|
113
|
+
pm_newline_list_line_column(pm_newline_list_t *list, const uint8_t *cursor) {
|
114
114
|
assert(cursor >= list->start);
|
115
115
|
size_t offset = (size_t) (cursor - list->start);
|
116
|
-
|
116
|
+
pm_line_column_t result;
|
117
117
|
|
118
118
|
if (list->last_offset == 0) {
|
119
|
-
result =
|
119
|
+
result = pm_newline_list_line_column_search(list, offset);
|
120
120
|
} else {
|
121
|
-
result =
|
121
|
+
result = pm_newline_list_line_column_scan(list, offset);
|
122
122
|
}
|
123
123
|
|
124
124
|
list->last_index = result.line;
|
@@ -129,6 +129,6 @@ yp_newline_list_line_column(yp_newline_list_t *list, const uint8_t *cursor) {
|
|
129
129
|
|
130
130
|
// Free the internal memory allocated for the newline list.
|
131
131
|
void
|
132
|
-
|
132
|
+
pm_newline_list_free(pm_newline_list_t *list) {
|
133
133
|
free(list->offsets);
|
134
134
|
}
|
@@ -1,19 +1,19 @@
|
|
1
|
-
#include "
|
1
|
+
#include "prism/util/pm_state_stack.h"
|
2
2
|
|
3
3
|
// Pushes a value onto the stack.
|
4
4
|
void
|
5
|
-
|
5
|
+
pm_state_stack_push(pm_state_stack_t *stack, bool value) {
|
6
6
|
*stack = (*stack << 1) | (value & 1);
|
7
7
|
}
|
8
8
|
|
9
9
|
// Pops a value off the stack.
|
10
10
|
void
|
11
|
-
|
11
|
+
pm_state_stack_pop(pm_state_stack_t *stack) {
|
12
12
|
*stack >>= 1;
|
13
13
|
}
|
14
14
|
|
15
15
|
// Returns the value at the top of the stack.
|
16
16
|
bool
|
17
|
-
|
17
|
+
pm_state_stack_p(pm_state_stack_t *stack) {
|
18
18
|
return *stack & 1;
|
19
19
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#include "
|
1
|
+
#include "prism/util/pm_string.h"
|
2
2
|
|
3
3
|
// The following headers are necessary to read files using demand paging.
|
4
4
|
#ifdef _WIN32
|
@@ -12,11 +12,11 @@
|
|
12
12
|
|
13
13
|
// Initialize a shared string that is based on initial input.
|
14
14
|
void
|
15
|
-
|
15
|
+
pm_string_shared_init(pm_string_t *string, const uint8_t *start, const uint8_t *end) {
|
16
16
|
assert(start <= end);
|
17
17
|
|
18
|
-
*string = (
|
19
|
-
.type =
|
18
|
+
*string = (pm_string_t) {
|
19
|
+
.type = PM_STRING_SHARED,
|
20
20
|
.source = start,
|
21
21
|
.length = (size_t) (end - start)
|
22
22
|
};
|
@@ -24,9 +24,9 @@ yp_string_shared_init(yp_string_t *string, const uint8_t *start, const uint8_t *
|
|
24
24
|
|
25
25
|
// Initialize an owned string that is responsible for freeing allocated memory.
|
26
26
|
void
|
27
|
-
|
28
|
-
*string = (
|
29
|
-
.type =
|
27
|
+
pm_string_owned_init(pm_string_t *string, uint8_t *source, size_t length) {
|
28
|
+
*string = (pm_string_t) {
|
29
|
+
.type = PM_STRING_OWNED,
|
30
30
|
.source = source,
|
31
31
|
.length = length
|
32
32
|
};
|
@@ -34,18 +34,18 @@ yp_string_owned_init(yp_string_t *string, uint8_t *source, size_t length) {
|
|
34
34
|
|
35
35
|
// Initialize a constant string that doesn't own its memory source.
|
36
36
|
void
|
37
|
-
|
38
|
-
*string = (
|
39
|
-
.type =
|
37
|
+
pm_string_constant_init(pm_string_t *string, const char *source, size_t length) {
|
38
|
+
*string = (pm_string_t) {
|
39
|
+
.type = PM_STRING_CONSTANT,
|
40
40
|
.source = (const uint8_t *) source,
|
41
41
|
.length = length
|
42
42
|
};
|
43
43
|
}
|
44
44
|
|
45
45
|
static void
|
46
|
-
|
47
|
-
*string = (
|
48
|
-
.type =
|
46
|
+
pm_string_mapped_init_internal(pm_string_t *string, uint8_t *source, size_t length) {
|
47
|
+
*string = (pm_string_t) {
|
48
|
+
.type = PM_STRING_MAPPED,
|
49
49
|
.source = source,
|
50
50
|
.length = length
|
51
51
|
};
|
@@ -53,9 +53,9 @@ yp_string_mapped_init_internal(yp_string_t *string, uint8_t *source, size_t leng
|
|
53
53
|
|
54
54
|
// Returns the memory size associated with the string.
|
55
55
|
size_t
|
56
|
-
|
57
|
-
size_t size = sizeof(
|
58
|
-
if (string->type ==
|
56
|
+
pm_string_memsize(const pm_string_t *string) {
|
57
|
+
size_t size = sizeof(pm_string_t);
|
58
|
+
if (string->type == PM_STRING_OWNED) {
|
59
59
|
size += string->length;
|
60
60
|
}
|
61
61
|
return size;
|
@@ -64,39 +64,39 @@ yp_string_memsize(const yp_string_t *string) {
|
|
64
64
|
// Ensure the string is owned. If it is not, then reinitialize it as owned and
|
65
65
|
// copy over the previous source.
|
66
66
|
void
|
67
|
-
|
68
|
-
if (string->type ==
|
67
|
+
pm_string_ensure_owned(pm_string_t *string) {
|
68
|
+
if (string->type == PM_STRING_OWNED) return;
|
69
69
|
|
70
|
-
size_t length =
|
71
|
-
const uint8_t *source =
|
70
|
+
size_t length = pm_string_length(string);
|
71
|
+
const uint8_t *source = pm_string_source(string);
|
72
72
|
|
73
73
|
uint8_t *memory = malloc(length);
|
74
74
|
if (!memory) return;
|
75
75
|
|
76
|
-
|
76
|
+
pm_string_owned_init(string, memory, length);
|
77
77
|
memcpy((void *) string->source, source, length);
|
78
78
|
}
|
79
79
|
|
80
80
|
// Returns the length associated with the string.
|
81
|
-
|
82
|
-
|
81
|
+
PRISM_EXPORTED_FUNCTION size_t
|
82
|
+
pm_string_length(const pm_string_t *string) {
|
83
83
|
return string->length;
|
84
84
|
}
|
85
85
|
|
86
86
|
// Returns the start pointer associated with the string.
|
87
|
-
|
88
|
-
|
87
|
+
PRISM_EXPORTED_FUNCTION const uint8_t *
|
88
|
+
pm_string_source(const pm_string_t *string) {
|
89
89
|
return string->source;
|
90
90
|
}
|
91
91
|
|
92
92
|
// Free the associated memory of the given string.
|
93
|
-
|
94
|
-
|
93
|
+
PRISM_EXPORTED_FUNCTION void
|
94
|
+
pm_string_free(pm_string_t *string) {
|
95
95
|
void *memory = (void *) string->source;
|
96
96
|
|
97
|
-
if (string->type ==
|
97
|
+
if (string->type == PM_STRING_OWNED) {
|
98
98
|
free(memory);
|
99
|
-
} else if (string->type ==
|
99
|
+
} else if (string->type == PM_STRING_MAPPED && string->length) {
|
100
100
|
#if defined(_WIN32)
|
101
101
|
UnmapViewOfFile(memory);
|
102
102
|
#else
|
@@ -106,7 +106,7 @@ yp_string_free(yp_string_t *string) {
|
|
106
106
|
}
|
107
107
|
|
108
108
|
bool
|
109
|
-
|
109
|
+
pm_string_mapped_init(pm_string_t *string, const char *filepath) {
|
110
110
|
#ifdef _WIN32
|
111
111
|
// Open the file for reading.
|
112
112
|
HANDLE file = CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
@@ -129,7 +129,7 @@ yp_string_mapped_init(yp_string_t *string, const char *filepath) {
|
|
129
129
|
if (file_size == 0) {
|
130
130
|
CloseHandle(file);
|
131
131
|
uint8_t empty[] = "";
|
132
|
-
|
132
|
+
pm_string_mapped_init_internal(string, empty, 0);
|
133
133
|
return true;
|
134
134
|
}
|
135
135
|
|
@@ -151,7 +151,7 @@ yp_string_mapped_init(yp_string_t *string, const char *filepath) {
|
|
151
151
|
return false;
|
152
152
|
}
|
153
153
|
|
154
|
-
|
154
|
+
pm_string_mapped_init_internal(string, source, (size_t) file_size);
|
155
155
|
return true;
|
156
156
|
#else
|
157
157
|
// Open the file for reading
|
@@ -176,7 +176,7 @@ yp_string_mapped_init(yp_string_t *string, const char *filepath) {
|
|
176
176
|
if (size == 0) {
|
177
177
|
close(fd);
|
178
178
|
uint8_t empty[] = "";
|
179
|
-
|
179
|
+
pm_string_mapped_init_internal(string, empty, 0);
|
180
180
|
return true;
|
181
181
|
}
|
182
182
|
|
@@ -187,14 +187,14 @@ yp_string_mapped_init(yp_string_t *string, const char *filepath) {
|
|
187
187
|
}
|
188
188
|
|
189
189
|
close(fd);
|
190
|
-
|
190
|
+
pm_string_mapped_init_internal(string, source, size);
|
191
191
|
return true;
|
192
192
|
#endif
|
193
193
|
}
|
194
194
|
|
195
|
-
// Returns the size of the
|
195
|
+
// Returns the size of the pm_string_t struct. This is necessary to allocate the
|
196
196
|
// correct amount of memory in the FFI backend.
|
197
|
-
|
198
|
-
|
199
|
-
return sizeof(
|
197
|
+
PRISM_EXPORTED_FUNCTION size_t
|
198
|
+
pm_string_sizeof(void) {
|
199
|
+
return sizeof(pm_string_t);
|
200
200
|
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#include "prism/util/pm_string_list.h"
|
2
|
+
|
3
|
+
// Initialize a pm_string_list_t with its default values.
|
4
|
+
void
|
5
|
+
pm_string_list_init(pm_string_list_t *string_list) {
|
6
|
+
string_list->strings = (pm_string_t *) malloc(sizeof(pm_string_t));
|
7
|
+
string_list->length = 0;
|
8
|
+
string_list->capacity = 1;
|
9
|
+
}
|
10
|
+
|
11
|
+
// Append a pm_string_t to the given string list.
|
12
|
+
void
|
13
|
+
pm_string_list_append(pm_string_list_t *string_list, pm_string_t *string) {
|
14
|
+
if (string_list->length + 1 > string_list->capacity) {
|
15
|
+
pm_string_t *original_string = string_list->strings;
|
16
|
+
string_list->capacity *= 2;
|
17
|
+
string_list->strings = (pm_string_t *) malloc(string_list->capacity * sizeof(pm_string_t));
|
18
|
+
memcpy(string_list->strings, original_string, (string_list->length) * sizeof(pm_string_t));
|
19
|
+
free(original_string);
|
20
|
+
}
|
21
|
+
|
22
|
+
string_list->strings[string_list->length++] = *string;
|
23
|
+
}
|
24
|
+
|
25
|
+
// Free the memory associated with the string list.
|
26
|
+
void
|
27
|
+
pm_string_list_free(pm_string_list_t *string_list) {
|
28
|
+
free(string_list->strings);
|
29
|
+
}
|
@@ -1,8 +1,8 @@
|
|
1
|
-
#include "
|
1
|
+
#include "prism/util/pm_strpbrk.h"
|
2
2
|
|
3
3
|
// This is the slow path that does care about the encoding.
|
4
4
|
static inline const uint8_t *
|
5
|
-
|
5
|
+
pm_strpbrk_multi_byte(pm_parser_t *parser, const uint8_t *source, const uint8_t *charset, size_t maximum) {
|
6
6
|
size_t index = 0;
|
7
7
|
|
8
8
|
while (index < maximum) {
|
@@ -23,7 +23,7 @@ yp_strpbrk_multi_byte(yp_parser_t *parser, const uint8_t *source, const uint8_t
|
|
23
23
|
|
24
24
|
// This is the fast path that does not care about the encoding.
|
25
25
|
static inline const uint8_t *
|
26
|
-
|
26
|
+
pm_strpbrk_single_byte(const uint8_t *source, const uint8_t *charset, size_t maximum) {
|
27
27
|
size_t index = 0;
|
28
28
|
|
29
29
|
while (index < maximum) {
|
@@ -39,9 +39,9 @@ yp_strpbrk_single_byte(const uint8_t *source, const uint8_t *charset, size_t max
|
|
39
39
|
|
40
40
|
// Here we have rolled our own version of strpbrk. The standard library strpbrk
|
41
41
|
// has undefined behavior when the source string is not null-terminated. We want
|
42
|
-
// to support strings that are not null-terminated because
|
42
|
+
// to support strings that are not null-terminated because pm_parse does not
|
43
43
|
// have the contract that the string is null-terminated. (This is desirable
|
44
|
-
// because it means the extension can call
|
44
|
+
// because it means the extension can call pm_parse with the result of a call to
|
45
45
|
// mmap).
|
46
46
|
//
|
47
47
|
// The standard library strpbrk also does not support passing a maximum length
|
@@ -55,12 +55,12 @@ yp_strpbrk_single_byte(const uint8_t *source, const uint8_t *charset, size_t max
|
|
55
55
|
// Shift-JIS, the backslash character can be a trailing byte. In that case we
|
56
56
|
// need to take a slower path and iterate one multi-byte character at a time.
|
57
57
|
const uint8_t *
|
58
|
-
|
58
|
+
pm_strpbrk(pm_parser_t *parser, const uint8_t *source, const uint8_t *charset, ptrdiff_t length) {
|
59
59
|
if (length <= 0) {
|
60
60
|
return NULL;
|
61
61
|
} else if (parser->encoding_changed && parser->encoding.multibyte) {
|
62
|
-
return
|
62
|
+
return pm_strpbrk_multi_byte(parser, source, charset, (size_t) length);
|
63
63
|
} else {
|
64
|
-
return
|
64
|
+
return pm_strpbrk_single_byte(source, charset, (size_t) length);
|
65
65
|
}
|
66
66
|
}
|
data/yarp.gemspec
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "yarp"
|
5
|
-
spec.version = "0.
|
5
|
+
spec.version = "0.13.0"
|
6
6
|
spec.authors = ["Shopify"]
|
7
7
|
spec.email = ["ruby@shopify.com"]
|
8
8
|
|
9
|
-
spec.summary = "
|
10
|
-
spec.homepage = "https://github.com/ruby/
|
9
|
+
spec.summary = "Prism Ruby parser"
|
10
|
+
spec.homepage = "https://github.com/ruby/prism"
|
11
11
|
spec.license = "MIT"
|
12
12
|
|
13
13
|
spec.required_ruby_version = ">= 3.0.0"
|
@@ -33,51 +33,60 @@ Gem::Specification.new do |spec|
|
|
33
33
|
"docs/ruby_api.md",
|
34
34
|
"docs/serialization.md",
|
35
35
|
"docs/testing.md",
|
36
|
-
"ext/
|
37
|
-
"ext/
|
38
|
-
"ext/
|
39
|
-
"ext/
|
40
|
-
"include/
|
41
|
-
"include/
|
42
|
-
"include/
|
43
|
-
"include/
|
44
|
-
"include/
|
45
|
-
"include/
|
46
|
-
"include/
|
47
|
-
"include/
|
48
|
-
"include/
|
49
|
-
"include/
|
50
|
-
"include/
|
51
|
-
"include/
|
52
|
-
"include/
|
53
|
-
"include/
|
54
|
-
"include/
|
55
|
-
"include/
|
56
|
-
"include/
|
57
|
-
"include/
|
58
|
-
"include/
|
59
|
-
"include/
|
60
|
-
"include/
|
36
|
+
"ext/prism/api_node.c",
|
37
|
+
"ext/prism/api_pack.c",
|
38
|
+
"ext/prism/extension.c",
|
39
|
+
"ext/prism/extension.h",
|
40
|
+
"include/prism.h",
|
41
|
+
"include/prism/ast.h",
|
42
|
+
"include/prism/defines.h",
|
43
|
+
"include/prism/diagnostic.h",
|
44
|
+
"include/prism/enc/pm_encoding.h",
|
45
|
+
"include/prism/node.h",
|
46
|
+
"include/prism/pack.h",
|
47
|
+
"include/prism/parser.h",
|
48
|
+
"include/prism/regexp.h",
|
49
|
+
"include/prism/unescape.h",
|
50
|
+
"include/prism/util/pm_buffer.h",
|
51
|
+
"include/prism/util/pm_char.h",
|
52
|
+
"include/prism/util/pm_constant_pool.h",
|
53
|
+
"include/prism/util/pm_list.h",
|
54
|
+
"include/prism/util/pm_memchr.h",
|
55
|
+
"include/prism/util/pm_newline_list.h",
|
56
|
+
"include/prism/util/pm_state_stack.h",
|
57
|
+
"include/prism/util/pm_string.h",
|
58
|
+
"include/prism/util/pm_string_list.h",
|
59
|
+
"include/prism/util/pm_strpbrk.h",
|
60
|
+
"include/prism/version.h",
|
61
61
|
"lib/yarp.rb",
|
62
|
-
"lib/
|
63
|
-
"lib/
|
64
|
-
"lib/
|
65
|
-
"lib/
|
66
|
-
"lib/
|
67
|
-
"lib/
|
68
|
-
"lib/
|
69
|
-
"lib/
|
70
|
-
"lib/
|
71
|
-
"lib/
|
72
|
-
"lib/
|
62
|
+
"lib/prism.rb",
|
63
|
+
"lib/prism/compiler.rb",
|
64
|
+
"lib/prism/debug.rb",
|
65
|
+
"lib/prism/desugar_compiler.rb",
|
66
|
+
"lib/prism/dispatcher.rb",
|
67
|
+
"lib/prism/dsl.rb",
|
68
|
+
"lib/prism/ffi.rb",
|
69
|
+
"lib/prism/lex_compat.rb",
|
70
|
+
"lib/prism/mutation_compiler.rb",
|
71
|
+
"lib/prism/node.rb",
|
72
|
+
"lib/prism/node_ext.rb",
|
73
|
+
"lib/prism/node_inspector.rb",
|
74
|
+
"lib/prism/pack.rb",
|
75
|
+
"lib/prism/parse_result.rb",
|
76
|
+
"lib/prism/pattern.rb",
|
77
|
+
"lib/prism/ripper_compat.rb",
|
78
|
+
"lib/prism/serialize.rb",
|
79
|
+
"lib/prism/parse_result/comments.rb",
|
80
|
+
"lib/prism/parse_result/newlines.rb",
|
81
|
+
"lib/prism/visitor.rb",
|
73
82
|
"src/diagnostic.c",
|
74
|
-
"src/enc/
|
75
|
-
"src/enc/
|
76
|
-
"src/enc/
|
77
|
-
"src/enc/
|
78
|
-
"src/enc/
|
79
|
-
"src/enc/
|
80
|
-
"src/enc/
|
83
|
+
"src/enc/pm_big5.c",
|
84
|
+
"src/enc/pm_euc_jp.c",
|
85
|
+
"src/enc/pm_gbk.c",
|
86
|
+
"src/enc/pm_shift_jis.c",
|
87
|
+
"src/enc/pm_tables.c",
|
88
|
+
"src/enc/pm_unicode.c",
|
89
|
+
"src/enc/pm_windows_31j.c",
|
81
90
|
"src/node.c",
|
82
91
|
"src/pack.c",
|
83
92
|
"src/prettyprint.c",
|
@@ -85,21 +94,21 @@ Gem::Specification.new do |spec|
|
|
85
94
|
"src/serialize.c",
|
86
95
|
"src/token_type.c",
|
87
96
|
"src/unescape.c",
|
88
|
-
"src/util/
|
89
|
-
"src/util/
|
90
|
-
"src/util/
|
91
|
-
"src/util/
|
92
|
-
"src/util/
|
93
|
-
"src/util/
|
94
|
-
"src/util/
|
95
|
-
"src/util/
|
96
|
-
"src/util/
|
97
|
-
"src/util/
|
98
|
-
"src/util/
|
99
|
-
"src/
|
97
|
+
"src/util/pm_buffer.c",
|
98
|
+
"src/util/pm_char.c",
|
99
|
+
"src/util/pm_constant_pool.c",
|
100
|
+
"src/util/pm_list.c",
|
101
|
+
"src/util/pm_memchr.c",
|
102
|
+
"src/util/pm_newline_list.c",
|
103
|
+
"src/util/pm_state_stack.c",
|
104
|
+
"src/util/pm_string.c",
|
105
|
+
"src/util/pm_string_list.c",
|
106
|
+
"src/util/pm_strncasecmp.c",
|
107
|
+
"src/util/pm_strpbrk.c",
|
108
|
+
"src/prism.c",
|
100
109
|
"yarp.gemspec",
|
101
110
|
]
|
102
111
|
|
103
|
-
spec.extensions = ["ext/
|
112
|
+
spec.extensions = ["ext/prism/extconf.rb"]
|
104
113
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
105
114
|
end
|