diff options
author | yui-knk <[email protected]> | 2024-07-10 22:28:22 +0900 |
---|---|---|
committer | Yuichiro Kaneko <[email protected]> | 2024-07-23 12:36:00 +0900 |
commit | f23485a8d693cb69fd7b84c1ab93cb4198ecfe4a () | |
tree | 12b99fc07f809edbd9ac32f3951a07f46e30a8cd | |
parent | 5617fec1f81d0f05563b70fd04e9494896f6abc7 (diff) |
[Feature #20624] Enhance `RubyVM::AbstractSyntaxTree::Node#locations`
This commit introduce `RubyVM::AbstractSyntaxTree::Node#locations` method and `RubyVM::AbstractSyntaxTree::Location` class. Ruby AST node will hold multiple locations information. `RubyVM::AbstractSyntaxTree::Node#locations` provides a way to access these locations information. `RubyVM::AbstractSyntaxTree::Location` is a class which holds these location information: * `#first_lineno` * `#first_column` * `#last_lineno` * `#last_column`
Notes: Merged: https://.com/ruby/ruby/pull/11226
-rw-r--r-- | NEWS.md | 7 | ||||
-rw-r--r-- | ast.c | 123 | ||||
-rw-r--r-- | ast.rb | 57 | ||||
-rw-r--r-- | test/ruby/test_ast.rb | 19 |
4 files changed, 206 insertions, 0 deletions
@@ -44,6 +44,12 @@ Note: We're only listing outstanding class updates. * Range#size now raises TypeError if the range is not iterable. [[Misc #18984]] ## Stdlib updates * Tempfile @@ -160,3 +166,4 @@ See releases like [ Releases of Logger](https://.com/ruby/log [Feature #20429]: https://bugs.ruby-lang.org/issues/20429 [Feature #20443]: https://bugs.ruby-lang.org/issues/20443 [Feature #20497]: https://bugs.ruby-lang.org/issues/20497 @@ -14,6 +14,7 @@ static VALUE rb_mAST; static VALUE rb_cNode; struct ASTNodeData { VALUE ast_value; @@ -43,6 +44,32 @@ static const rb_data_type_t rb_node_type = { RUBY_TYPED_FREE_IMMEDIATELY, }; static VALUE rb_ast_node_alloc(VALUE klass); static void @@ -721,6 +748,45 @@ ast_node_children(rb_execution_context_t *ec, VALUE self) } static VALUE ast_node_first_lineno(rb_execution_context_t *ec, VALUE self) { struct ASTNodeData *data; @@ -823,6 +889,61 @@ ast_node_script_lines(rb_execution_context_t *ec, VALUE self) return rb_parser_build_script_lines_from(ret); } #include "ast.rbinc" void @@ -830,5 +951,7 @@ Init_ast(void) { rb_mAST = rb_define_module_under(rb_cRubyVM, "AbstractSyntaxTree"); rb_cNode = rb_define_class_under(rb_mAST, "Node", rb_cObject); rb_undef_alloc_func(rb_cNode); } @@ -272,5 +272,62 @@ module RubyVM::AbstractSyntaxTree nil end end end end @@ -1297,6 +1297,13 @@ dummy end; end private def assert_error_tolerant(src, expected, keep_tokens: false) @@ -1316,4 +1323,16 @@ dummy assert_equal(expected, str) node end end |