kanayago 0.3.0 → 0.4.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/CHANGELOG.md +261 -0
- data/README.md +1 -1
- data/ext/kanayago/kanayago.c +30 -185
- data/ext/kanayago/scope_node.c +2 -16
- data/ext/kanayago/variable_node.c +2 -1
- data/lib/kanayago/call_node.rb +19 -0
- data/lib/kanayago/constant_node.rb +15 -0
- data/lib/kanayago/literal_node.rb +4 -0
- data/lib/kanayago/scope_node.rb +14 -0
- data/lib/kanayago/statement_node.rb +16 -0
- data/lib/kanayago/variable_node.rb +4 -0
- data/lib/kanayago/version.rb +1 -1
- data/lib/kanayago.rb +3 -16
- metadata +5 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5c6e26071a97395c4f35c029908d78bba8a927f75129aa361367dc9cf549c3ca
|
|
4
|
+
data.tar.gz: be48eae66a3bc69256ff3a9dba5afa842b8b8876f7be66eb72d79774fb94d878
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5073effb4706b23b912a61f79a3bb40d2565e59f4d9805c6ba6f3006c613d8029340d2e164e67f94eb0341cc7b14d340ca5a9f862ee8c4fb84a2b8a86f1622b9
|
|
7
|
+
data.tar.gz: 5731b6e8463b384cbd3dfe7bd3bf67835ea0a4a8f51ac0ee84259f8fd04d414fd5b2e1ea38e79f6f3dfab83787207c86757dfa5bce0180bfbf6fbac1102665ef
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.4.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Add Ruby class definitions for previously C-only AST nodes:
|
|
14
|
+
- `ScopeNode` - Scope representation with args and body
|
|
15
|
+
- `ClassNode` - Class definition with cpath, super, and body
|
|
16
|
+
- `ModuleNode` - Module definition with cpath, super, and body
|
|
17
|
+
- `DefinitionNode` - Method definition with mid and defn
|
|
18
|
+
- `BeginNode` - Begin statement with body
|
|
19
|
+
- `SelfNode` - Self reference with state
|
|
20
|
+
- `ConstantNode` - Constant reference with vid
|
|
21
|
+
- `OperatorCallNode` - Operator method call with recv, mid, and args
|
|
22
|
+
- `CallNode` - Method call with recv, mid, and args
|
|
23
|
+
- `FunctionCallNode` - Function call with mid and args
|
|
24
|
+
- `VariableCallNode` - Variable call with mid
|
|
25
|
+
- `ArgumentsNode` - Arguments information with ainfo hash
|
|
26
|
+
- `BlockNode` - Block representation (inherits from Array)
|
|
27
|
+
- `ConstantDeclarationNode` - Constant declaration with vid, else, and value
|
|
28
|
+
- `Colon2Node` - Scoped constant resolution (::) with mid and head
|
|
29
|
+
- `Colon3Node` - Top-level constant resolution (::) with mid
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
- Use `rb_intern("@...")` instead of `symbol()` macro for instance variable access in C layer
|
|
33
|
+
- Remove redundant getter methods from C layer (scope_node.c and kanayago.c)
|
|
34
|
+
- Rely on Ruby's `attr_reader` for attribute access instead of C-defined methods
|
|
35
|
+
|
|
36
|
+
### Fixed
|
|
37
|
+
- Fix SEGV in args_ainfo_tohash function
|
|
38
|
+
|
|
39
|
+
## [0.3.0] - 2025-10-25
|
|
40
|
+
|
|
41
|
+
### Fixed
|
|
42
|
+
- Fix gem install kanayago
|
|
43
|
+
|
|
44
|
+
## [0.2.0] - 2025-10-25
|
|
45
|
+
|
|
46
|
+
### Added
|
|
47
|
+
- Add sample for Kanayago usecase
|
|
48
|
+
- Support NODE_FOR_MASGN, NODE_MASGN, NODE_DASGN, NODE_ONCE, NODE_ERRINFO, NODE_POSTEXE, and NODE_ERROR
|
|
49
|
+
- Support NODE_ARGS_AUX, NODE_OPT_ARG, NODE_KW_ARG, NODE_POSTARG, NODE_ARGSCAT, and NODE_ARGSPUSH
|
|
50
|
+
- Support NODE_SPLAT and NODE_BLOCK_PASS
|
|
51
|
+
- Support NODE_YIELD and NODE_LAMBDA
|
|
52
|
+
- Support NODE_OP_ASGN1, NODE_OP_ASGN2, NODE_OP_ASGN_AND, NODE_OP_ASGN_OR and NODE_OP_CDECL
|
|
53
|
+
- Support NODE_NTH_REF and NODE_BACK_REF
|
|
54
|
+
- Support NODE_DVAR
|
|
55
|
+
- Support NODE_DSYM
|
|
56
|
+
- Support NODE_BREAK and NODE_NEXT
|
|
57
|
+
- Support NODE_REDO
|
|
58
|
+
- Support NODE_DEFINED
|
|
59
|
+
- Support NODE_ITER, NODE_RETRY, NODE_RESCUE, NODE_RESBODY and NODE_ENSURE
|
|
60
|
+
- Support NODE_HASH, NODE_IN, NODE_ARYPTN, NODE_HSHPTN and NODE_FNDPTN
|
|
61
|
+
- Support NODE_MATCH, NODE_MATCH2 and NODE_MATCH3
|
|
62
|
+
- Support NODE_REGX and NODE_DREGX
|
|
63
|
+
- Support NODE_XSTR and NODE_DXSTR
|
|
64
|
+
- Support NODE_FLIP2 and NODE_FLIP3
|
|
65
|
+
- Support NODE_DOT2 and NODE_DOT3
|
|
66
|
+
- Support NODE_CASE, NODE_CASE2, NODE_CASE3 and NODE_WHEN
|
|
67
|
+
- Support NODE_QCALL, NODE_SUPER and NODE_ZSUPER
|
|
68
|
+
- Support NODE_DEFS, NODE_SCLASS and NODE_ATTRASGN
|
|
69
|
+
- Support NODE_COLON3
|
|
70
|
+
- Support NODE_VCALL
|
|
71
|
+
- Support NODE_CVASGN
|
|
72
|
+
- Support NODE_IASGN
|
|
73
|
+
- Support NODE_DSTR and NODE_EVSTR
|
|
74
|
+
- Support NODE_GASGN
|
|
75
|
+
- Support NODE_RETURN
|
|
76
|
+
- Support NODE_UNDEF
|
|
77
|
+
- Support NODE_VALIAS
|
|
78
|
+
- Support NODE_ALIAS
|
|
79
|
+
- Support NODE_FOR
|
|
80
|
+
- Support NODE_UNTIL
|
|
81
|
+
- Add NODE_WHILE test
|
|
82
|
+
- Support NODE_WHILE
|
|
83
|
+
- Support NODE_CVAR
|
|
84
|
+
- Introduce debug.gem
|
|
85
|
+
- Support NODE_MODULE
|
|
86
|
+
- Support NODE_SELF
|
|
87
|
+
- Support NODE_GVAR
|
|
88
|
+
- Support NODE_AND
|
|
89
|
+
- Support NODE_OR
|
|
90
|
+
- Support NODE_FALSE
|
|
91
|
+
- Support NODE_TRUE
|
|
92
|
+
- Support NODE_NIL
|
|
93
|
+
- Support NODE_ENCODING
|
|
94
|
+
- Add typeprof.conf.json
|
|
95
|
+
- Support NODE_ZLIST
|
|
96
|
+
- Introduce TypeProf for development
|
|
97
|
+
- Support __LINE__ literal node
|
|
98
|
+
- Support __FILE__ literal node
|
|
99
|
+
- Support Ruby 3.4
|
|
100
|
+
- Introduce Kanayago gem build and install CI
|
|
101
|
+
|
|
102
|
+
### Changed
|
|
103
|
+
- Update RuboCop
|
|
104
|
+
- Split kanayago.patch file to more easier maintain multi Ruby Parser
|
|
105
|
+
- Update bin/setup
|
|
106
|
+
- Use Node class attr_reader to access Node values
|
|
107
|
+
- Split Literal Node code
|
|
108
|
+
- Split Kanayago::ScopeNode code
|
|
109
|
+
- Update README.md
|
|
110
|
+
- Update test CI
|
|
111
|
+
- Update kanayago.patch
|
|
112
|
+
- Improve import Ruby Parser file's
|
|
113
|
+
- Update RuboCop setting
|
|
114
|
+
- Migrate to Kanayago parsed AST hash to Instance
|
|
115
|
+
- Update kanayago.patch for Ruby head build
|
|
116
|
+
- Update CI flow
|
|
117
|
+
- Update Kanayago build flow
|
|
118
|
+
- Update Ruby Parser's file
|
|
119
|
+
- Update lrama
|
|
120
|
+
- Split file for Variable Node's
|
|
121
|
+
- Move Statement Node class definition
|
|
122
|
+
- Rename LeftAssignNode to LocalAssignmentNode
|
|
123
|
+
|
|
124
|
+
### Fixed
|
|
125
|
+
- Fix RuboCop Lint error
|
|
126
|
+
- Fix NODE_IF attributes access
|
|
127
|
+
- Fix Kanayago::ListNode holds data
|
|
128
|
+
- Fix NODE_FOR loop
|
|
129
|
+
- Fix Ruby head build failure
|
|
130
|
+
- Add internal/namespace.h for Ruby head Parser dependency
|
|
131
|
+
- Fix RuboCop SEGV in Ruby head
|
|
132
|
+
- Apply auto correct
|
|
133
|
+
- Update json
|
|
134
|
+
- Update zlib
|
|
135
|
+
- Fix CI failures
|
|
136
|
+
- Add ext/kanayago/probes.h
|
|
137
|
+
- Fix Ruby 3.4 dependency
|
|
138
|
+
- Fix Ruby 3.4 build
|
|
139
|
+
- Fix file copy error handling
|
|
140
|
+
- Fix build gem
|
|
141
|
+
- Add dependency for Universal Parser
|
|
142
|
+
- Fix code lint
|
|
143
|
+
|
|
144
|
+
### Removed
|
|
145
|
+
- Remove unneeded comment
|
|
146
|
+
- Remove Lrama that unneeded any more
|
|
147
|
+
|
|
148
|
+
### CI
|
|
149
|
+
- Add fail-fast: false
|
|
150
|
+
- Suppress already initialized constant warning
|
|
151
|
+
|
|
152
|
+
## [0.1.1] - 2024-09-06
|
|
153
|
+
|
|
154
|
+
### Changed
|
|
155
|
+
- Bump up v0.1.1
|
|
156
|
+
|
|
157
|
+
## [0.1.0] - 2024-09-06
|
|
158
|
+
|
|
159
|
+
### Added
|
|
160
|
+
- Support NODE_UNLESS
|
|
161
|
+
- Add class description
|
|
162
|
+
- Add rubocop check in CI
|
|
163
|
+
- Add rubocop-on-rbs
|
|
164
|
+
- Add rubocop-rake
|
|
165
|
+
- Add rubocop and rubocop-minitest for development
|
|
166
|
+
- Add refine_tree_parse module function
|
|
167
|
+
- Support NODE_IVAR
|
|
168
|
+
- Add Referenced implementations link
|
|
169
|
+
- Support NODE_SYM
|
|
170
|
+
- Support method definition
|
|
171
|
+
- Add NODE_CONST test
|
|
172
|
+
- Support NODE_CDECL
|
|
173
|
+
- Support NODE_CONST
|
|
174
|
+
- Support NODE_IF
|
|
175
|
+
- Support NODE_LVAR
|
|
176
|
+
- Add gdb rake task
|
|
177
|
+
- Support NODE_FCALL
|
|
178
|
+
- Introduce literal_node_to_hash function for get literal node value
|
|
179
|
+
- Support NODE_LASGN
|
|
180
|
+
- Add NODE_STR parse test
|
|
181
|
+
- Add NODE_IMAGINARY parse test
|
|
182
|
+
- Add NODE_RATIONAL parse test
|
|
183
|
+
- Add NODE_FLOAT parse test
|
|
184
|
+
- Add parse NODE_INTEGER test
|
|
185
|
+
- Add GitHub Actions for test
|
|
186
|
+
- Add Ruby's Parser files
|
|
187
|
+
- Add run task for running test.rb
|
|
188
|
+
- Add test for NODE_INTEGER
|
|
189
|
+
- Support NODE_CALL
|
|
190
|
+
- Support NODE_STR
|
|
191
|
+
- Support NODE_IMAGINARY
|
|
192
|
+
- Support NODE_BLOCK
|
|
193
|
+
- Support NODE_RATIONAL
|
|
194
|
+
- Support NODE_FLOAT
|
|
195
|
+
- Support NODE_OPCALL and NODE_LIST
|
|
196
|
+
- Parse Ruby code and return Hash
|
|
197
|
+
- Build Mjollnir with Ruby Parser
|
|
198
|
+
- Build ruby-parser for Mjollnir
|
|
199
|
+
- Add ruby_parser:build task
|
|
200
|
+
- Add lex.c generation for ruby_parser:import task
|
|
201
|
+
- Add ruby_parser:clean task
|
|
202
|
+
- Add Mjollnir.parse method
|
|
203
|
+
- Import ruby parser
|
|
204
|
+
- Add lrama
|
|
205
|
+
- Add 金屋子 for README.md
|
|
206
|
+
|
|
207
|
+
### Changed
|
|
208
|
+
- Rename parse to kanayago_parse
|
|
209
|
+
- Using test-queue
|
|
210
|
+
- Auto correct to Gemfile
|
|
211
|
+
- Auto correct Hash
|
|
212
|
+
- Fix required_ruby_version to > 3.3.0
|
|
213
|
+
- Rename to Kanayago
|
|
214
|
+
- Ignore refine_tree.gemspec in Metrics/BlockLength
|
|
215
|
+
- Format Rakefile
|
|
216
|
+
- Rename sig/refine_tree.rb to sig/refine_tree.rbs
|
|
217
|
+
- require rubocop-minitest and rubocop-rake
|
|
218
|
+
- Generate .rubocop.yml and .rubocop_todo.yml
|
|
219
|
+
- Move minitest to test group in Gemfile
|
|
220
|
+
- Change to key type from String to Symbol
|
|
221
|
+
- Fix require path for test
|
|
222
|
+
- Fix install gem name
|
|
223
|
+
- Rename to RefineTree
|
|
224
|
+
- Fix GitHub Actions
|
|
225
|
+
- Add PATH for GitHub Actions
|
|
226
|
+
- Add install check for GitHub Actions
|
|
227
|
+
- Add depend task for rake build and rake install
|
|
228
|
+
- Fix Mjollnir.parse sample in README.md
|
|
229
|
+
- Fix username in README.md
|
|
230
|
+
- Merge Ruby's Parser struct and enum definition for Mjollnir
|
|
231
|
+
- Fix Mjollnir gem summary and description
|
|
232
|
+
- Fix gem's description
|
|
233
|
+
- Fix README.md
|
|
234
|
+
- Fix Mjollnir gem build and install
|
|
235
|
+
- Apply RuboCop auto correct to Gemfile
|
|
236
|
+
- Apply RuboCop auto correct for test helper
|
|
237
|
+
- Apply RuboCop auto correct
|
|
238
|
+
- Fix Mjollnir build
|
|
239
|
+
- Update TODO's
|
|
240
|
+
|
|
241
|
+
### Fixed
|
|
242
|
+
- Fix SEGV
|
|
243
|
+
- Fix NODE_BLOCK support
|
|
244
|
+
- Remove allowed_push_host
|
|
245
|
+
- Remove parse.c and parse.h
|
|
246
|
+
- Ignore parse.c and parse.h
|
|
247
|
+
- Fix gem name in GitHub Action
|
|
248
|
+
|
|
249
|
+
### Removed
|
|
250
|
+
- Remove uneeded file
|
|
251
|
+
- Remove unnecessary include header
|
|
252
|
+
- Remove unnecessary code in Rakefile
|
|
253
|
+
- Remove ext/mjollnir/ruby-parser directory
|
|
254
|
+
- Remove uneeded headers
|
|
255
|
+
- Remove gem build for CI
|
|
256
|
+
|
|
257
|
+
### Internal
|
|
258
|
+
- Suppress warning
|
|
259
|
+
- Add newline
|
|
260
|
+
- Some refactor for mjollnir.c
|
|
261
|
+
- Using rb_ruby_ast_data_get function
|
data/README.md
CHANGED
data/ext/kanayago/kanayago.c
CHANGED
|
@@ -33,84 +33,36 @@ operator_call_node_new(const NODE *node)
|
|
|
33
33
|
{
|
|
34
34
|
VALUE obj = rb_class_new_instance(0, 0, rb_cOperatorCallNode);
|
|
35
35
|
|
|
36
|
-
rb_ivar_set(obj,
|
|
37
|
-
rb_ivar_set(obj,
|
|
38
|
-
rb_ivar_set(obj,
|
|
36
|
+
rb_ivar_set(obj, rb_intern("@recv"), ast_to_node_instance(RNODE_OPCALL(node)->nd_recv));
|
|
37
|
+
rb_ivar_set(obj, rb_intern("@mid"), ID2SYM(RNODE_OPCALL(node)->nd_mid));
|
|
38
|
+
rb_ivar_set(obj, rb_intern("@args"), ast_to_node_instance(RNODE_OPCALL(node)->nd_args));
|
|
39
39
|
|
|
40
40
|
return obj;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
static VALUE
|
|
44
|
-
operator_call_node_recv_get(VALUE self)
|
|
45
|
-
{
|
|
46
|
-
return rb_ivar_get(self, symbol("recv"));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
static VALUE
|
|
50
|
-
operator_call_node_mid_get(VALUE self)
|
|
51
|
-
{
|
|
52
|
-
return rb_ivar_get(self, symbol("mid"));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
static VALUE
|
|
56
|
-
operator_call_node_args_get(VALUE self)
|
|
57
|
-
{
|
|
58
|
-
return rb_ivar_get(self, symbol("args"));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
43
|
static VALUE
|
|
62
44
|
call_node_new(const NODE *node)
|
|
63
45
|
{
|
|
64
46
|
VALUE result = rb_class_new_instance(0, 0, rb_cCallNode);
|
|
65
47
|
|
|
66
|
-
rb_ivar_set(result,
|
|
67
|
-
rb_ivar_set(result,
|
|
68
|
-
rb_ivar_set(result,
|
|
48
|
+
rb_ivar_set(result, rb_intern("@recv"), ast_to_node_instance(RNODE_OPCALL(node)->nd_recv));
|
|
49
|
+
rb_ivar_set(result, rb_intern("@mid"), ID2SYM(RNODE_CALL(node)->nd_mid));
|
|
50
|
+
rb_ivar_set(result, rb_intern("@args"), ast_to_node_instance(RNODE_CALL(node)->nd_args));
|
|
69
51
|
|
|
70
52
|
return result;
|
|
71
53
|
}
|
|
72
54
|
|
|
73
|
-
static VALUE
|
|
74
|
-
call_node_recv_get(VALUE self)
|
|
75
|
-
{
|
|
76
|
-
return rb_ivar_get(self, symbol("recv"));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
static VALUE
|
|
80
|
-
call_node_mid_get(VALUE self)
|
|
81
|
-
{
|
|
82
|
-
return rb_ivar_get(self, symbol("mid"));
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
static VALUE
|
|
86
|
-
call_node_args_get(VALUE self)
|
|
87
|
-
{
|
|
88
|
-
return rb_ivar_get(self, symbol("args"));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
55
|
static VALUE
|
|
92
56
|
function_call_node_new(const NODE *node)
|
|
93
57
|
{
|
|
94
58
|
VALUE obj = rb_class_new_instance(0, 0, rb_cFunctionCallNode);
|
|
95
59
|
|
|
96
|
-
rb_ivar_set(obj,
|
|
97
|
-
rb_ivar_set(obj,
|
|
60
|
+
rb_ivar_set(obj, rb_intern("@mid"), ID2SYM(RNODE_FCALL(node)->nd_mid));
|
|
61
|
+
rb_ivar_set(obj, rb_intern("@args"), ast_to_node_instance(RNODE_FCALL(node)->nd_args));
|
|
98
62
|
|
|
99
63
|
return obj;
|
|
100
64
|
}
|
|
101
65
|
|
|
102
|
-
static VALUE
|
|
103
|
-
function_call_node_mid_get(VALUE self)
|
|
104
|
-
{
|
|
105
|
-
return rb_ivar_get(self, symbol("mid"));
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
static VALUE
|
|
109
|
-
function_call_node_args_get(VALUE self)
|
|
110
|
-
{
|
|
111
|
-
return rb_ivar_get(self, symbol("args"));
|
|
112
|
-
}
|
|
113
|
-
|
|
114
66
|
static VALUE
|
|
115
67
|
variable_call_node_new(const NODE *node)
|
|
116
68
|
{
|
|
@@ -121,12 +73,6 @@ variable_call_node_new(const NODE *node)
|
|
|
121
73
|
return obj;
|
|
122
74
|
}
|
|
123
75
|
|
|
124
|
-
static VALUE
|
|
125
|
-
variable_call_node_mid_get(VALUE self)
|
|
126
|
-
{
|
|
127
|
-
return rb_ivar_get(self, rb_intern("@mid"));
|
|
128
|
-
}
|
|
129
|
-
|
|
130
76
|
static VALUE
|
|
131
77
|
list_node_new(const NODE *node)
|
|
132
78
|
{
|
|
@@ -151,24 +97,12 @@ definition_node_new(const NODE *node)
|
|
|
151
97
|
{
|
|
152
98
|
VALUE obj = rb_class_new_instance(0, 0, rb_cDefinitionNode);
|
|
153
99
|
|
|
154
|
-
rb_ivar_set(obj,
|
|
155
|
-
rb_ivar_set(obj,
|
|
100
|
+
rb_ivar_set(obj, rb_intern("@mid"), ID2SYM(RNODE_DEFN(node)->nd_mid));
|
|
101
|
+
rb_ivar_set(obj, rb_intern("@defn"), ast_to_node_instance(RNODE_DEFN(node)->nd_defn));
|
|
156
102
|
|
|
157
103
|
return obj;
|
|
158
104
|
}
|
|
159
105
|
|
|
160
|
-
static VALUE
|
|
161
|
-
definition_node_mid_get(VALUE self)
|
|
162
|
-
{
|
|
163
|
-
return rb_ivar_get(self, symbol("mid"));
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
static VALUE
|
|
167
|
-
definition_node_defn_get(VALUE self)
|
|
168
|
-
{
|
|
169
|
-
return rb_ivar_get(self, symbol("defn"));
|
|
170
|
-
}
|
|
171
|
-
|
|
172
106
|
static VALUE
|
|
173
107
|
block_node_new(const NODE *node)
|
|
174
108
|
{
|
|
@@ -188,47 +122,23 @@ constant_node_new(const NODE *node)
|
|
|
188
122
|
{
|
|
189
123
|
VALUE obj = rb_class_new_instance(0, 0, rb_cConstantNode);
|
|
190
124
|
|
|
191
|
-
rb_ivar_set(obj,
|
|
125
|
+
rb_ivar_set(obj, rb_intern("@vid"), ID2SYM(RNODE_CONST(node)->nd_vid));
|
|
192
126
|
|
|
193
127
|
return obj;
|
|
194
128
|
}
|
|
195
129
|
|
|
196
|
-
static VALUE
|
|
197
|
-
constant_node_vid_get(VALUE self)
|
|
198
|
-
{
|
|
199
|
-
return rb_ivar_get(self, symbol("vid"));
|
|
200
|
-
}
|
|
201
|
-
|
|
202
130
|
static VALUE
|
|
203
131
|
constant_declaration_node_new(const NODE *node)
|
|
204
132
|
{
|
|
205
133
|
VALUE obj = rb_class_new_instance(0, 0, rb_cConstantDeclarationNode);
|
|
206
134
|
|
|
207
|
-
rb_ivar_set(obj,
|
|
208
|
-
rb_ivar_set(obj,
|
|
209
|
-
rb_ivar_set(obj,
|
|
135
|
+
rb_ivar_set(obj, rb_intern("@vid"), ID2SYM(RNODE_CDECL(node)->nd_vid));
|
|
136
|
+
rb_ivar_set(obj, rb_intern("@else"), ast_to_node_instance(RNODE_CDECL(node)->nd_else));
|
|
137
|
+
rb_ivar_set(obj, rb_intern("@value"), ast_to_node_instance(RNODE_CDECL(node)->nd_value));
|
|
210
138
|
|
|
211
139
|
return obj;
|
|
212
140
|
}
|
|
213
141
|
|
|
214
|
-
static VALUE
|
|
215
|
-
constant_declaration_node_vid_get(VALUE self)
|
|
216
|
-
{
|
|
217
|
-
return rb_ivar_get(self, symbol("vid"));
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
static VALUE
|
|
221
|
-
constant_declaration_node_else_get(VALUE self)
|
|
222
|
-
{
|
|
223
|
-
return rb_ivar_get(self, symbol("else"));
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
static VALUE
|
|
227
|
-
constant_declaration_node_value_get(VALUE self)
|
|
228
|
-
{
|
|
229
|
-
return rb_ivar_get(self, symbol("value"));
|
|
230
|
-
}
|
|
231
|
-
|
|
232
142
|
static VALUE
|
|
233
143
|
node_literal_to_hash(const NODE *node)
|
|
234
144
|
{
|
|
@@ -271,31 +181,13 @@ class_node_new(const NODE *node)
|
|
|
271
181
|
{
|
|
272
182
|
VALUE obj = rb_class_new_instance(0, 0, rb_cClassNode);
|
|
273
183
|
|
|
274
|
-
rb_ivar_set(obj,
|
|
275
|
-
rb_ivar_set(obj,
|
|
276
|
-
rb_ivar_set(obj,
|
|
184
|
+
rb_ivar_set(obj, rb_intern("@cpath"), ast_to_node_instance(RNODE_CLASS(node)->nd_cpath));
|
|
185
|
+
rb_ivar_set(obj, rb_intern("@super"), ast_to_node_instance(RNODE_CLASS(node)->nd_super));
|
|
186
|
+
rb_ivar_set(obj, rb_intern("@body"), ast_to_node_instance(RNODE_CLASS(node)->nd_body));
|
|
277
187
|
|
|
278
188
|
return obj;
|
|
279
189
|
}
|
|
280
190
|
|
|
281
|
-
static VALUE
|
|
282
|
-
class_node_cpath_get(VALUE self)
|
|
283
|
-
{
|
|
284
|
-
return rb_ivar_get(self, symbol("cpath"));
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
static VALUE
|
|
288
|
-
class_node_super_get(VALUE self)
|
|
289
|
-
{
|
|
290
|
-
return rb_ivar_get(self, symbol("super"));
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
static VALUE
|
|
294
|
-
class_node_body_get(VALUE self)
|
|
295
|
-
{
|
|
296
|
-
return rb_ivar_get(self, symbol("body"));
|
|
297
|
-
}
|
|
298
|
-
|
|
299
191
|
static VALUE
|
|
300
192
|
module_node_new(const NODE *node)
|
|
301
193
|
{
|
|
@@ -313,24 +205,12 @@ colon2_node_new(const NODE *node)
|
|
|
313
205
|
{
|
|
314
206
|
VALUE obj = rb_class_new_instance(0, 0, rb_cColon2Node);
|
|
315
207
|
|
|
316
|
-
rb_ivar_set(obj,
|
|
317
|
-
rb_ivar_set(obj,
|
|
208
|
+
rb_ivar_set(obj, rb_intern("@mid"), ID2SYM(RNODE_COLON2(node)->nd_mid));
|
|
209
|
+
rb_ivar_set(obj, rb_intern("@head"), ast_to_node_instance(RNODE_COLON2(node)->nd_head));
|
|
318
210
|
|
|
319
211
|
return obj;
|
|
320
212
|
}
|
|
321
213
|
|
|
322
|
-
static VALUE
|
|
323
|
-
colon2_node_mid_get(VALUE self)
|
|
324
|
-
{
|
|
325
|
-
return rb_ivar_get(self, symbol("mid"));
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
static VALUE
|
|
329
|
-
colon2_node_head_get(VALUE self)
|
|
330
|
-
{
|
|
331
|
-
return rb_ivar_get(self, symbol("head"));
|
|
332
|
-
}
|
|
333
|
-
|
|
334
214
|
static VALUE
|
|
335
215
|
colon3_node_new(const NODE *node)
|
|
336
216
|
{
|
|
@@ -341,28 +221,16 @@ colon3_node_new(const NODE *node)
|
|
|
341
221
|
return obj;
|
|
342
222
|
}
|
|
343
223
|
|
|
344
|
-
static VALUE
|
|
345
|
-
colon3_node_mid_get(VALUE self)
|
|
346
|
-
{
|
|
347
|
-
return rb_ivar_get(self, rb_intern("@mid"));
|
|
348
|
-
}
|
|
349
|
-
|
|
350
224
|
static VALUE
|
|
351
225
|
begin_node_new(const NODE *node)
|
|
352
226
|
{
|
|
353
227
|
VALUE obj = rb_class_new_instance(0, 0, rb_cBeginNode);
|
|
354
228
|
|
|
355
|
-
rb_ivar_set(obj,
|
|
229
|
+
rb_ivar_set(obj, rb_intern("@body"), ast_to_node_instance(RNODE_BEGIN(node)->nd_body));
|
|
356
230
|
|
|
357
231
|
return obj;
|
|
358
232
|
}
|
|
359
233
|
|
|
360
|
-
static VALUE
|
|
361
|
-
begin_node_body_get(VALUE self)
|
|
362
|
-
{
|
|
363
|
-
return rb_ivar_get(self, symbol("body"));
|
|
364
|
-
}
|
|
365
|
-
|
|
366
234
|
static VALUE
|
|
367
235
|
args_ainfo_to_hash(const struct rb_args_info ainfo)
|
|
368
236
|
{
|
|
@@ -373,9 +241,11 @@ args_ainfo_to_hash(const struct rb_args_info ainfo)
|
|
|
373
241
|
rb_hash_aset(result, symbol("pre_init"), ast_to_node_instance(ainfo.pre_init));
|
|
374
242
|
rb_hash_aset(result, symbol("post_args_num"), INT2NUM(ainfo.post_args_num));
|
|
375
243
|
rb_hash_aset(result, symbol("post_init"), ast_to_node_instance(ainfo.post_init));
|
|
376
|
-
|
|
377
|
-
rb_hash_aset(result, symbol("
|
|
378
|
-
rb_hash_aset(result, symbol("
|
|
244
|
+
|
|
245
|
+
rb_hash_aset(result, symbol("first_post_arg"), ainfo.first_post_arg ? ID2SYM(ainfo.first_post_arg) : Qnil);
|
|
246
|
+
rb_hash_aset(result, symbol("rest_arg"), ainfo.rest_arg ? ID2SYM(ainfo.rest_arg) : Qnil);
|
|
247
|
+
rb_hash_aset(result, symbol("block_arg"), ainfo.block_arg ? ID2SYM(ainfo.block_arg) : Qnil);
|
|
248
|
+
|
|
379
249
|
rb_hash_aset(result, symbol("opt_args"), ast_to_node_instance((const NODE *)(ainfo.opt_args)));
|
|
380
250
|
rb_hash_aset(result, symbol("kw_args"), ast_to_node_instance((const NODE *)(ainfo.kw_args)));
|
|
381
251
|
rb_hash_aset(result, symbol("kw_rest_arg"), ast_to_node_instance(ainfo.kw_rest_arg));
|
|
@@ -389,17 +259,11 @@ arguments_node_new(const NODE *node)
|
|
|
389
259
|
VALUE obj = rb_class_new_instance(0, 0, rb_cArgumentsNode);
|
|
390
260
|
VALUE ainfo_hash = args_ainfo_to_hash(RNODE_ARGS(node)->nd_ainfo);
|
|
391
261
|
|
|
392
|
-
rb_ivar_set(obj,
|
|
262
|
+
rb_ivar_set(obj, rb_intern("@ainfo"), ainfo_hash);
|
|
393
263
|
|
|
394
264
|
return obj;
|
|
395
265
|
}
|
|
396
266
|
|
|
397
|
-
static VALUE
|
|
398
|
-
arguments_node_ainfo_get(VALUE self)
|
|
399
|
-
{
|
|
400
|
-
return rb_ivar_get(self, symbol("ainfo"));
|
|
401
|
-
}
|
|
402
|
-
|
|
403
267
|
static VALUE
|
|
404
268
|
self_node_new(const NODE *node)
|
|
405
269
|
{
|
|
@@ -419,6 +283,10 @@ ast_to_node_instance(const NODE *node)
|
|
|
419
283
|
return Qnil;
|
|
420
284
|
}
|
|
421
285
|
|
|
286
|
+
if (node == (NODE *)-1) {
|
|
287
|
+
return Qnil;
|
|
288
|
+
}
|
|
289
|
+
|
|
422
290
|
type = nd_type(node);
|
|
423
291
|
|
|
424
292
|
switch (type) {
|
|
@@ -674,38 +542,22 @@ Init_kanayago(void)
|
|
|
674
542
|
Init_StringNode(rb_mKanayago);
|
|
675
543
|
|
|
676
544
|
rb_cConstantNode = rb_define_class_under(rb_mKanayago, "ConstantNode", rb_cObject);
|
|
677
|
-
rb_define_method(rb_cConstantNode, "vid", constant_node_vid_get, 0);
|
|
678
545
|
|
|
679
546
|
rb_cConstantDeclarationNode = rb_define_class_under(rb_mKanayago, "ConstantDeclarationNode", rb_cObject);
|
|
680
|
-
rb_define_method(rb_cConstantDeclarationNode, "vid", constant_declaration_node_vid_get, 0);
|
|
681
|
-
rb_define_method(rb_cConstantDeclarationNode, "else", constant_declaration_node_else_get, 0);
|
|
682
|
-
rb_define_method(rb_cConstantDeclarationNode, "value", constant_declaration_node_value_get, 0);
|
|
683
547
|
|
|
684
548
|
rb_cDefinitionNode = rb_define_class_under(rb_mKanayago, "DefinitionNode", rb_cObject);
|
|
685
|
-
rb_define_method(rb_cDefinitionNode, "mid", definition_node_mid_get, 0);
|
|
686
|
-
rb_define_method(rb_cDefinitionNode, "defn", definition_node_defn_get, 0);
|
|
687
549
|
|
|
688
550
|
rb_cOperatorCallNode = rb_define_class_under(rb_mKanayago, "OperatorCallNode", rb_cObject);
|
|
689
|
-
rb_define_method(rb_cOperatorCallNode, "recv", operator_call_node_recv_get, 0);
|
|
690
|
-
rb_define_method(rb_cOperatorCallNode, "mid", operator_call_node_mid_get, 0);
|
|
691
|
-
rb_define_method(rb_cOperatorCallNode, "args", operator_call_node_args_get, 0);
|
|
692
551
|
|
|
693
552
|
rb_cListNode = rb_define_class_under(rb_mKanayago, "ListNode", rb_cObject);
|
|
694
553
|
|
|
695
554
|
rb_cArgumentsNode = rb_define_class_under(rb_mKanayago, "ArgumentsNode", rb_cObject);
|
|
696
|
-
rb_define_method(rb_cArgumentsNode, "ainfo", arguments_node_ainfo_get, 0);
|
|
697
555
|
|
|
698
556
|
rb_cCallNode = rb_define_class_under(rb_mKanayago, "CallNode", rb_cObject);
|
|
699
|
-
rb_define_method(rb_cCallNode, "recv", call_node_recv_get, 0);
|
|
700
|
-
rb_define_method(rb_cCallNode, "mid", call_node_mid_get, 0);
|
|
701
|
-
rb_define_method(rb_cCallNode, "args", call_node_args_get, 0);
|
|
702
557
|
|
|
703
558
|
rb_cFunctionCallNode = rb_define_class_under(rb_mKanayago, "FunctionCallNode", rb_cObject);
|
|
704
|
-
rb_define_method(rb_cFunctionCallNode, "mid", function_call_node_mid_get, 0);
|
|
705
|
-
rb_define_method(rb_cFunctionCallNode, "args", function_call_node_args_get, 0);
|
|
706
559
|
|
|
707
560
|
rb_cVariableCallNode = rb_define_class_under(rb_mKanayago, "VariableCallNode", rb_cObject);
|
|
708
|
-
rb_define_method(rb_cVariableCallNode, "mid", variable_call_node_mid_get, 0);
|
|
709
561
|
|
|
710
562
|
// For Statement Node(e.g. Kanayago::IfStatementNode)
|
|
711
563
|
Init_StatementNode(rb_mKanayago);
|
|
@@ -713,21 +565,14 @@ Init_kanayago(void)
|
|
|
713
565
|
rb_cBlockNode = rb_define_class_under(rb_mKanayago, "BlockNode", rb_cArray);
|
|
714
566
|
|
|
715
567
|
rb_cBeginNode = rb_define_class_under(rb_mKanayago, "BeginNode", rb_cObject);
|
|
716
|
-
rb_define_method(rb_cBeginNode, "body", begin_node_body_get, 0);
|
|
717
568
|
|
|
718
569
|
rb_cClassNode = rb_define_class_under(rb_mKanayago, "ClassNode", rb_cObject);
|
|
719
|
-
rb_define_method(rb_cClassNode, "cpath", class_node_cpath_get, 0);
|
|
720
|
-
rb_define_method(rb_cClassNode, "super", class_node_super_get, 0);
|
|
721
|
-
rb_define_method(rb_cClassNode, "body", class_node_body_get, 0);
|
|
722
570
|
|
|
723
571
|
rb_cModuleNode = rb_define_class_under(rb_mKanayago, "ModuleNode", rb_cObject);
|
|
724
572
|
|
|
725
573
|
rb_cColon2Node = rb_define_class_under(rb_mKanayago, "Colon2Node", rb_cObject);
|
|
726
|
-
rb_define_method(rb_cColon2Node, "mid", colon2_node_mid_get, 0);
|
|
727
|
-
rb_define_method(rb_cColon2Node, "head", colon2_node_head_get, 0);
|
|
728
574
|
|
|
729
575
|
rb_cColon3Node = rb_define_class_under(rb_mKanayago, "Colon3Node", rb_cObject);
|
|
730
|
-
rb_define_method(rb_cColon3Node, "mid", colon3_node_mid_get, 0);
|
|
731
576
|
|
|
732
577
|
// For Variable Node(e.g. Kanayago::LocalVariableNode)
|
|
733
578
|
Init_VariableNode(rb_mKanayago);
|
data/ext/kanayago/scope_node.c
CHANGED
|
@@ -7,28 +7,14 @@ scope_node_new(const NODE *node)
|
|
|
7
7
|
{
|
|
8
8
|
VALUE result = rb_class_new_instance(0, 0, rb_cScopeNode);
|
|
9
9
|
|
|
10
|
-
rb_ivar_set(result,
|
|
11
|
-
rb_ivar_set(result,
|
|
10
|
+
rb_ivar_set(result, rb_intern("@args"), ast_to_node_instance((const NODE *)(RNODE_SCOPE(node)->nd_args)));
|
|
11
|
+
rb_ivar_set(result, rb_intern("@body"), ast_to_node_instance(RNODE_SCOPE(node)->nd_body));
|
|
12
12
|
|
|
13
13
|
return result;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
static VALUE
|
|
17
|
-
scope_node_args_get(VALUE self)
|
|
18
|
-
{
|
|
19
|
-
return rb_ivar_get(self, symbol("args"));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
static VALUE
|
|
23
|
-
scope_node_body_get(VALUE self)
|
|
24
|
-
{
|
|
25
|
-
return rb_ivar_get(self, symbol("body"));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
16
|
void
|
|
29
17
|
Init_ScopeNode(VALUE module)
|
|
30
18
|
{
|
|
31
19
|
rb_cScopeNode = rb_define_class_under(module, "ScopeNode", rb_cObject);
|
|
32
|
-
rb_define_method(rb_cScopeNode, "args", scope_node_args_get, 0);
|
|
33
|
-
rb_define_method(rb_cScopeNode, "body", scope_node_body_get, 0);
|
|
34
20
|
}
|
|
@@ -21,8 +21,9 @@ VALUE
|
|
|
21
21
|
dynamic_variable_node_new(const NODE *node)
|
|
22
22
|
{
|
|
23
23
|
VALUE obj = rb_class_new_instance(0, 0, rb_cDynamicVariableNode);
|
|
24
|
+
ID vid = RNODE_DVAR(node)->nd_vid;
|
|
24
25
|
|
|
25
|
-
rb_ivar_set(obj, rb_intern("@vid"), ID2SYM(
|
|
26
|
+
rb_ivar_set(obj, rb_intern("@vid"), vid ? ID2SYM(vid) : Qnil);
|
|
26
27
|
|
|
27
28
|
return obj;
|
|
28
29
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Kanayago
|
|
4
|
+
class OperatorCallNode
|
|
5
|
+
attr_reader :recv, :mid, :args
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
class CallNode
|
|
9
|
+
attr_reader :recv, :mid, :args
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class FunctionCallNode
|
|
13
|
+
attr_reader :mid, :args
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class VariableCallNode
|
|
17
|
+
attr_reader :mid
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -61,10 +61,22 @@ module Kanayago
|
|
|
61
61
|
attr_reader :id, :value
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
+
class DefinitionNode
|
|
65
|
+
attr_reader :mid, :defn
|
|
66
|
+
end
|
|
67
|
+
|
|
64
68
|
class SingletonDefinitionNode
|
|
65
69
|
attr_reader :recv, :mid, :defn
|
|
66
70
|
end
|
|
67
71
|
|
|
72
|
+
class ClassNode
|
|
73
|
+
attr_reader :cpath, :super, :body
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
class ModuleNode
|
|
77
|
+
attr_reader :cpath, :super, :body
|
|
78
|
+
end
|
|
79
|
+
|
|
68
80
|
class SingletonClassNode
|
|
69
81
|
attr_reader :recv, :body
|
|
70
82
|
end
|
|
@@ -122,6 +134,10 @@ module Kanayago
|
|
|
122
134
|
attr_reader :body, :iter
|
|
123
135
|
end
|
|
124
136
|
|
|
137
|
+
class BeginNode
|
|
138
|
+
attr_reader :body
|
|
139
|
+
end
|
|
140
|
+
|
|
125
141
|
class EnsureNode
|
|
126
142
|
attr_reader :head, :ensr
|
|
127
143
|
end
|
data/lib/kanayago/version.rb
CHANGED
data/lib/kanayago.rb
CHANGED
|
@@ -8,26 +8,13 @@ require_relative 'kanayago/string_node'
|
|
|
8
8
|
require_relative 'kanayago/statement_node'
|
|
9
9
|
require_relative 'kanayago/variable_node'
|
|
10
10
|
require_relative 'kanayago/pattern_node'
|
|
11
|
+
require_relative 'kanayago/call_node'
|
|
12
|
+
require_relative 'kanayago/scope_node'
|
|
13
|
+
require_relative 'kanayago/constant_node'
|
|
11
14
|
|
|
12
15
|
# Parse Ruby code with Ruby's Parser(Universal Parser)
|
|
13
16
|
module Kanayago
|
|
14
17
|
def self.parse(source)
|
|
15
18
|
kanayago_parse(source)
|
|
16
19
|
end
|
|
17
|
-
|
|
18
|
-
class SelfNode
|
|
19
|
-
attr_reader :state
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
class ModuleNode
|
|
23
|
-
attr_reader :cpath, :body
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
class VariableCallNode
|
|
27
|
-
attr_reader :mid
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
class Colon3Node
|
|
31
|
-
attr_reader :mid
|
|
32
|
-
end
|
|
33
20
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kanayago
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- S-H-GAMELINKS
|
|
@@ -20,6 +20,7 @@ files:
|
|
|
20
20
|
- ".rubocop.yml"
|
|
21
21
|
- ".rubocop_todo.yml"
|
|
22
22
|
- ".ruby-version"
|
|
23
|
+
- CHANGELOG.md
|
|
23
24
|
- LICENSE.txt
|
|
24
25
|
- README.md
|
|
25
26
|
- Rakefile
|
|
@@ -39,8 +40,11 @@ files:
|
|
|
39
40
|
- ext/kanayago/variable_node.c
|
|
40
41
|
- ext/kanayago/variable_node.h
|
|
41
42
|
- lib/kanayago.rb
|
|
43
|
+
- lib/kanayago/call_node.rb
|
|
44
|
+
- lib/kanayago/constant_node.rb
|
|
42
45
|
- lib/kanayago/literal_node.rb
|
|
43
46
|
- lib/kanayago/pattern_node.rb
|
|
47
|
+
- lib/kanayago/scope_node.rb
|
|
44
48
|
- lib/kanayago/statement_node.rb
|
|
45
49
|
- lib/kanayago/string_node.rb
|
|
46
50
|
- lib/kanayago/variable_node.rb
|