kanayago 0.6.0 → 0.7.0
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/.rubocop.yml +1 -1
- data/.rubocop_todo.yml +22 -11
- data/CHANGELOG.md +32 -0
- data/README.md +44 -25
- data/Rakefile +97 -2
- data/ext/kanayago/kanayago.c +630 -1
- data/lib/kanayago/version.rb +1 -1
- data/patch/3.4.0/copy_target.rb +78 -0
- data/patch/3.4.0/kanayago.patch +210 -0
- data/patch/3.4.1/copy_target.rb +78 -0
- data/patch/3.4.1/kanayago.patch +210 -0
- data/patch/3.4.2/copy_target.rb +78 -0
- data/patch/3.4.2/kanayago.patch +210 -0
- data/patch/3.4.3/copy_target.rb +78 -0
- data/patch/3.4.3/kanayago.patch +210 -0
- data/patch/3.4.4/copy_target.rb +78 -0
- data/patch/3.4.4/kanayago.patch +210 -0
- data/patch/3.4.5/copy_target.rb +78 -0
- data/patch/3.4.5/kanayago.patch +210 -0
- data/patch/3.4.6/copy_target.rb +78 -0
- data/patch/3.4.6/kanayago.patch +210 -0
- data/patch/3.4.7/copy_target.rb +78 -0
- data/patch/3.4.7/kanayago.patch +210 -0
- data/patch/3.4.8/copy_target.rb +78 -0
- data/patch/3.4.8/kanayago.patch +210 -0
- data/patch/4.0.0/copy_target.rb +85 -0
- data/patch/4.0.0/kanayago.patch +282 -0
- data/patch/4.0.0/macos.patch +46 -0
- data/patch/head/kanayago.patch +1 -1
- data/patch/head/macos.patch +65 -0
- data/patch/head/macos.patch.rej +49 -0
- data/script/setup_parser.rb +40 -3
- metadata +25 -2
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
diff -ruN a/ext/kanayago/internal/ruby_parser.h b/ext/kanayago/internal/ruby_parser.h
|
|
2
|
+
--- a/ext/kanayago/internal/ruby_parser.h 2025-12-17 19:50:40.592959132 +0900
|
|
3
|
+
+++ b/ext/kanayago/internal/ruby_parser.h 2025-12-17 19:50:40.592959132 +0900
|
|
4
|
+
@@ -10,11 +10,35 @@
|
|
5
|
+
#include "rubyparser.h"
|
|
6
|
+
#include "vm.h"
|
|
7
|
+
|
|
8
|
+
-struct lex_pointer_string {
|
|
9
|
+
+ struct lex_pointer_string {
|
|
10
|
+
VALUE str;
|
|
11
|
+
long ptr;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
+
|
|
15
|
+
+// Add Ruby's Parser struct and enum for Kanayago
|
|
16
|
+
+enum lex_type {
|
|
17
|
+
+ lex_type_str,
|
|
18
|
+
+ lex_type_io,
|
|
19
|
+
+ lex_type_array,
|
|
20
|
+
+ lex_type_generic,
|
|
21
|
+
+};
|
|
22
|
+
+
|
|
23
|
+
+struct ruby_parser {
|
|
24
|
+
+ rb_parser_t *parser_params;
|
|
25
|
+
+ enum lex_type type;
|
|
26
|
+
+ union {
|
|
27
|
+
+ struct lex_pointer_string lex_str;
|
|
28
|
+
+ struct {
|
|
29
|
+
+ VALUE file;
|
|
30
|
+
+ } lex_io;
|
|
31
|
+
+ struct {
|
|
32
|
+
+ VALUE ary;
|
|
33
|
+
+ } lex_array;
|
|
34
|
+
+ } data;
|
|
35
|
+
+};
|
|
36
|
+
+// End for Kanayago
|
|
37
|
+
+
|
|
38
|
+
RUBY_SYMBOL_EXPORT_BEGIN
|
|
39
|
+
#ifdef UNIVERSAL_PARSER
|
|
40
|
+
const rb_parser_config_t *rb_ruby_parser_config(void);
|
|
41
|
+
diff -ruN a/ext/kanayago/parse.c b/ext/kanayago/parse.c
|
|
42
|
+
--- a/ext/kanayago/parse.c 2025-12-17 19:50:40.592959132 +0900
|
|
43
|
+
+++ b/ext/kanayago/parse.c 2025-12-17 19:50:40.592959132 +0900
|
|
44
|
+
@@ -26941,6 +26941,16 @@
|
|
45
|
+
return p->value;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
+#else /* !RIPPER */
|
|
49
|
+
+
|
|
50
|
+
+// Accessor function for error_buffer (for Kanayago)
|
|
51
|
+
+VALUE
|
|
52
|
+
+rb_ruby_parser_error_buffer_get(rb_parser_t *p)
|
|
53
|
+
+{
|
|
54
|
+
+ return p->error_buffer;
|
|
55
|
+
+}
|
|
56
|
+
+
|
|
57
|
+
+
|
|
58
|
+
#endif /* RIPPER */
|
|
59
|
+
/*
|
|
60
|
+
* Local variables:
|
|
61
|
+
diff -ruN a/ext/kanayago/ruby_parser.c b/ext/kanayago/ruby_parser.c
|
|
62
|
+
--- a/ext/kanayago/ruby_parser.c 2025-12-17 19:50:40.592959132 +0900
|
|
63
|
+
+++ b/ext/kanayago/ruby_parser.c 2025-12-17 19:50:40.592959132 +0900
|
|
64
|
+
@@ -326,6 +326,51 @@
|
|
65
|
+
|
|
66
|
+
extern VALUE rb_eArgError;
|
|
67
|
+
|
|
68
|
+
+// Add for Kanayago - wrapper functions to avoid unexported symbols
|
|
69
|
+
+static void *
|
|
70
|
+
+xmalloc_mul_add(size_t x, size_t y, size_t z)
|
|
71
|
+
+{
|
|
72
|
+
+ size_t size;
|
|
73
|
+
+ if (y != 0 && x > (SIZE_MAX - z) / y) {
|
|
74
|
+
+ rb_raise(rb_eArgError, "allocation size overflow");
|
|
75
|
+
+ }
|
|
76
|
+
+ size = x * y + z;
|
|
77
|
+
+ return ruby_xmalloc(size);
|
|
78
|
+
+}
|
|
79
|
+
+
|
|
80
|
+
+static VALUE
|
|
81
|
+
+suppress_tracing(VALUE (*func)(VALUE), VALUE arg)
|
|
82
|
+
+{
|
|
83
|
+
+ return func(arg);
|
|
84
|
+
+}
|
|
85
|
+
+
|
|
86
|
+
+static ID
|
|
87
|
+
+make_temporary_id(size_t n)
|
|
88
|
+
+{
|
|
89
|
+
+ char buf[64];
|
|
90
|
+
+ snprintf(buf, sizeof(buf), "@kanayago_tmp_%zu", n);
|
|
91
|
+
+ return rb_intern(buf);
|
|
92
|
+
+}
|
|
93
|
+
+
|
|
94
|
+
+static int
|
|
95
|
+
+stderr_tty_p(void)
|
|
96
|
+
+{
|
|
97
|
+
+ return isatty(fileno(stderr));
|
|
98
|
+
+}
|
|
99
|
+
+
|
|
100
|
+
+static VALUE
|
|
101
|
+
+reg_compile(VALUE str, int options, const char *sourcefile, int sourceline)
|
|
102
|
+
+{
|
|
103
|
+
+ return rb_reg_new_str(str, options);
|
|
104
|
+
+}
|
|
105
|
+
+
|
|
106
|
+
+static VALUE
|
|
107
|
+
+reg_check_preprocess(VALUE val)
|
|
108
|
+
+{
|
|
109
|
+
+ return Qnil;
|
|
110
|
+
+}
|
|
111
|
+
+// End of Add for Kanayago
|
|
112
|
+
+
|
|
113
|
+
static const rb_parser_config_t rb_global_parser_config = {
|
|
114
|
+
.malloc = ruby_xmalloc,
|
|
115
|
+
.calloc = ruby_xcalloc,
|
|
116
|
+
@@ -337,9 +382,9 @@
|
|
117
|
+
.zalloc = zalloc,
|
|
118
|
+
.rb_memmove = memmove2,
|
|
119
|
+
.nonempty_memcpy = nonempty_memcpy,
|
|
120
|
+
- .xmalloc_mul_add = rb_xmalloc_mul_add,
|
|
121
|
+
+ .xmalloc_mul_add = xmalloc_mul_add,
|
|
122
|
+
|
|
123
|
+
- .compile_callback = rb_suppress_tracing,
|
|
124
|
+
+ .compile_callback = suppress_tracing,
|
|
125
|
+
.reg_named_capture_assign = reg_named_capture_assign,
|
|
126
|
+
|
|
127
|
+
.attr_get = rb_attr_get,
|
|
128
|
+
@@ -348,7 +393,7 @@
|
|
129
|
+
.ary_new_from_args = rb_ary_new_from_args,
|
|
130
|
+
.ary_unshift = rb_ary_unshift,
|
|
131
|
+
|
|
132
|
+
- .make_temporary_id = rb_make_temporary_id,
|
|
133
|
+
+ .make_temporary_id = make_temporary_id,
|
|
134
|
+
.is_local_id = is_local_id2,
|
|
135
|
+
.is_attrset_id = is_attrset_id2,
|
|
136
|
+
.is_global_name_punct = is_global_name_punct,
|
|
137
|
+
@@ -380,7 +425,7 @@
|
|
138
|
+
|
|
139
|
+
.int2num = rb_int2num_inline,
|
|
140
|
+
|
|
141
|
+
- .stderr_tty_p = rb_stderr_tty_p,
|
|
142
|
+
+ .stderr_tty_p = stderr_tty_p,
|
|
143
|
+
.write_error_str = rb_write_error_str,
|
|
144
|
+
.io_write = rb_io_write,
|
|
145
|
+
.io_flush = rb_io_flush,
|
|
146
|
+
@@ -430,8 +475,8 @@
|
|
147
|
+
.gc_guard = gc_guard,
|
|
148
|
+
.gc_mark = rb_gc_mark,
|
|
149
|
+
|
|
150
|
+
- .reg_compile = rb_reg_compile,
|
|
151
|
+
- .reg_check_preprocess = rb_reg_check_preprocess,
|
|
152
|
+
+ .reg_compile = reg_compile,
|
|
153
|
+
+ .reg_check_preprocess = reg_check_preprocess,
|
|
154
|
+
.memcicmp = rb_memcicmp,
|
|
155
|
+
|
|
156
|
+
.compile_warn = rb_compile_warn,
|
|
157
|
+
@@ -461,26 +506,6 @@
|
|
158
|
+
};
|
|
159
|
+
#endif
|
|
160
|
+
|
|
161
|
+
-enum lex_type {
|
|
162
|
+
- lex_type_str,
|
|
163
|
+
- lex_type_io,
|
|
164
|
+
- lex_type_array,
|
|
165
|
+
- lex_type_generic,
|
|
166
|
+
-};
|
|
167
|
+
-
|
|
168
|
+
-struct ruby_parser {
|
|
169
|
+
- rb_parser_t *parser_params;
|
|
170
|
+
- enum lex_type type;
|
|
171
|
+
- union {
|
|
172
|
+
- struct lex_pointer_string lex_str;
|
|
173
|
+
- struct {
|
|
174
|
+
- VALUE file;
|
|
175
|
+
- } lex_io;
|
|
176
|
+
- struct {
|
|
177
|
+
- VALUE ary;
|
|
178
|
+
- } lex_array;
|
|
179
|
+
- } data;
|
|
180
|
+
-};
|
|
181
|
+
|
|
182
|
+
static void
|
|
183
|
+
parser_mark(void *ptr)
|
|
184
|
+
@@ -519,7 +544,7 @@
|
|
185
|
+
return rb_ruby_parser_memsize(parser->parser_params);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
-static const rb_data_type_t ruby_parser_data_type = {
|
|
189
|
+
+const rb_data_type_t ruby_parser_data_type = {
|
|
190
|
+
"parser",
|
|
191
|
+
{
|
|
192
|
+
parser_mark,
|
|
193
|
+
@@ -891,7 +916,7 @@
|
|
194
|
+
VALUE
|
|
195
|
+
rb_str_new_parser_string(rb_parser_string_t *str)
|
|
196
|
+
{
|
|
197
|
+
- VALUE string = rb_enc_literal_str(str->ptr, str->len, str->enc);
|
|
198
|
+
+ VALUE string = rb_enc_str_new(str->ptr, str->len, str->enc);
|
|
199
|
+
rb_enc_str_coderange(string);
|
|
200
|
+
return string;
|
|
201
|
+
}
|
|
202
|
+
@@ -1073,7 +1098,7 @@
|
|
203
|
+
rb_parser_string_t *string = node_reg->string;
|
|
204
|
+
VALUE str = rb_enc_str_new(string->ptr, string->len, string->enc);
|
|
205
|
+
|
|
206
|
+
- return rb_reg_compile(str, node_reg->options, NULL, 0);
|
|
207
|
+
+ return rb_reg_new_str(str, node_reg->options);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
VALUE
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RUBY_PARSER_COPY_TARGETS = %w[
|
|
4
|
+
ccan/check_type/check_type.h
|
|
5
|
+
ccan/container_of/container_of.h
|
|
6
|
+
ccan/list/list.h
|
|
7
|
+
ccan/str/str.h
|
|
8
|
+
constant.h
|
|
9
|
+
id.h
|
|
10
|
+
id_table.h
|
|
11
|
+
include/ruby/st.h
|
|
12
|
+
internal/array.h
|
|
13
|
+
internal/basic_operators.h
|
|
14
|
+
internal/bignum.h
|
|
15
|
+
internal/bits.h
|
|
16
|
+
internal/box.h
|
|
17
|
+
internal/compile.h
|
|
18
|
+
internal/compilers.h
|
|
19
|
+
internal/complex.h
|
|
20
|
+
internal/encoding.h
|
|
21
|
+
internal/error.h
|
|
22
|
+
internal/fixnum.h
|
|
23
|
+
internal/gc.h
|
|
24
|
+
internal/hash.h
|
|
25
|
+
internal/imemo.h
|
|
26
|
+
internal/io.h
|
|
27
|
+
internal/namespace.h
|
|
28
|
+
internal/numeric.h
|
|
29
|
+
internal/parse.h
|
|
30
|
+
internal/rational.h
|
|
31
|
+
internal/re.h
|
|
32
|
+
internal/ruby_parser.h
|
|
33
|
+
internal/sanitizers.h
|
|
34
|
+
internal/serial.h
|
|
35
|
+
internal/set_table.h
|
|
36
|
+
internal/static_assert.h
|
|
37
|
+
internal/string.h
|
|
38
|
+
internal/symbol.h
|
|
39
|
+
internal/thread.h
|
|
40
|
+
internal/variable.h
|
|
41
|
+
internal/warnings.h
|
|
42
|
+
internal/vm.h
|
|
43
|
+
internal.h
|
|
44
|
+
lex.c
|
|
45
|
+
method.h
|
|
46
|
+
node.c
|
|
47
|
+
node.h
|
|
48
|
+
node_name.inc
|
|
49
|
+
parse.c
|
|
50
|
+
parse.h
|
|
51
|
+
parser_bits.h
|
|
52
|
+
parser_node.h
|
|
53
|
+
parser_st.c
|
|
54
|
+
parser_st.h
|
|
55
|
+
parser_value.h
|
|
56
|
+
ruby_assert.h
|
|
57
|
+
ruby_atomic.h
|
|
58
|
+
ruby_parser.c
|
|
59
|
+
rubyparser.h
|
|
60
|
+
shape.h
|
|
61
|
+
st.c
|
|
62
|
+
symbol.h
|
|
63
|
+
thread_pthread.h
|
|
64
|
+
universal_parser.c
|
|
65
|
+
vm_core.h
|
|
66
|
+
vm_opts.h
|
|
67
|
+
].freeze
|
|
68
|
+
|
|
69
|
+
MAKE_DIRECTORIES = [
|
|
70
|
+
'ccan',
|
|
71
|
+
'ccan/check_type',
|
|
72
|
+
'ccan/container',
|
|
73
|
+
'ccan/container_of',
|
|
74
|
+
'ccan/list',
|
|
75
|
+
'ccan/str',
|
|
76
|
+
'internal',
|
|
77
|
+
'include',
|
|
78
|
+
'include/ruby'
|
|
79
|
+
].freeze
|
|
80
|
+
|
|
81
|
+
DELETE_DIRECTORIES = %w[
|
|
82
|
+
ccan
|
|
83
|
+
internal
|
|
84
|
+
include
|
|
85
|
+
].freeze
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
diff --git a/ext/kanayago/internal/ruby_parser.h b/ext/kanayago/internal/ruby_parser.h
|
|
2
|
+
index 8e306d1..d420a02 100644
|
|
3
|
+
--- a/ext/kanayago/internal/ruby_parser.h
|
|
4
|
+
+++ b/ext/kanayago/internal/ruby_parser.h
|
|
5
|
+
@@ -15,6 +15,29 @@ struct lex_pointer_string {
|
|
6
|
+
long ptr;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
+// Add Ruby's Parser struct and enum for Kanayago
|
|
10
|
+
+enum lex_type {
|
|
11
|
+
+ lex_type_str,
|
|
12
|
+
+ lex_type_io,
|
|
13
|
+
+ lex_type_array,
|
|
14
|
+
+ lex_type_generic,
|
|
15
|
+
+};
|
|
16
|
+
+
|
|
17
|
+
+struct ruby_parser {
|
|
18
|
+
+ rb_parser_t *parser_params;
|
|
19
|
+
+ enum lex_type type;
|
|
20
|
+
+ union {
|
|
21
|
+
+ struct lex_pointer_string lex_str;
|
|
22
|
+
+ struct {
|
|
23
|
+
+ VALUE file;
|
|
24
|
+
+ } lex_io;
|
|
25
|
+
+ struct {
|
|
26
|
+
+ VALUE ary;
|
|
27
|
+
+ } lex_array;
|
|
28
|
+
+ } data;
|
|
29
|
+
+};
|
|
30
|
+
+// End for Kanayago
|
|
31
|
+
+
|
|
32
|
+
RUBY_SYMBOL_EXPORT_BEGIN
|
|
33
|
+
#ifdef UNIVERSAL_PARSER
|
|
34
|
+
const rb_parser_config_t *rb_ruby_parser_config(void);
|
|
35
|
+
diff --git a/ext/kanayago/ruby_parser.c b/ext/kanayago/ruby_parser.c
|
|
36
|
+
index 267f619..841db65 100644
|
|
37
|
+
--- a/ext/kanayago/ruby_parser.c
|
|
38
|
+
+++ b/ext/kanayago/ruby_parser.c
|
|
39
|
+
@@ -34,6 +34,100 @@
|
|
40
|
+
|
|
41
|
+
#define parser_encoding const void
|
|
42
|
+
|
|
43
|
+
+/*
|
|
44
|
+
+ * The following functions are ported from Ruby's error.c for Kanayago:
|
|
45
|
+
+ * - err_vcatf
|
|
46
|
+
+ * - syntax_error_with_path
|
|
47
|
+
+ * - rb_syntax_error_append
|
|
48
|
+
+ *
|
|
49
|
+
+ * Copyright (C) 1993-2007 Yukihiro Matsumoto
|
|
50
|
+
+ *
|
|
51
|
+
+ * Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
|
|
52
|
+
+ * You can redistribute it and/or modify it under either the terms of the
|
|
53
|
+
+ * 2-clause BSDL (see the file BSDL), or the conditions below:
|
|
54
|
+
+ *
|
|
55
|
+
+ * Redistribution and use in source and binary forms, with or without
|
|
56
|
+
+ * modification, are permitted provided that the following conditions
|
|
57
|
+
+ * are met:
|
|
58
|
+
+ * 1. Redistributions of source code must retain the above copyright
|
|
59
|
+
+ * notice, this list of conditions and the following disclaimer.
|
|
60
|
+
+ * 2. Redistributions in binary form must reproduce the above copyright
|
|
61
|
+
+ * notice, this list of conditions and the following disclaimer in the
|
|
62
|
+
+ * documentation and/or other materials provided with the distribution.
|
|
63
|
+
+ *
|
|
64
|
+
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
65
|
+
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
66
|
+
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
67
|
+
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
68
|
+
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
69
|
+
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
70
|
+
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
71
|
+
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
72
|
+
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
73
|
+
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
74
|
+
+ * SUCH DAMAGE.
|
|
75
|
+
+ */
|
|
76
|
+
+
|
|
77
|
+
+static VALUE
|
|
78
|
+
+err_vcatf(VALUE str, const char *pre, const char *file, int line,
|
|
79
|
+
+ const char *fmt, va_list args)
|
|
80
|
+
+{
|
|
81
|
+
+ if (file) {
|
|
82
|
+
+ rb_str_cat_cstr(str, file);
|
|
83
|
+
+ if (line) rb_str_catf(str, ":%d", line);
|
|
84
|
+
+ rb_str_cat_cstr(str, ": ");
|
|
85
|
+
+ }
|
|
86
|
+
+ if (pre) rb_str_cat_cstr(str, pre);
|
|
87
|
+
+ rb_str_vcatf(str, fmt, args);
|
|
88
|
+
+ return str;
|
|
89
|
+
+}
|
|
90
|
+
+
|
|
91
|
+
+static VALUE
|
|
92
|
+
+syntax_error_with_path(VALUE exc, VALUE file, VALUE *mesg, rb_encoding *enc)
|
|
93
|
+
+{
|
|
94
|
+
+ // Create new SyntaxError if exc is nil or Qfalse (for error_tolerant mode)
|
|
95
|
+
+ if (NIL_P(exc) || exc == Qfalse) {
|
|
96
|
+
+ exc = rb_class_new_instance(0, 0, rb_eSyntaxError);
|
|
97
|
+
+ }
|
|
98
|
+
+ *mesg = rb_attr_get(exc, rb_intern("mesg"));
|
|
99
|
+
+ // Check if mesg is nil or frozen (default "compile error" may be frozen)
|
|
100
|
+
+ if (NIL_P(*mesg) || OBJ_FROZEN(*mesg)) {
|
|
101
|
+
+ *mesg = rb_enc_str_new(0, 0, enc);
|
|
102
|
+
+ rb_ivar_set(exc, rb_intern("mesg"), *mesg);
|
|
103
|
+
+ }
|
|
104
|
+
+ return exc;
|
|
105
|
+
+}
|
|
106
|
+
+
|
|
107
|
+
+RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 6, 0)
|
|
108
|
+
+VALUE
|
|
109
|
+
+rb_syntax_error_append(VALUE exc, VALUE file, int line, int column,
|
|
110
|
+
+ rb_encoding *enc, const char *fmt, va_list args)
|
|
111
|
+
+{
|
|
112
|
+
+ const char *fn = NIL_P(file) ? NULL : RSTRING_PTR(file);
|
|
113
|
+
+ if (!exc) {
|
|
114
|
+
+ // For error_tolerant mode, create SyntaxError even when writing to stderr
|
|
115
|
+
+ exc = rb_class_new_instance(0, 0, rb_eSyntaxError);
|
|
116
|
+
+ VALUE mesg = rb_attr_get(exc, rb_intern("mesg"));
|
|
117
|
+
+ // Check if mesg is nil or frozen (default "compile error" may be frozen)
|
|
118
|
+
+ if (NIL_P(mesg) || OBJ_FROZEN(mesg)) {
|
|
119
|
+
+ mesg = rb_enc_str_new(0, 0, enc);
|
|
120
|
+
+ rb_ivar_set(exc, rb_intern("mesg"), mesg);
|
|
121
|
+
+ }
|
|
122
|
+
+ err_vcatf(mesg, NULL, fn, line, fmt, args);
|
|
123
|
+
+ // Still write to stderr for compatibility
|
|
124
|
+
+ VALUE err_mesg = rb_str_dup(mesg);
|
|
125
|
+
+ rb_str_cat_cstr(err_mesg, "\n");
|
|
126
|
+
+ rb_write_error_str(err_mesg);
|
|
127
|
+
+ }
|
|
128
|
+
+ else {
|
|
129
|
+
+ VALUE mesg;
|
|
130
|
+
+ exc = syntax_error_with_path(exc, file, &mesg, enc);
|
|
131
|
+
+ err_vcatf(mesg, NULL, fn, line, fmt, args);
|
|
132
|
+
+ }
|
|
133
|
+
+
|
|
134
|
+
+ return exc;
|
|
135
|
+
+}
|
|
136
|
+
+
|
|
137
|
+
RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 6, 0)
|
|
138
|
+
static VALUE
|
|
139
|
+
syntax_error_append(VALUE exc, VALUE file, int line, int column,
|
|
140
|
+
@@ -314,6 +408,44 @@ enc_mbc_to_codepoint(const char *p, const char *e, parser_encoding *enc)
|
|
141
|
+
|
|
142
|
+
extern VALUE rb_eArgError;
|
|
143
|
+
|
|
144
|
+
+// Add for Kanayago
|
|
145
|
+
+static void *
|
|
146
|
+
+xmalloc_mul_add(size_t x, size_t y, size_t z)
|
|
147
|
+
+{
|
|
148
|
+
+ return rb_xmalloc_mul_add(x, y, z);
|
|
149
|
+
+}
|
|
150
|
+
+
|
|
151
|
+
+static VALUE
|
|
152
|
+
+suppress_tracing(VALUE (*func)(VALUE), VALUE arg)
|
|
153
|
+
+{
|
|
154
|
+
+ return func(arg);
|
|
155
|
+
+}
|
|
156
|
+
+
|
|
157
|
+
+static ID
|
|
158
|
+
+make_temporary_id(size_t n)
|
|
159
|
+
+{
|
|
160
|
+
+ return rb_make_temporary_id(n);
|
|
161
|
+
+}
|
|
162
|
+
+
|
|
163
|
+
+static int
|
|
164
|
+
+stderr_tty_p(void)
|
|
165
|
+
+{
|
|
166
|
+
+ return rb_stderr_tty_p();
|
|
167
|
+
+}
|
|
168
|
+
+
|
|
169
|
+
+static VALUE
|
|
170
|
+
+reg_compile(VALUE str, int options, const char *sourcefile, int sourceline)
|
|
171
|
+
+{
|
|
172
|
+
+ return rb_reg_compile(str, options, sourcefile, sourceline);
|
|
173
|
+
+}
|
|
174
|
+
+
|
|
175
|
+
+static VALUE
|
|
176
|
+
+reg_check_preprocess(VALUE val)
|
|
177
|
+
+{
|
|
178
|
+
+ return rb_reg_check_preprocess(val);
|
|
179
|
+
+}
|
|
180
|
+
+// End of Add for Kanayago
|
|
181
|
+
+
|
|
182
|
+
static const rb_parser_config_t rb_global_parser_config = {
|
|
183
|
+
.malloc = ruby_xmalloc,
|
|
184
|
+
.calloc = ruby_xcalloc,
|
|
185
|
+
@@ -325,9 +457,9 @@ static const rb_parser_config_t rb_global_parser_config = {
|
|
186
|
+
.zalloc = zalloc,
|
|
187
|
+
.rb_memmove = memmove2,
|
|
188
|
+
.nonempty_memcpy = nonempty_memcpy,
|
|
189
|
+
- .xmalloc_mul_add = rb_xmalloc_mul_add,
|
|
190
|
+
+ .xmalloc_mul_add = xmalloc_mul_add, // use xmalloc_mul_add for Kanayago
|
|
191
|
+
|
|
192
|
+
- .compile_callback = rb_suppress_tracing,
|
|
193
|
+
+ .compile_callback = suppress_tracing, // use suppress_tracing for Kanayago
|
|
194
|
+
.reg_named_capture_assign = reg_named_capture_assign,
|
|
195
|
+
|
|
196
|
+
.attr_get = rb_attr_get,
|
|
197
|
+
@@ -335,7 +467,7 @@ static const rb_parser_config_t rb_global_parser_config = {
|
|
198
|
+
.ary_new_from_args = rb_ary_new_from_args,
|
|
199
|
+
.ary_unshift = rb_ary_unshift,
|
|
200
|
+
|
|
201
|
+
- .make_temporary_id = rb_make_temporary_id,
|
|
202
|
+
+ .make_temporary_id = make_temporary_id, // use make_temporary_id for Kanayago
|
|
203
|
+
.is_local_id = is_local_id2,
|
|
204
|
+
.is_attrset_id = is_attrset_id2,
|
|
205
|
+
.is_global_name_punct = is_global_name_punct,
|
|
206
|
+
@@ -365,7 +497,7 @@ static const rb_parser_config_t rb_global_parser_config = {
|
|
207
|
+
|
|
208
|
+
.int2num = rb_int2num_inline,
|
|
209
|
+
|
|
210
|
+
- .stderr_tty_p = rb_stderr_tty_p,
|
|
211
|
+
+ .stderr_tty_p = stderr_tty_p, //use stderr_tty_p for Kanayago
|
|
212
|
+
.write_error_str = rb_write_error_str,
|
|
213
|
+
.io_write = rb_io_write,
|
|
214
|
+
.io_flush = rb_io_flush,
|
|
215
|
+
@@ -412,8 +544,8 @@ static const rb_parser_config_t rb_global_parser_config = {
|
|
216
|
+
.gc_guard = gc_guard,
|
|
217
|
+
.gc_mark = rb_gc_mark,
|
|
218
|
+
|
|
219
|
+
- .reg_compile = rb_reg_compile,
|
|
220
|
+
- .reg_check_preprocess = rb_reg_check_preprocess,
|
|
221
|
+
+ .reg_compile = reg_compile, // use reg_compile for Kanayago
|
|
222
|
+
+ .reg_check_preprocess = reg_check_preprocess, // use reg_check_preprocess for Kanayago
|
|
223
|
+
.memcicmp = rb_memcicmp,
|
|
224
|
+
|
|
225
|
+
.compile_warn = rb_compile_warn,
|
|
226
|
+
@@ -443,27 +575,6 @@ static const rb_parser_config_t rb_global_parser_config = {
|
|
227
|
+
};
|
|
228
|
+
#endif
|
|
229
|
+
|
|
230
|
+
-enum lex_type {
|
|
231
|
+
- lex_type_str,
|
|
232
|
+
- lex_type_io,
|
|
233
|
+
- lex_type_array,
|
|
234
|
+
- lex_type_generic,
|
|
235
|
+
-};
|
|
236
|
+
-
|
|
237
|
+
-struct ruby_parser {
|
|
238
|
+
- rb_parser_t *parser_params;
|
|
239
|
+
- enum lex_type type;
|
|
240
|
+
- union {
|
|
241
|
+
- struct lex_pointer_string lex_str;
|
|
242
|
+
- struct {
|
|
243
|
+
- VALUE file;
|
|
244
|
+
- } lex_io;
|
|
245
|
+
- struct {
|
|
246
|
+
- VALUE ary;
|
|
247
|
+
- } lex_array;
|
|
248
|
+
- } data;
|
|
249
|
+
-};
|
|
250
|
+
-
|
|
251
|
+
static void
|
|
252
|
+
parser_mark(void *ptr)
|
|
253
|
+
{
|
|
254
|
+
@@ -501,7 +612,8 @@ parser_memsize(const void *ptr)
|
|
255
|
+
return rb_ruby_parser_memsize(parser->parser_params);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
-static const rb_data_type_t ruby_parser_data_type = {
|
|
259
|
+
+// Not static const for Kanayago
|
|
260
|
+
+const rb_data_type_t ruby_parser_data_type = {
|
|
261
|
+
"parser",
|
|
262
|
+
{
|
|
263
|
+
parser_mark,
|
|
264
|
+
diff --git a/ext/kanayago/parse.c b/ext/kanayago/parse.c
|
|
265
|
+
--- a/ext/kanayago/parse.c
|
|
266
|
+
+++ b/ext/kanayago/parse.c
|
|
267
|
+
@@ -27350,6 +27350,15 @@ ripper_value(struct parser_params *p)
|
|
268
|
+
return p->value;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
+#else /* !RIPPER */
|
|
272
|
+
+
|
|
273
|
+
+// Accessor function for error_buffer (for Kanayago)
|
|
274
|
+
+VALUE
|
|
275
|
+
+rb_ruby_parser_error_buffer_get(rb_parser_t *p)
|
|
276
|
+
+{
|
|
277
|
+
+ return p->error_buffer;
|
|
278
|
+
+}
|
|
279
|
+
+
|
|
280
|
+
#endif /* RIPPER */
|
|
281
|
+
/*
|
|
282
|
+
* Local variables:
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
--- a/ext/kanayago/ruby_parser.c
|
|
2
|
+
+++ b/ext/kanayago/ruby_parser.c
|
|
3
|
+
@@ -433,16 +433,21 @@
|
|
4
|
+
return rb_stderr_tty_p();
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
+// Kanayago macOS: Use rb_reg_new_str instead of rb_reg_compile (not exported in Ruby head)
|
|
8
|
+
static VALUE
|
|
9
|
+
reg_compile(VALUE str, int options, const char *sourcefile, int sourceline)
|
|
10
|
+
{
|
|
11
|
+
- return rb_reg_compile(str, options, sourcefile, sourceline);
|
|
12
|
+
+ (void)sourcefile;
|
|
13
|
+
+ (void)sourceline;
|
|
14
|
+
+ return rb_reg_new_str(str, options);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
+// Kanayago macOS: Return Qnil instead of calling rb_reg_check_preprocess (not exported in Ruby head)
|
|
18
|
+
static VALUE
|
|
19
|
+
reg_check_preprocess(VALUE val)
|
|
20
|
+
{
|
|
21
|
+
- return rb_reg_check_preprocess(val);
|
|
22
|
+
+ (void)val;
|
|
23
|
+
+ return Qnil;
|
|
24
|
+
}
|
|
25
|
+
// End of Add for Kanayago
|
|
26
|
+
|
|
27
|
+
@@ -985,7 +990,8 @@
|
|
28
|
+
VALUE
|
|
29
|
+
rb_str_new_parser_string(rb_parser_string_t *str)
|
|
30
|
+
{
|
|
31
|
+
- VALUE string = rb_enc_literal_str(str->ptr, str->len, str->enc);
|
|
32
|
+
+ // Kanayago macOS: Use rb_enc_str_new instead of rb_enc_literal_str (not exported in Ruby head)
|
|
33
|
+
+ VALUE string = rb_enc_str_new(str->ptr, str->len, str->enc);
|
|
34
|
+
rb_enc_str_coderange(string);
|
|
35
|
+
return string;
|
|
36
|
+
}
|
|
37
|
+
@@ -1167,7 +1173,8 @@
|
|
38
|
+
rb_parser_string_t *string = node_reg->string;
|
|
39
|
+
VALUE str = rb_enc_str_new(string->ptr, string->len, string->enc);
|
|
40
|
+
|
|
41
|
+
- return rb_reg_compile(str, node_reg->options, NULL, 0);
|
|
42
|
+
+ // Kanayago macOS: Use rb_reg_new_str instead of rb_reg_compile
|
|
43
|
+
+ return rb_reg_new_str(str, node_reg->options);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
VALUE
|
data/patch/head/kanayago.patch
CHANGED
|
@@ -264,7 +264,7 @@ index 267f619..841db65 100644
|
|
|
264
264
|
diff --git a/ext/kanayago/parse.c b/ext/kanayago/parse.c
|
|
265
265
|
--- a/ext/kanayago/parse.c
|
|
266
266
|
+++ b/ext/kanayago/parse.c
|
|
267
|
-
@@ -
|
|
267
|
+
@@ -27350,6 +27350,15 @@ ripper_value(struct parser_params *p)
|
|
268
268
|
return p->value;
|
|
269
269
|
}
|
|
270
270
|
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
--- a/ext/kanayago/ruby_parser.c
|
|
2
|
+
+++ b/ext/kanayago/ruby_parser.c
|
|
3
|
+
@@ -6,7 +6,6 @@
|
|
4
|
+
|
|
5
|
+
#include "node.h"
|
|
6
|
+
#include "rubyparser.h"
|
|
7
|
+
-#include "internal/error.h"
|
|
8
|
+
|
|
9
|
+
#ifdef UNIVERSAL_PARSER
|
|
10
|
+
|
|
11
|
+
@@ -433,16 +432,21 @@ stderr_tty_p(void)
|
|
12
|
+
return rb_stderr_tty_p();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
+// Kanayago macOS: Use rb_reg_new_str instead of rb_reg_compile (not exported in Ruby head)
|
|
16
|
+
static VALUE
|
|
17
|
+
reg_compile(VALUE str, int options, const char *sourcefile, int sourceline)
|
|
18
|
+
{
|
|
19
|
+
- return rb_reg_compile(str, options, sourcefile, sourceline);
|
|
20
|
+
+ (void)sourcefile;
|
|
21
|
+
+ (void)sourceline;
|
|
22
|
+
+ return rb_reg_new_str(str, options);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
+// Kanayago macOS: Return Qnil instead of calling rb_reg_check_preprocess (not exported in Ruby head)
|
|
26
|
+
static VALUE
|
|
27
|
+
reg_check_preprocess(VALUE val)
|
|
28
|
+
{
|
|
29
|
+
- return rb_reg_check_preprocess(val);
|
|
30
|
+
+ (void)val;
|
|
31
|
+
+ return Qnil;
|
|
32
|
+
}
|
|
33
|
+
// End of Add for Kanayago
|
|
34
|
+
|
|
35
|
+
@@ -985,7 +989,8 @@ rb_parser_build_script_lines_from(rb_par
|
|
36
|
+
VALUE
|
|
37
|
+
rb_str_new_parser_string(rb_parser_string_t *str)
|
|
38
|
+
{
|
|
39
|
+
- VALUE string = rb_enc_literal_str(str->ptr, str->len, str->enc);
|
|
40
|
+
+ // Kanayago macOS: Use rb_enc_str_new instead of rb_enc_literal_str (not exported in Ruby head)
|
|
41
|
+
+ VALUE string = rb_enc_str_new(str->ptr, str->len, str->enc);
|
|
42
|
+
rb_enc_str_coderange(string);
|
|
43
|
+
return string;
|
|
44
|
+
}
|
|
45
|
+
@@ -1027,8 +1032,9 @@ negative_numeric(VALUE val)
|
|
46
|
+
break;
|
|
47
|
+
unknown:
|
|
48
|
+
default:
|
|
49
|
+
+ // Kanayago macOS: Use rb_obj_classname instead of rb_builtin_class_name
|
|
50
|
+
rb_bug("unknown literal type (%s) passed to negative_numeric",
|
|
51
|
+
- rb_builtin_class_name(val));
|
|
52
|
+
+ rb_obj_classname(val));
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
return val;
|
|
56
|
+
@@ -1167,7 +1173,8 @@ rb_node_regx_string_val(const NODE *node
|
|
57
|
+
rb_parser_string_t *string = node_reg->string;
|
|
58
|
+
VALUE str = rb_enc_str_new(string->ptr, string->len, string->enc);
|
|
59
|
+
|
|
60
|
+
- return rb_reg_compile(str, node_reg->options, NULL, 0);
|
|
61
|
+
+ // Kanayago macOS: Use rb_reg_new_str instead of rb_reg_compile
|
|
62
|
+
+ return rb_reg_new_str(str, node_reg->options);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
VALUE
|