summaryrefslogtreecommitdiff
path: root/ast.c
diff options
context:
space:
mode:
authoryui-knk <[email protected]>2024-07-10 22:28:22 +0900
committerYuichiro Kaneko <[email protected]>2024-07-23 12:36:00 +0900
commitf23485a8d693cb69fd7b84c1ab93cb4198ecfe4a ()
tree12b99fc07f809edbd9ac32f3951a07f46e30a8cd /ast.c
parent5617fec1f81d0f05563b70fd04e9494896f6abc7 (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--ast.c123
1 files changed, 123 insertions, 0 deletions
@@ -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);
}