@@ -32,6 +32,8 @@ def initialize(src, path)
32
32
33
33
private
34
34
35
+ alias character column
36
+
35
37
attr_reader :path
36
38
37
39
def lineno
@@ -40,13 +42,13 @@ def lineno
40
42
end
41
43
42
44
def on_const ( name )
43
- Constant . new ( namespaces : [ ] , name : name , value : nil , lineno : lineno , path : path ) . tap do |c |
45
+ build_node ( Constant , namespaces : [ ] , name : name , value : nil ) . tap do |c |
44
46
@current_constants . push ( c )
45
47
end
46
48
end
47
49
48
50
def on_int ( value )
49
- LiteralValue . new ( value : value . to_i , lineno : lineno , path : path )
51
+ build_node ( LiteralValue , value : value . to_i )
50
52
end
51
53
52
54
def on_stmts_add ( *args )
@@ -62,19 +64,23 @@ def on_assign(left, right)
62
64
63
65
def on_module ( constant , children )
64
66
cn = children . select { |child | child . instance_of? ( Constant ) || child . instance_of? ( Module ) || child . instance_of? ( Class ) }
65
- Module . new ( constant : constant , lineno : lineno , path : path , children : cn ) . tap do |m |
67
+ build_node ( Module , constant : constant , children : cn ) . tap do |m |
66
68
result . modules << m
67
69
cn . each { |child | child . unshift_namespace ( m ) }
68
70
end
69
71
end
70
72
71
73
def on_class ( constant , superclass , children )
72
74
cn = children . select { |child | child . instance_of? ( Constant ) || child . instance_of? ( Module ) || child . instance_of? ( Class ) }
73
- Class . new ( constant : constant , superclass : superclass , lineno : lineno , path : path , children : cn ) . tap do |c |
75
+ build_node ( Class , constant : constant , superclass : superclass , children : cn ) . tap do |c |
74
76
result . classes << c
75
77
cn . each { |child | child . unshift_namespace ( c ) }
76
78
end
77
79
end
80
+
81
+ def build_node ( klass , **args )
82
+ klass . new ( { lineno : lineno , character : character , path : path } . merge ( args ) )
83
+ end
78
84
end
79
85
end
80
86
end
0 commit comments