steep 1.0.0 → 1.1.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby-windows.yml +34 -0
- data/.github/workflows/ruby.yml +7 -2
- data/.gitignore +1 -0
- data/CHANGELOG.md +59 -0
- data/Gemfile +7 -4
- data/Gemfile.lock +17 -21
- data/Gemfile.steep +3 -0
- data/Gemfile.steep.lock +49 -0
- data/Rakefile +5 -0
- data/Steepfile +6 -1
- data/bin/setup +2 -0
- data/bin/steep +19 -0
- data/lib/steep/ast/builtin.rb +2 -2
- data/lib/steep/ast/types/factory.rb +7 -3
- data/lib/steep/ast/types/proc.rb +2 -0
- data/lib/steep/cli.rb +3 -1
- data/lib/steep/diagnostic/ruby.rb +50 -4
- data/lib/steep/diagnostic/signature.rb +18 -0
- data/lib/steep/drivers/check.rb +3 -3
- data/lib/steep/drivers/watch.rb +3 -1
- data/lib/steep/method_name.rb +9 -3
- data/lib/steep/node_helper.rb +49 -0
- data/lib/steep/path_helper.rb +22 -0
- data/lib/steep/project.rb +3 -15
- data/lib/steep/server/base_worker.rb +1 -0
- data/lib/steep/server/change_buffer.rb +1 -1
- data/lib/steep/server/interaction_worker.rb +3 -5
- data/lib/steep/server/master.rb +61 -45
- data/lib/steep/server/type_check_worker.rb +10 -25
- data/lib/steep/services/completion_provider.rb +25 -18
- data/lib/steep/services/goto_service.rb +2 -4
- data/lib/steep/services/hover_provider/rbs.rb +1 -1
- data/lib/steep/services/hover_provider/ruby.rb +30 -12
- data/lib/steep/services/stats_calculator.rb +0 -1
- data/lib/steep/services/type_check_service.rb +15 -12
- data/lib/steep/shims/symbol_start_with.rb +18 -0
- data/lib/steep/signature/validator.rb +25 -1
- data/lib/steep/source.rb +1 -1
- data/lib/steep/subtyping/check.rb +0 -3
- data/lib/steep/subtyping/constraints.rb +43 -14
- data/lib/steep/type_construction.rb +721 -764
- data/lib/steep/type_inference/constant_env.rb +0 -2
- data/lib/steep/type_inference/context.rb +23 -17
- data/lib/steep/type_inference/logic_type_interpreter.rb +210 -117
- data/lib/steep/type_inference/method_call.rb +80 -6
- data/lib/steep/type_inference/multiple_assignment.rb +189 -0
- data/lib/steep/type_inference/send_args.rb +1 -2
- data/lib/steep/type_inference/type_env.rb +273 -116
- data/lib/steep/type_inference/type_env_builder.rb +138 -0
- data/lib/steep/typing.rb +2 -0
- data/lib/steep/version.rb +1 -1
- data/lib/steep.rb +7 -5
- data/rbs_collection.steep.lock.yaml +112 -0
- data/rbs_collection.steep.yaml +19 -0
- data/sample/sig/conference.rbs +8 -0
- data/sig/shims/parser/source/map.rbs +146 -0
- data/sig/shims/parser/source/range.rbs +237 -0
- data/sig/shims/parser.rbs +17 -0
- data/sig/steep/ast/annotation/collection.rbs +75 -0
- data/sig/steep/ast/annotation.rbs +126 -0
- data/sig/steep/ast/builtin.rbs +69 -0
- data/sig/steep/ast/type_params.rbs +11 -0
- data/sig/steep/ast/types/any.rbs +29 -0
- data/sig/steep/ast/types/boolean.rbs +31 -0
- data/sig/steep/ast/types/bot.rbs +29 -0
- data/sig/steep/ast/types/class.rbs +29 -0
- data/sig/steep/ast/types/factory.rbs +76 -0
- data/sig/steep/ast/types/helper.rbs +19 -0
- data/sig/steep/ast/types/instance.rbs +29 -0
- data/sig/steep/ast/types/intersection.rbs +35 -0
- data/sig/steep/ast/types/literal.rbs +33 -0
- data/sig/steep/ast/types/logic.rbs +78 -0
- data/sig/steep/ast/types/name.rbs +71 -0
- data/sig/steep/ast/types/nil.rbs +31 -0
- data/sig/steep/ast/types/proc.rbs +46 -0
- data/sig/steep/ast/types/record.rbs +38 -0
- data/sig/steep/ast/types/self.rbs +29 -0
- data/sig/steep/ast/types/top.rbs +29 -0
- data/sig/steep/ast/types/tuple.rbs +34 -0
- data/sig/steep/ast/types/union.rbs +38 -0
- data/sig/steep/ast/types/var.rbs +37 -0
- data/sig/steep/ast/types/void.rbs +29 -0
- data/sig/steep/ast/types.rbs +37 -0
- data/sig/steep/diagnostic/deprecated/unknown_constant_assigned.rbs +15 -0
- data/sig/steep/diagnostic/helper.rbs +9 -0
- data/sig/steep/diagnostic/lsp_formatter.rbs +29 -0
- data/sig/steep/diagnostic/ruby.rbs +494 -0
- data/sig/steep/diagnostic/signature.rbs +215 -0
- data/sig/steep/interface/block.rbs +35 -0
- data/sig/steep/interface/function.rbs +253 -0
- data/sig/steep/interface/interface.rbs +23 -0
- data/sig/steep/interface/method_type.rbs +55 -0
- data/sig/steep/interface/substitution.rbs +53 -0
- data/sig/steep/interface/type_param.rbs +35 -0
- data/sig/steep/method_name.rbs +26 -0
- data/sig/steep/module_helper.rbs +7 -0
- data/sig/steep/node_helper.rbs +11 -0
- data/sig/steep/project/dsl.rbs +94 -0
- data/sig/steep/project/options.rbs +15 -0
- data/sig/steep/project/pattern.rbs +25 -0
- data/sig/steep/project/target.rbs +25 -0
- data/sig/steep/project.rbs +19 -0
- data/sig/steep/services/completion_provider.rbs +123 -0
- data/sig/steep/services/content_change.rbs +35 -0
- data/sig/steep/services/file_loader.rbs +13 -0
- data/sig/steep/services/goto_service.rbs +45 -0
- data/sig/steep/services/hover_provider/rbs.rbs +21 -0
- data/sig/steep/services/hover_provider/ruby.rbs +109 -0
- data/sig/steep/services/hover_provider/singleton_methods.rbs +11 -0
- data/sig/steep/services/path_assignment.rbs +21 -0
- data/sig/steep/services/signature_service.rbs +91 -0
- data/sig/steep/services/stats_calculator.rbs +17 -0
- data/sig/steep/services/type_check_service.rbs +93 -0
- data/sig/steep/source.rbs +55 -0
- data/sig/steep/subtyping/cache.rbs +17 -0
- data/sig/steep/subtyping/check.rbs +93 -0
- data/sig/steep/subtyping/constraints.rbs +111 -0
- data/sig/steep/subtyping/relation.rbs +51 -0
- data/sig/steep/subtyping/result.rbs +157 -0
- data/sig/steep/subtyping/variable_variance.rbs +23 -0
- data/sig/steep/type_construction.rbs +285 -0
- data/sig/steep/type_inference/block_params.rbs +52 -0
- data/sig/steep/type_inference/constant_env.rbs +27 -0
- data/sig/steep/type_inference/context.rbs +137 -0
- data/sig/steep/type_inference/logic_type_interpreter.rbs +72 -0
- data/sig/steep/type_inference/method_call.rbs +124 -0
- data/sig/steep/type_inference/method_params.rbs +104 -0
- data/sig/steep/type_inference/multiple_assignment.rbs +76 -0
- data/sig/steep/type_inference/type_env.rbs +158 -0
- data/sig/steep/type_inference/type_env_builder.rbs +77 -0
- data/sig/steep/typing.rbs +68 -0
- data/sig/steep.rbs +31 -0
- data/smoke/class/f.rb +1 -0
- data/smoke/class/test_expectations.yml +2 -2
- data/smoke/diagnostics/test_expectations.yml +4 -2
- data/smoke/regression/lambda.rb +3 -0
- data/smoke/regression/test_expectations.yml +12 -0
- data/steep.gemspec +1 -1
- metadata +95 -9
- data/lib/steep/subtyping/variable_occurrence.rb +0 -51
- data/lib/steep/type_inference/local_variable_type_env.rb +0 -249
- data/lib/steep/type_inference/logic.rb +0 -161
@@ -0,0 +1,138 @@
|
|
1
|
+
module Steep
|
2
|
+
module TypeInference
|
3
|
+
class TypeEnvBuilder
|
4
|
+
module Command
|
5
|
+
class AnnotationsBase
|
6
|
+
attr_reader :annotations
|
7
|
+
|
8
|
+
def initialize(annotations)
|
9
|
+
@annotations = annotations
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class RBSBase
|
14
|
+
attr_reader :factory
|
15
|
+
|
16
|
+
attr_reader :environment
|
17
|
+
|
18
|
+
def initialize(factory)
|
19
|
+
@factory = factory
|
20
|
+
@environment = factory.env
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class ImportLocalVariableAnnotations < AnnotationsBase
|
25
|
+
attr_reader :on_duplicate
|
26
|
+
|
27
|
+
def initialize(annotations)
|
28
|
+
super
|
29
|
+
@merge = false
|
30
|
+
@on_duplicate = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def merge!(merge = true)
|
34
|
+
@merge = merge
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
def on_duplicate!(&block)
|
39
|
+
@on_duplicate = block
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
def call(env)
|
44
|
+
local_variable_types = annotations.var_type_annotations.each.with_object({}) do |pair, hash|
|
45
|
+
name, annotation = pair
|
46
|
+
annotation_type = annotations.absolute_type(annotation.type) || annotation.type
|
47
|
+
|
48
|
+
if current_type = env[name]
|
49
|
+
on_duplicate&.call(name, current_type, annotation_type)
|
50
|
+
hash[name] = [annotation_type, annotation_type]
|
51
|
+
else
|
52
|
+
hash[name] = [annotation_type, annotation_type]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
if @merge
|
57
|
+
env.merge(local_variable_types: local_variable_types)
|
58
|
+
else
|
59
|
+
env.update(local_variable_types: local_variable_types)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class ImportInstanceVariableAnnotations < AnnotationsBase
|
65
|
+
def call(env)
|
66
|
+
ivar_types = annotations.ivar_type_annotations.transform_values do |annotation|
|
67
|
+
annotations.absolute_type(annotation.type) || annotation.type
|
68
|
+
end
|
69
|
+
|
70
|
+
if @merge
|
71
|
+
env.merge(instance_variable_types: ivar_types)
|
72
|
+
else
|
73
|
+
env.update(instance_variable_types: ivar_types)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def merge!(merge = true)
|
78
|
+
@merge = merge
|
79
|
+
self
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class ImportGlobalDeclarations < RBSBase
|
84
|
+
def call(env)
|
85
|
+
global_types = environment.global_decls.transform_values do |decl|
|
86
|
+
factory.type(decl.decl.type)
|
87
|
+
end
|
88
|
+
|
89
|
+
env.update(global_types: global_types)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class ImportInstanceVariableDefinition
|
94
|
+
attr_reader :definition
|
95
|
+
|
96
|
+
attr_reader :factory
|
97
|
+
|
98
|
+
def initialize(definition, factory)
|
99
|
+
@definition = definition
|
100
|
+
@factory = factory
|
101
|
+
end
|
102
|
+
|
103
|
+
def call(env)
|
104
|
+
return env unless definition
|
105
|
+
|
106
|
+
instance_variable_types = definition.instance_variables.transform_values do |ivar|
|
107
|
+
factory.type(ivar.type)
|
108
|
+
end
|
109
|
+
|
110
|
+
env.update(instance_variable_types: instance_variable_types)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
class ImportConstantAnnotations < AnnotationsBase
|
115
|
+
def call(env)
|
116
|
+
constant_types = annotations.const_type_annotations.transform_values do |const|
|
117
|
+
annotations.absolute_type(const.type) || const.type
|
118
|
+
end
|
119
|
+
|
120
|
+
env.update(constant_types: constant_types)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
attr_reader :commands
|
126
|
+
|
127
|
+
def initialize(*commands)
|
128
|
+
@commands = commands
|
129
|
+
end
|
130
|
+
|
131
|
+
def build(type_env)
|
132
|
+
commands.inject(type_env) do |env, command|
|
133
|
+
command.call(env)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
data/lib/steep/typing.rb
CHANGED
data/lib/steep/version.rb
CHANGED
data/lib/steep.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "steep/version"
|
2
2
|
|
3
3
|
require "pathname"
|
4
|
-
require "parser/
|
4
|
+
require "parser/ruby31"
|
5
5
|
require "active_support"
|
6
6
|
require "active_support/core_ext/object/try"
|
7
7
|
require "active_support/core_ext/string/inflections"
|
@@ -21,10 +21,14 @@ require "terminal-table"
|
|
21
21
|
|
22
22
|
require "rbs"
|
23
23
|
|
24
|
+
require "steep/path_helper"
|
25
|
+
|
24
26
|
require "steep/shims/filter_map"
|
27
|
+
require "steep/shims/symbol_start_with"
|
25
28
|
|
26
29
|
require "steep/equatable"
|
27
30
|
require "steep/method_name"
|
31
|
+
require "steep/node_helper"
|
28
32
|
require "steep/ast/types/helper"
|
29
33
|
require "steep/ast/types/any"
|
30
34
|
require "steep/ast/types/instance"
|
@@ -44,7 +48,6 @@ require "steep/ast/types/tuple"
|
|
44
48
|
require "steep/ast/types/proc"
|
45
49
|
require "steep/ast/types/record"
|
46
50
|
require "steep/ast/types/logic"
|
47
|
-
require "steep/ast/type_params"
|
48
51
|
require "steep/ast/annotation"
|
49
52
|
require "steep/ast/annotation/collection"
|
50
53
|
require "steep/ast/builtin"
|
@@ -65,7 +68,6 @@ require "steep/subtyping/cache"
|
|
65
68
|
require "steep/subtyping/relation"
|
66
69
|
require "steep/subtyping/constraints"
|
67
70
|
require "steep/subtyping/variable_variance"
|
68
|
-
require "steep/subtyping/variable_occurrence"
|
69
71
|
|
70
72
|
require "steep/diagnostic/helper"
|
71
73
|
require "steep/diagnostic/ruby"
|
@@ -84,9 +86,9 @@ require "steep/type_inference/block_params"
|
|
84
86
|
require "steep/type_inference/method_params"
|
85
87
|
require "steep/type_inference/constant_env"
|
86
88
|
require "steep/type_inference/type_env"
|
87
|
-
require "steep/type_inference/
|
88
|
-
require "steep/type_inference/logic"
|
89
|
+
require "steep/type_inference/type_env_builder"
|
89
90
|
require "steep/type_inference/logic_type_interpreter"
|
91
|
+
require "steep/type_inference/multiple_assignment"
|
90
92
|
require "steep/type_inference/method_call"
|
91
93
|
require "steep/ast/types"
|
92
94
|
|
@@ -0,0 +1,112 @@
|
|
1
|
+
---
|
2
|
+
sources:
|
3
|
+
- name: ruby/gem_rbs_collection
|
4
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
5
|
+
revision: main
|
6
|
+
repo_dir: gems
|
7
|
+
path: ".gem_rbs_collection"
|
8
|
+
gems:
|
9
|
+
- name: set
|
10
|
+
version: '0'
|
11
|
+
source:
|
12
|
+
type: stdlib
|
13
|
+
- name: rbs
|
14
|
+
version: 2.6.0
|
15
|
+
source:
|
16
|
+
type: rubygems
|
17
|
+
- name: activesupport
|
18
|
+
version: '6.0'
|
19
|
+
source:
|
20
|
+
type: git
|
21
|
+
name: ruby/gem_rbs_collection
|
22
|
+
revision: cd6db41310b911e1df3476246257510673f01b8a
|
23
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
24
|
+
repo_dir: gems
|
25
|
+
- name: ast
|
26
|
+
version: '2.4'
|
27
|
+
source:
|
28
|
+
type: git
|
29
|
+
name: ruby/gem_rbs_collection
|
30
|
+
revision: cd6db41310b911e1df3476246257510673f01b8a
|
31
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
32
|
+
repo_dir: gems
|
33
|
+
- name: i18n
|
34
|
+
version: '1.10'
|
35
|
+
source:
|
36
|
+
type: git
|
37
|
+
name: ruby/gem_rbs_collection
|
38
|
+
revision: cd6db41310b911e1df3476246257510673f01b8a
|
39
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
40
|
+
repo_dir: gems
|
41
|
+
- name: listen
|
42
|
+
version: '3.2'
|
43
|
+
source:
|
44
|
+
type: git
|
45
|
+
name: ruby/gem_rbs_collection
|
46
|
+
revision: cd6db41310b911e1df3476246257510673f01b8a
|
47
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
48
|
+
repo_dir: gems
|
49
|
+
- name: minitest
|
50
|
+
version: '0'
|
51
|
+
source:
|
52
|
+
type: stdlib
|
53
|
+
- name: parallel
|
54
|
+
version: '1.20'
|
55
|
+
source:
|
56
|
+
type: git
|
57
|
+
name: ruby/gem_rbs_collection
|
58
|
+
revision: cd6db41310b911e1df3476246257510673f01b8a
|
59
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
60
|
+
repo_dir: gems
|
61
|
+
- name: rainbow
|
62
|
+
version: '3.0'
|
63
|
+
source:
|
64
|
+
type: git
|
65
|
+
name: ruby/gem_rbs_collection
|
66
|
+
revision: cd6db41310b911e1df3476246257510673f01b8a
|
67
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
68
|
+
repo_dir: gems
|
69
|
+
- name: logger
|
70
|
+
version: '0'
|
71
|
+
source:
|
72
|
+
type: stdlib
|
73
|
+
- name: pathname
|
74
|
+
version: '0'
|
75
|
+
source:
|
76
|
+
type: stdlib
|
77
|
+
- name: json
|
78
|
+
version: '0'
|
79
|
+
source:
|
80
|
+
type: stdlib
|
81
|
+
- name: optparse
|
82
|
+
version: '0'
|
83
|
+
source:
|
84
|
+
type: stdlib
|
85
|
+
- name: rubygems
|
86
|
+
version: '0'
|
87
|
+
source:
|
88
|
+
type: stdlib
|
89
|
+
- name: tsort
|
90
|
+
version: '0'
|
91
|
+
source:
|
92
|
+
type: stdlib
|
93
|
+
- name: monitor
|
94
|
+
version: '0'
|
95
|
+
source:
|
96
|
+
type: stdlib
|
97
|
+
- name: date
|
98
|
+
version: '0'
|
99
|
+
source:
|
100
|
+
type: stdlib
|
101
|
+
- name: singleton
|
102
|
+
version: '0'
|
103
|
+
source:
|
104
|
+
type: stdlib
|
105
|
+
- name: mutex_m
|
106
|
+
version: '0'
|
107
|
+
source:
|
108
|
+
type: stdlib
|
109
|
+
- name: time
|
110
|
+
version: '0'
|
111
|
+
source:
|
112
|
+
type: stdlib
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Download sources
|
2
|
+
sources:
|
3
|
+
- name: ruby/gem_rbs_collection
|
4
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
5
|
+
revision: main
|
6
|
+
repo_dir: gems
|
7
|
+
|
8
|
+
# A directory to install the downloaded RBSs
|
9
|
+
path: .gem_rbs_collection
|
10
|
+
|
11
|
+
gems:
|
12
|
+
# Skip loading rbs gem's RBS.
|
13
|
+
# It's unnecessary if you don't use rbs as a library.
|
14
|
+
- name: steep
|
15
|
+
ignore: true
|
16
|
+
- name: set
|
17
|
+
- name: rbs
|
18
|
+
- name: with_steep_types
|
19
|
+
ignore: true
|
data/sample/sig/conference.rbs
CHANGED
@@ -0,0 +1,146 @@
|
|
1
|
+
module Parser
|
2
|
+
module Source
|
3
|
+
#
|
4
|
+
# {Map} relates AST nodes to the source code they were parsed from.
|
5
|
+
# More specifically, a {Map} or its subclass contains a set of ranges:
|
6
|
+
#
|
7
|
+
# * `expression`: smallest range which includes all source corresponding
|
8
|
+
# to the node and all `expression` ranges of its children.
|
9
|
+
# * other ranges (`begin`, `end`, `operator`, ...): node-specific ranges
|
10
|
+
# pointing to various interesting tokens corresponding to the node.
|
11
|
+
#
|
12
|
+
# Note that the {Map::Heredoc} map is the only one whose `expression` does
|
13
|
+
# not include other ranges. It only covers the heredoc marker (`<<HERE`),
|
14
|
+
# not the here document itself.
|
15
|
+
#
|
16
|
+
# All ranges except `expression` are defined by {Map} subclasses.
|
17
|
+
#
|
18
|
+
# Ranges (except `expression`) can be `nil` if the corresponding token is
|
19
|
+
# not present in source. For example, a hash may not have opening/closing
|
20
|
+
# braces, and so would its source map.
|
21
|
+
#
|
22
|
+
# p Parser::CurrentRuby.parse('[1 => 2]').children[0].loc
|
23
|
+
# # => <Parser::Source::Map::Collection:0x007f5492b547d8
|
24
|
+
# # @end=nil, @begin=nil,
|
25
|
+
# # @expression=#<Source::Range (string) 1...7>>
|
26
|
+
#
|
27
|
+
# The {file:doc/AST_FORMAT.md} document describes how ranges associated to source
|
28
|
+
# code tokens. For example, the entry
|
29
|
+
#
|
30
|
+
# (array (int 1) (int 2))
|
31
|
+
#
|
32
|
+
# "[1, 2]"
|
33
|
+
# ^ begin
|
34
|
+
# ^ end
|
35
|
+
# ~~~~~~ expression
|
36
|
+
#
|
37
|
+
# means that if `node` is an {Parser::AST::Node} `(array (int 1) (int 2))`,
|
38
|
+
# then `node.loc` responds to `begin`, `end` and `expression`, and
|
39
|
+
# `node.loc.begin` returns a range pointing at the opening bracket, and so on.
|
40
|
+
#
|
41
|
+
# If you want to write code polymorphic by the source map (i.e. accepting
|
42
|
+
# several subclasses of {Map}), use `respond_to?` instead of `is_a?` to
|
43
|
+
# check whether the map features the range you need. Concrete {Map}
|
44
|
+
# subclasses may not be preserved between versions, but their interfaces
|
45
|
+
# will be kept compatible.
|
46
|
+
#
|
47
|
+
# You can visualize the source maps with `ruby-parse -E` command-line tool.
|
48
|
+
#
|
49
|
+
# @example
|
50
|
+
# require 'parser/current'
|
51
|
+
#
|
52
|
+
# p Parser::CurrentRuby.parse('[1, 2]').loc
|
53
|
+
# # => #<Parser::Source::Map::Collection:0x007f14b80eccd8
|
54
|
+
# # @end=#<Source::Range (string) 5...6>,
|
55
|
+
# # @begin=#<Source::Range (string) 0...1>,
|
56
|
+
# # @expression=#<Source::Range (string) 0...6>>
|
57
|
+
#
|
58
|
+
# @!attribute [r] node
|
59
|
+
# The node that is described by this map. Nodes and maps have 1:1 correspondence.
|
60
|
+
# @return [Parser::AST::Node]
|
61
|
+
#
|
62
|
+
# @!attribute [r] expression
|
63
|
+
# @return [Range]
|
64
|
+
#
|
65
|
+
# @api public
|
66
|
+
#
|
67
|
+
class Map
|
68
|
+
attr_reader node: AST::Node
|
69
|
+
|
70
|
+
attr_reader expression: Range
|
71
|
+
|
72
|
+
#
|
73
|
+
# @param [Range] expression
|
74
|
+
def initialize: (untyped expression) -> void
|
75
|
+
|
76
|
+
#
|
77
|
+
# @api private
|
78
|
+
def initialize_copy: (untyped other) -> untyped
|
79
|
+
|
80
|
+
#
|
81
|
+
# @api private
|
82
|
+
def node=: (untyped node) -> untyped
|
83
|
+
|
84
|
+
#
|
85
|
+
# A shortcut for `self.expression.line`.
|
86
|
+
# @return [Integer]
|
87
|
+
#
|
88
|
+
def line: () -> Integer
|
89
|
+
|
90
|
+
alias first_line line
|
91
|
+
|
92
|
+
#
|
93
|
+
# A shortcut for `self.expression.column`.
|
94
|
+
# @return [Integer]
|
95
|
+
#
|
96
|
+
def column: () -> Integer
|
97
|
+
|
98
|
+
#
|
99
|
+
# A shortcut for `self.expression.last_line`.
|
100
|
+
# @return [Integer]
|
101
|
+
#
|
102
|
+
def last_line: () -> Integer
|
103
|
+
|
104
|
+
#
|
105
|
+
# A shortcut for `self.expression.last_column`.
|
106
|
+
# @return [Integer]
|
107
|
+
#
|
108
|
+
def last_column: () -> Integer
|
109
|
+
|
110
|
+
#
|
111
|
+
# @api private
|
112
|
+
#
|
113
|
+
def with_expression: (untyped expression_l) -> untyped
|
114
|
+
|
115
|
+
#
|
116
|
+
# Compares source maps.
|
117
|
+
# @return [Boolean]
|
118
|
+
#
|
119
|
+
def ==: (untyped other) -> bool
|
120
|
+
|
121
|
+
#
|
122
|
+
# Converts this source map to a hash with keys corresponding to
|
123
|
+
# ranges. For example, if called on an instance of {Collection},
|
124
|
+
# which adds the `begin` and `end` ranges, the resulting hash
|
125
|
+
# will contain keys `:expression`, `:begin` and `:end`.
|
126
|
+
#
|
127
|
+
# @example
|
128
|
+
# require 'parser/current'
|
129
|
+
#
|
130
|
+
# p Parser::CurrentRuby.parse('[1, 2]').loc.to_hash
|
131
|
+
# # => {
|
132
|
+
# # :begin => #<Source::Range (string) 0...1>,
|
133
|
+
# # :end => #<Source::Range (string) 5...6>,
|
134
|
+
# # :expression => #<Source::Range (string) 0...6>
|
135
|
+
# # }
|
136
|
+
#
|
137
|
+
# @return [Hash<Symbol, Parser::Source::Range>]
|
138
|
+
#
|
139
|
+
def to_hash: () -> Hash[Symbol, Range]
|
140
|
+
|
141
|
+
def with: () ?{ () -> untyped } -> untyped
|
142
|
+
|
143
|
+
def update_expression: (untyped expression_l) -> untyped
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|