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.
@@ -0,0 +1,78 @@
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
+ internal/array.h
12
+ internal/basic_operators.h
13
+ internal/bignum.h
14
+ internal/bits.h
15
+ internal/compile.h
16
+ internal/compilers.h
17
+ internal/complex.h
18
+ internal/encoding.h
19
+ internal/error.h
20
+ internal/fixnum.h
21
+ internal/gc.h
22
+ internal/hash.h
23
+ internal/imemo.h
24
+ internal/io.h
25
+ internal/numeric.h
26
+ internal/parse.h
27
+ internal/rational.h
28
+ internal/re.h
29
+ internal/ruby_parser.h
30
+ internal/sanitizers.h
31
+ internal/serial.h
32
+ internal/static_assert.h
33
+ internal/string.h
34
+ internal/symbol.h
35
+ internal/thread.h
36
+ internal/variable.h
37
+ internal/warnings.h
38
+ internal/vm.h
39
+ internal.h
40
+ lex.c
41
+ method.h
42
+ node.c
43
+ node.h
44
+ node_name.inc
45
+ parse.c
46
+ parse.h
47
+ parser_bits.h
48
+ parser_node.h
49
+ parser_st.c
50
+ parser_st.h
51
+ parser_value.h
52
+ ruby_assert.h
53
+ ruby_atomic.h
54
+ ruby_parser.c
55
+ rubyparser.h
56
+ shape.h
57
+ st.c
58
+ symbol.h
59
+ thread_pthread.h
60
+ universal_parser.c
61
+ vm_core.h
62
+ vm_opts.h
63
+ ].freeze
64
+
65
+ MAKE_DIRECTORIES = [
66
+ 'ccan',
67
+ 'ccan/check_type',
68
+ 'ccan/container',
69
+ 'ccan/container_of',
70
+ 'ccan/list',
71
+ 'ccan/str',
72
+ 'internal'
73
+ ].freeze
74
+
75
+ DELETE_DIRECTORIES = %w[
76
+ ccan
77
+ internal
78
+ ].freeze
@@ -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:49:33.742994229 +0900
3
+ +++ b/ext/kanayago/internal/ruby_parser.h 2025-12-17 19:49:33.742994229 +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:49:33.742994229 +0900
43
+ +++ b/ext/kanayago/parse.c 2025-12-17 19:49:33.742994229 +0900
44
+ @@ -26828,6 +26828,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:49:33.742994229 +0900
63
+ +++ b/ext/kanayago/ruby_parser.c 2025-12-17 19:49:33.742994229 +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,78 @@
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
+ internal/array.h
12
+ internal/basic_operators.h
13
+ internal/bignum.h
14
+ internal/bits.h
15
+ internal/compile.h
16
+ internal/compilers.h
17
+ internal/complex.h
18
+ internal/encoding.h
19
+ internal/error.h
20
+ internal/fixnum.h
21
+ internal/gc.h
22
+ internal/hash.h
23
+ internal/imemo.h
24
+ internal/io.h
25
+ internal/numeric.h
26
+ internal/parse.h
27
+ internal/rational.h
28
+ internal/re.h
29
+ internal/ruby_parser.h
30
+ internal/sanitizers.h
31
+ internal/serial.h
32
+ internal/static_assert.h
33
+ internal/string.h
34
+ internal/symbol.h
35
+ internal/thread.h
36
+ internal/variable.h
37
+ internal/warnings.h
38
+ internal/vm.h
39
+ internal.h
40
+ lex.c
41
+ method.h
42
+ node.c
43
+ node.h
44
+ node_name.inc
45
+ parse.c
46
+ parse.h
47
+ parser_bits.h
48
+ parser_node.h
49
+ parser_st.c
50
+ parser_st.h
51
+ parser_value.h
52
+ ruby_assert.h
53
+ ruby_atomic.h
54
+ ruby_parser.c
55
+ rubyparser.h
56
+ shape.h
57
+ st.c
58
+ symbol.h
59
+ thread_pthread.h
60
+ universal_parser.c
61
+ vm_core.h
62
+ vm_opts.h
63
+ ].freeze
64
+
65
+ MAKE_DIRECTORIES = [
66
+ 'ccan',
67
+ 'ccan/check_type',
68
+ 'ccan/container',
69
+ 'ccan/container_of',
70
+ 'ccan/list',
71
+ 'ccan/str',
72
+ 'internal'
73
+ ].freeze
74
+
75
+ DELETE_DIRECTORIES = %w[
76
+ ccan
77
+ internal
78
+ ].freeze
@@ -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:49:39.804477317 +0900
3
+ +++ b/ext/kanayago/internal/ruby_parser.h 2025-12-17 19:49:39.804477317 +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:49:39.804477317 +0900
43
+ +++ b/ext/kanayago/parse.c 2025-12-17 19:49:39.804477317 +0900
44
+ @@ -26828,6 +26828,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:49:39.804477317 +0900
63
+ +++ b/ext/kanayago/ruby_parser.c 2025-12-17 19:49:39.804477317 +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,78 @@
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
+ internal/array.h
12
+ internal/basic_operators.h
13
+ internal/bignum.h
14
+ internal/bits.h
15
+ internal/compile.h
16
+ internal/compilers.h
17
+ internal/complex.h
18
+ internal/encoding.h
19
+ internal/error.h
20
+ internal/fixnum.h
21
+ internal/gc.h
22
+ internal/hash.h
23
+ internal/imemo.h
24
+ internal/io.h
25
+ internal/numeric.h
26
+ internal/parse.h
27
+ internal/rational.h
28
+ internal/re.h
29
+ internal/ruby_parser.h
30
+ internal/sanitizers.h
31
+ internal/serial.h
32
+ internal/static_assert.h
33
+ internal/string.h
34
+ internal/symbol.h
35
+ internal/thread.h
36
+ internal/variable.h
37
+ internal/warnings.h
38
+ internal/vm.h
39
+ internal.h
40
+ lex.c
41
+ method.h
42
+ node.c
43
+ node.h
44
+ node_name.inc
45
+ parse.c
46
+ parse.h
47
+ parser_bits.h
48
+ parser_node.h
49
+ parser_st.c
50
+ parser_st.h
51
+ parser_value.h
52
+ ruby_assert.h
53
+ ruby_atomic.h
54
+ ruby_parser.c
55
+ rubyparser.h
56
+ shape.h
57
+ st.c
58
+ symbol.h
59
+ thread_pthread.h
60
+ universal_parser.c
61
+ vm_core.h
62
+ vm_opts.h
63
+ ].freeze
64
+
65
+ MAKE_DIRECTORIES = [
66
+ 'ccan',
67
+ 'ccan/check_type',
68
+ 'ccan/container',
69
+ 'ccan/container_of',
70
+ 'ccan/list',
71
+ 'ccan/str',
72
+ 'internal'
73
+ ].freeze
74
+
75
+ DELETE_DIRECTORIES = %w[
76
+ ccan
77
+ internal
78
+ ].freeze