herb 0.11.1 → 0.11.2
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/Rakefile +4 -2
- data/config.yml +6 -0
- data/ext/herb/extconf.rb +8 -31
- data/ext/herb/nodes.c +75 -75
- data/ext/herb/parser_options_helpers.c +26 -0
- data/lib/herb/analysis/partial_index.rb +1 -1
- data/lib/herb/analysis/partial_resolution.rb +27 -0
- data/lib/herb/ast/helpers.rb +1 -1
- data/lib/herb/configuration.rb +11 -1
- data/lib/herb/dev/classifier.rb +1 -1
- data/lib/herb/engine/compiler.rb +5 -8
- data/lib/herb/engine/slots/dynamics_compiler.rb +53 -14
- data/lib/herb/engine/slots/subtree_compiler.rb +1 -1
- data/lib/herb/engine/slots/visitor.rb +32 -4
- data/lib/herb/engine/visitors/instrumentation_visitor.rb +18 -6
- data/lib/herb/parser_options.rb +6 -3
- data/lib/herb/project.rb +19 -8
- data/lib/herb/version.rb +1 -1
- data/lib/herb.rb +1 -1
- data/sig/herb/analysis/partial_resolution.rbs +8 -0
- data/sig/herb/configuration.rbs +3 -0
- data/sig/herb/engine/slots/dynamics_compiler.rbs +24 -7
- data/sig/herb/engine/slots/visitor.rbs +14 -0
- data/sig/herb/engine/visitors/instrumentation_visitor.rbs +5 -1
- data/sig/herb/parser_options.rbs +6 -4
- data/sig/herb.rbs +2 -2
- data/src/analyze/action_view/attribute_extraction_helpers.c +40 -21
- data/src/analyze/action_view/generated_handlers.c +36 -36
- data/src/analyze/action_view/image_tag.c +7 -3
- data/src/analyze/action_view/javascript_include_tag.c +6 -3
- data/src/analyze/action_view/link_to.c +23 -23
- data/src/analyze/action_view/registry.c +7 -3
- data/src/analyze/action_view/tag_helper_node_builders.c +6 -13
- data/src/analyze/action_view/tag_helpers.c +139 -90
- data/src/analyze/action_view/turbo_frame_tag.c +5 -4
- data/src/analyze/analyze.c +35 -19
- data/src/analyze/analyze_helpers.c +161 -188
- data/src/analyze/analyzed_ruby.c +8 -7
- data/src/analyze/control_type.c +29 -22
- data/src/analyze/herb_directives.c +16 -20
- data/src/analyze/iteration_nodes.c +69 -24
- data/src/analyze/parse_errors.c +32 -22
- data/src/analyze/postfix_conditionals.c +23 -13
- data/src/analyze/prism_annotate.c +29 -28
- data/src/analyze/render_nodes.c +51 -41
- data/src/analyze/strict_locals.c +14 -15
- data/src/analyze/ternary_conditionals.c +14 -10
- data/src/herb.c +10 -8
- data/src/include/analyze/action_view/tag_helper_handler.h +1 -1
- data/src/include/analyze/action_view/tag_helper_node_builders.h +1 -0
- data/src/include/analyze/action_view/tag_helpers.h +1 -1
- data/src/include/analyze/analyze.h +3 -2
- data/src/include/analyze/analyzed_ruby.h +4 -2
- data/src/include/analyze/helpers.h +6 -6
- data/src/include/herb.h +3 -2
- data/src/include/parser/parser_options.h +5 -0
- data/src/include/prism/prism_context.h +12 -12
- data/src/include/prism/prism_helpers.h +30 -0
- data/src/include/prism_version.h +11 -0
- data/src/include/version.h +1 -1
- data/src/parser/parser_helpers.c +1 -2
- data/src/parser.c +6 -7
- data/src/parser_options_defaults.c +1 -0
- data/src/prism/prism_helpers.c +84 -50
- data/src/prism/ruby_parser.c +20 -20
- data/templates/ext/herb/nodes.c.erb +5 -5
- data/templates/ext/herb/parser_options_helpers.c.erb +33 -0
- data/templates/java/nodes.c.erb +6 -6
- data/templates/java/parser_options_helpers.c.erb +41 -2
- data/templates/java/parser_options_helpers.h.erb +2 -1
- data/templates/javascript/packages/node/extension/nodes.cpp.erb +5 -5
- data/templates/javascript/packages/node/extension/parser_options_helpers.cpp.erb +34 -2
- data/templates/javascript/packages/node/extension/parser_options_helpers.h.erb +1 -1
- data/templates/lib/herb/parser_options.rb.erb +1 -1
- data/templates/rust/src/prism/generated_deserialize.rs.erb +90 -44
- data/templates/rust/src/prism/generated_prettyprint.rs.erb +18 -27
- data/templates/src/analyze/action_view/generated_handlers.c.erb +23 -22
- data/templates/src/include/parser/parser_options.h.erb +10 -0
- data/templates/src/include/prism_version.h.erb +17 -0
- data/templates/src/parser_options_defaults.c.erb +1 -1
- data/templates/template.rb +17 -2
- data/templates/wasm/nodes.cpp.erb +5 -5
- data/templates/wasm/parser_options_helpers.cpp.erb +24 -0
- data/vendor/prism/Rakefile +76 -7
- data/vendor/prism/config.yml +174 -161
- data/vendor/prism/include/prism/arena.h +45 -0
- data/vendor/prism/include/prism/arena.hpp +42 -0
- data/vendor/prism/include/prism/ast.h +2738 -611
- data/vendor/prism/include/prism/ast.hpp +641 -0
- data/vendor/prism/include/prism/buffer.h +60 -0
- data/vendor/prism/include/prism/buffer.hpp +55 -0
- data/vendor/prism/include/prism/comments.h +72 -0
- data/vendor/prism/include/prism/compiler/accel.h +26 -0
- data/vendor/prism/include/prism/compiler/align.h +36 -0
- data/vendor/prism/include/prism/compiler/assume.h +25 -0
- data/vendor/prism/include/prism/compiler/branch.h +26 -0
- data/vendor/prism/include/prism/compiler/bswap.h +46 -0
- data/vendor/prism/include/prism/compiler/cplusplus.hpp +16 -0
- data/vendor/prism/include/prism/compiler/endianness.h +34 -0
- data/vendor/prism/include/prism/compiler/exceptions.hpp +17 -0
- data/vendor/prism/include/prism/compiler/exported.h +24 -0
- data/vendor/prism/include/prism/compiler/fallthrough.h +22 -0
- data/vendor/prism/include/prism/compiler/filesystem.h +32 -0
- data/vendor/prism/include/prism/compiler/flex_array.h +19 -0
- data/vendor/prism/include/prism/compiler/force_inline.h +21 -0
- data/vendor/prism/include/prism/compiler/format.h +27 -0
- data/vendor/prism/include/prism/compiler/inline.h +17 -0
- data/vendor/prism/include/prism/compiler/lifetimebound.hpp +25 -0
- data/vendor/prism/include/prism/compiler/nodiscard.h +22 -0
- data/vendor/prism/include/prism/compiler/nonnull.h +18 -0
- data/vendor/prism/include/prism/compiler/unused.h +18 -0
- data/vendor/prism/include/prism/constant_pool.h +106 -0
- data/vendor/prism/include/prism/diagnostic.h +55 -402
- data/vendor/prism/include/prism/errors_format.h +61 -0
- data/vendor/prism/include/prism/excludes.h +29 -0
- data/vendor/prism/include/prism/integer.h +41 -0
- data/vendor/prism/include/prism/internal/allocator.h +68 -0
- data/vendor/prism/include/prism/internal/allocator_debug.h +88 -0
- data/vendor/prism/include/prism/internal/arena.h +108 -0
- data/vendor/prism/include/prism/internal/bit.h +42 -0
- data/vendor/prism/include/prism/internal/buffer.h +94 -0
- data/vendor/prism/include/prism/internal/char.h +145 -0
- data/vendor/prism/include/prism/internal/comments.h +54 -0
- data/vendor/prism/include/prism/internal/constant_pool.h +152 -0
- data/vendor/prism/include/prism/internal/diagnostic.h +389 -0
- data/vendor/prism/include/prism/{encoding.h → internal/encoding.h} +27 -68
- data/vendor/prism/include/prism/internal/integer.h +68 -0
- data/vendor/prism/include/prism/internal/isinf.h +16 -0
- data/vendor/prism/include/prism/internal/line_offset_list.h +34 -0
- data/vendor/prism/include/prism/{util/pm_list.h → internal/list.h} +11 -52
- data/vendor/prism/include/prism/internal/magic_comments.h +23 -0
- data/vendor/prism/include/prism/internal/memchr.h +15 -0
- data/vendor/prism/include/prism/internal/node.h +42 -0
- data/vendor/prism/include/prism/internal/options.h +232 -0
- data/vendor/prism/include/prism/internal/parser.h +1015 -0
- data/vendor/prism/include/prism/internal/regexp.h +26 -0
- data/vendor/prism/include/prism/internal/serialize.h +39 -0
- data/vendor/prism/include/prism/internal/source.h +72 -0
- data/vendor/prism/include/prism/internal/static_literals.h +60 -0
- data/vendor/prism/include/prism/internal/stringy.h +30 -0
- data/vendor/prism/include/prism/{util/pm_strncasecmp.h → internal/strncasecmp.h} +3 -17
- data/vendor/prism/include/prism/{util/pm_strpbrk.h → internal/strpbrk.h} +7 -20
- data/vendor/prism/include/prism/internal/tokens.h +11 -0
- data/vendor/prism/include/prism/internal/xxh3.h +16 -0
- data/vendor/prism/include/prism/json.h +40 -0
- data/vendor/prism/include/prism/line_offset_list.h +69 -0
- data/vendor/prism/include/prism/magic_comments.h +53 -0
- data/vendor/prism/include/prism/node.h +59 -49
- data/vendor/prism/include/prism/node.hpp +272 -0
- data/vendor/prism/include/prism/node_type.hpp +38 -0
- data/vendor/prism/include/prism/options.h +154 -279
- data/vendor/prism/include/prism/options.hpp +43 -0
- data/vendor/prism/include/prism/parser.h +367 -870
- data/vendor/prism/include/prism/parser.hpp +274 -0
- data/vendor/prism/include/prism/prettyprint.h +14 -9
- data/vendor/prism/include/prism/serialize.h +123 -0
- data/vendor/prism/include/prism/source.h +163 -0
- data/vendor/prism/include/prism/stream.h +36 -0
- data/vendor/prism/include/prism/string_query.h +82 -0
- data/vendor/prism/include/prism/stringy.h +61 -0
- data/vendor/prism/include/prism/stringy.hpp +31 -0
- data/vendor/prism/include/prism/version.h +20 -3
- data/vendor/prism/include/prism.h +35 -320
- data/vendor/prism/include/prism.hpp +24 -0
- data/vendor/prism/src/arena.c +122 -0
- data/vendor/prism/src/{util/pm_buffer.c → buffer.c} +53 -21
- data/vendor/prism/src/{util/pm_char.c → char.c} +28 -57
- data/vendor/prism/src/comments.c +455 -0
- data/vendor/prism/src/constant_pool.c +406 -0
- data/vendor/prism/src/diagnostic.c +120 -68
- data/vendor/prism/src/encoding.c +8 -3
- data/vendor/prism/src/errors_format.c +519 -0
- data/vendor/prism/src/{util/pm_integer.c → integer.c} +38 -22
- data/vendor/prism/src/json.c +5733 -0
- data/vendor/prism/src/line_offset_list.c +100 -0
- data/vendor/prism/src/list.c +24 -0
- data/vendor/prism/src/{util/pm_memchr.c → memchr.c} +8 -6
- data/vendor/prism/src/node.c +3465 -7787
- data/vendor/prism/src/options.c +161 -54
- data/vendor/prism/src/parser.c +371 -0
- data/vendor/prism/src/prettyprint.c +421 -354
- data/vendor/prism/src/prism.c +8522 -7280
- data/vendor/prism/src/regexp.c +960 -45
- data/vendor/prism/src/serialize.c +2434 -2048
- data/vendor/prism/src/source.c +524 -0
- data/vendor/prism/src/static_literals.c +303 -360
- data/vendor/prism/src/string_query.c +180 -0
- data/vendor/prism/src/stringy.c +61 -0
- data/vendor/prism/src/{util/pm_strncasecmp.c → strncasecmp.c} +5 -4
- data/vendor/prism/src/strpbrk.c +447 -0
- data/vendor/prism/src/{token_type.c → tokens.c} +39 -18
- data/vendor/prism/src/xxh3.c +292 -0
- data/vendor/prism/templates/ext/prism/api_node.c.erb +58 -44
- data/vendor/prism/templates/include/prism/ast.h.erb +67 -17
- data/vendor/prism/templates/include/prism/ast.hpp.erb +31 -0
- data/vendor/prism/templates/include/prism/internal/diagnostic.h.erb +60 -0
- data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/AbstractNodeVisitor.java.erb +1 -1
- data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/Loader.java.erb +232 -133
- data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/Nodes.java.erb +62 -23
- data/vendor/prism/templates/javascript/src/deserialize.js.erb +153 -146
- data/vendor/prism/templates/javascript/src/nodes.js.erb +4 -9
- data/vendor/prism/templates/lib/prism/compiler.rb.erb +14 -5
- data/vendor/prism/templates/lib/prism/dispatcher.rb.erb +20 -12
- data/vendor/prism/templates/lib/prism/dot_visitor.rb.erb +37 -11
- data/vendor/prism/templates/lib/prism/dsl.rb.erb +43 -4
- data/vendor/prism/templates/lib/prism/inspect_visitor.rb.erb +26 -10
- data/vendor/prism/templates/lib/prism/mutation_compiler.rb.erb +5 -2
- data/vendor/prism/templates/lib/prism/node.rb.erb +283 -105
- data/vendor/prism/templates/lib/prism/reflection.rb.erb +11 -2
- data/vendor/prism/templates/lib/prism/serialize.rb.erb +291 -134
- data/vendor/prism/templates/lib/prism/visitor.rb.erb +18 -0
- data/vendor/prism/templates/src/diagnostic.c.erb +114 -63
- data/vendor/prism/templates/src/json.c.erb +130 -0
- data/vendor/prism/templates/src/node.c.erb +79 -236
- data/vendor/prism/templates/src/prettyprint.c.erb +24 -13
- data/vendor/prism/templates/src/serialize.c.erb +369 -183
- data/vendor/prism/templates/src/{token_type.c.erb → tokens.c.erb} +22 -11
- data/vendor/prism/templates/template.rb +193 -91
- metadata +100 -42
- data/vendor/prism/include/prism/defines.h +0 -260
- data/vendor/prism/include/prism/pack.h +0 -163
- data/vendor/prism/include/prism/regexp.h +0 -43
- data/vendor/prism/include/prism/static_literals.h +0 -121
- data/vendor/prism/include/prism/util/pm_buffer.h +0 -236
- data/vendor/prism/include/prism/util/pm_char.h +0 -204
- data/vendor/prism/include/prism/util/pm_constant_pool.h +0 -218
- data/vendor/prism/include/prism/util/pm_integer.h +0 -130
- data/vendor/prism/include/prism/util/pm_memchr.h +0 -29
- data/vendor/prism/include/prism/util/pm_newline_list.h +0 -113
- data/vendor/prism/include/prism/util/pm_string.h +0 -200
- data/vendor/prism/src/pack.c +0 -509
- data/vendor/prism/src/util/pm_constant_pool.c +0 -342
- data/vendor/prism/src/util/pm_list.c +0 -49
- data/vendor/prism/src/util/pm_newline_list.c +0 -125
- data/vendor/prism/src/util/pm_string.c +0 -381
- data/vendor/prism/src/util/pm_strpbrk.c +0 -206
- data/vendor/prism/templates/include/prism/diagnostic.h.erb +0 -130
- data/vendor/prism/templates/rbi/prism/dsl.rbi.erb +0 -68
- data/vendor/prism/templates/rbi/prism/node.rbi.erb +0 -167
- data/vendor/prism/templates/rbi/prism/visitor.rbi.erb +0 -18
- data/vendor/prism/templates/sig/prism/_private/dot_visitor.rbs.erb +0 -45
- data/vendor/prism/templates/sig/prism/dsl.rbs.erb +0 -31
- data/vendor/prism/templates/sig/prism/mutation_compiler.rbs.erb +0 -7
- data/vendor/prism/templates/sig/prism/node.rbs.erb +0 -136
- data/vendor/prism/templates/sig/prism/visitor.rbs.erb +0 -17
- data/vendor/prism/templates/sig/prism.rbs.erb +0 -92
|
@@ -1,24 +1,49 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
1
4
|
module Prism
|
|
5
|
+
# @rbs!
|
|
6
|
+
# interface _Repository
|
|
7
|
+
# def enter: (Integer node_id, Symbol field_name) -> Relocation::Entry
|
|
8
|
+
# end
|
|
9
|
+
#
|
|
10
|
+
# interface _Node
|
|
11
|
+
# def deconstruct: () -> Array[Prism::node?]
|
|
12
|
+
# def inspect: () -> String
|
|
13
|
+
# end
|
|
14
|
+
#
|
|
15
|
+
# type node = Node & _Node
|
|
16
|
+
|
|
2
17
|
# This represents a node in the tree. It is the parent class of all of the
|
|
3
18
|
# various node types.
|
|
4
19
|
class Node
|
|
5
20
|
# A pointer to the source that this node was created from.
|
|
6
|
-
|
|
21
|
+
# :stopdoc:
|
|
22
|
+
attr_reader :source #: Source
|
|
7
23
|
private :source
|
|
24
|
+
# :startdoc:
|
|
8
25
|
|
|
9
26
|
# A unique identifier for this node. This is used in a very specific
|
|
10
27
|
# use case where you want to keep around a reference to a node without
|
|
11
28
|
# having to keep around the syntax tree in memory. This unique identifier
|
|
12
29
|
# will be consistent across multiple parses of the same source code.
|
|
13
|
-
attr_reader :node_id
|
|
30
|
+
attr_reader :node_id #: Integer
|
|
31
|
+
|
|
32
|
+
# The location associated with this node. For lazily loading Location
|
|
33
|
+
# objects, we keep it as a packed integer until it is accessed.
|
|
34
|
+
# @rbs @location: Location | Integer
|
|
14
35
|
|
|
15
36
|
# Save this node using a saved source so that it can be retrieved later.
|
|
37
|
+
#
|
|
38
|
+
#: (_Repository repository) -> Relocation::Entry
|
|
16
39
|
def save(repository)
|
|
17
40
|
repository.enter(node_id, :itself)
|
|
18
41
|
end
|
|
19
42
|
|
|
20
43
|
# A Location instance that represents the location of this node in the
|
|
21
44
|
# source.
|
|
45
|
+
#
|
|
46
|
+
#: () -> Location
|
|
22
47
|
def location
|
|
23
48
|
location = @location
|
|
24
49
|
return location if location.is_a?(Location)
|
|
@@ -26,104 +51,138 @@ module Prism
|
|
|
26
51
|
end
|
|
27
52
|
|
|
28
53
|
# Save the location using a saved source so that it can be retrieved later.
|
|
54
|
+
#
|
|
55
|
+
#: (_Repository repository) -> Relocation::Entry
|
|
29
56
|
def save_location(repository)
|
|
30
57
|
repository.enter(node_id, :location)
|
|
31
58
|
end
|
|
32
59
|
|
|
33
|
-
#
|
|
60
|
+
# --------------------------------------------------------------------------
|
|
61
|
+
# :section: Location Delegators
|
|
62
|
+
# These methods provide convenient access to the underlying Location object.
|
|
63
|
+
# --------------------------------------------------------------------------
|
|
64
|
+
|
|
65
|
+
# Delegates to [`start_line`](rdoc-ref:Location#start_line) of the associated location object.
|
|
66
|
+
#
|
|
67
|
+
#: () -> Integer
|
|
34
68
|
def start_line
|
|
35
69
|
location.start_line
|
|
36
70
|
end
|
|
37
71
|
|
|
38
|
-
# Delegates to
|
|
72
|
+
# Delegates to [`end_line`](rdoc-ref:Location#end_line) of the associated location object.
|
|
73
|
+
#
|
|
74
|
+
#: () -> Integer
|
|
39
75
|
def end_line
|
|
40
76
|
location.end_line
|
|
41
77
|
end
|
|
42
78
|
|
|
43
|
-
#
|
|
44
|
-
#
|
|
79
|
+
# Delegates to [`start_offset`](rdoc-ref:Location#start_offset) of the associated location object.
|
|
80
|
+
#
|
|
81
|
+
#: () -> Integer
|
|
45
82
|
def start_offset
|
|
46
83
|
location = @location
|
|
47
84
|
location.is_a?(Location) ? location.start_offset : location >> 32
|
|
48
85
|
end
|
|
49
86
|
|
|
50
|
-
#
|
|
51
|
-
#
|
|
87
|
+
# Delegates to [`end_offset`](rdoc-ref:Location#end_offset) of the associated location object.
|
|
88
|
+
#
|
|
89
|
+
#: () -> Integer
|
|
52
90
|
def end_offset
|
|
53
91
|
location = @location
|
|
54
92
|
location.is_a?(Location) ? location.end_offset : ((location >> 32) + (location & 0xFFFFFFFF))
|
|
55
93
|
end
|
|
56
94
|
|
|
57
|
-
# Delegates to
|
|
95
|
+
# Delegates to [`start_character_offset`](rdoc-ref:Location#start_character_offset)
|
|
96
|
+
# of the associated location object.
|
|
97
|
+
#
|
|
98
|
+
#: () -> Integer
|
|
58
99
|
def start_character_offset
|
|
59
100
|
location.start_character_offset
|
|
60
101
|
end
|
|
61
102
|
|
|
62
|
-
# Delegates to
|
|
103
|
+
# Delegates to [`end_character_offset`](rdoc-ref:Location#end_character_offset)
|
|
104
|
+
# of the associated location object.
|
|
105
|
+
#
|
|
106
|
+
#: () -> Integer
|
|
63
107
|
def end_character_offset
|
|
64
108
|
location.end_character_offset
|
|
65
109
|
end
|
|
66
110
|
|
|
67
|
-
# Delegates to
|
|
68
|
-
# object.
|
|
111
|
+
# Delegates to [`cached_start_code_units_offset`](rdoc-ref:Location#cached_start_code_units_offset)
|
|
112
|
+
# of the associated location object.
|
|
113
|
+
#
|
|
114
|
+
#: (_CodeUnitsCache cache) -> Integer
|
|
69
115
|
def cached_start_code_units_offset(cache)
|
|
70
116
|
location.cached_start_code_units_offset(cache)
|
|
71
117
|
end
|
|
72
118
|
|
|
73
|
-
# Delegates to
|
|
74
|
-
# object.
|
|
119
|
+
# Delegates to [`cached_end_code_units_offset`](rdoc-ref:Location#cached_end_code_units_offset)
|
|
120
|
+
# of the associated location object.
|
|
121
|
+
#
|
|
122
|
+
#: (_CodeUnitsCache cache) -> Integer
|
|
75
123
|
def cached_end_code_units_offset(cache)
|
|
76
124
|
location.cached_end_code_units_offset(cache)
|
|
77
125
|
end
|
|
78
126
|
|
|
79
|
-
# Delegates to
|
|
127
|
+
# Delegates to [`start_column`](rdoc-ref:Location#start_column) of the associated location object.
|
|
128
|
+
#
|
|
129
|
+
#: () -> Integer
|
|
80
130
|
def start_column
|
|
81
131
|
location.start_column
|
|
82
132
|
end
|
|
83
133
|
|
|
84
|
-
# Delegates to
|
|
134
|
+
# Delegates to [`end_column`](rdoc-ref:Location#end_column) of the associated location object.
|
|
135
|
+
#
|
|
136
|
+
#: () -> Integer
|
|
85
137
|
def end_column
|
|
86
138
|
location.end_column
|
|
87
139
|
end
|
|
88
140
|
|
|
89
|
-
# Delegates to
|
|
141
|
+
# Delegates to [`start_character_column`](rdoc-ref:Location#start_character_column)
|
|
142
|
+
# of the associated location object.
|
|
143
|
+
#
|
|
144
|
+
#: () -> Integer
|
|
90
145
|
def start_character_column
|
|
91
146
|
location.start_character_column
|
|
92
147
|
end
|
|
93
148
|
|
|
94
|
-
# Delegates to
|
|
149
|
+
# Delegates to [`end_character_column`](rdoc-ref:Location#end_character_column)
|
|
150
|
+
# of the associated location object.
|
|
151
|
+
#
|
|
152
|
+
#: () -> Integer
|
|
95
153
|
def end_character_column
|
|
96
154
|
location.end_character_column
|
|
97
155
|
end
|
|
98
156
|
|
|
99
|
-
# Delegates to
|
|
100
|
-
# object.
|
|
157
|
+
# Delegates to [`cached_start_code_units_column`](rdoc-ref:Location#cached_start_code_units_column)
|
|
158
|
+
# of the associated location object.
|
|
159
|
+
#
|
|
160
|
+
#: (_CodeUnitsCache cache) -> Integer
|
|
101
161
|
def cached_start_code_units_column(cache)
|
|
102
162
|
location.cached_start_code_units_column(cache)
|
|
103
163
|
end
|
|
104
164
|
|
|
105
|
-
# Delegates to
|
|
106
|
-
# object.
|
|
165
|
+
# Delegates to [`cached_end_code_units_column`](rdoc-ref:Location#cached_end_code_units_column)
|
|
166
|
+
# of the associated location object.
|
|
167
|
+
#
|
|
168
|
+
#: (_CodeUnitsCache cache) -> Integer
|
|
107
169
|
def cached_end_code_units_column(cache)
|
|
108
170
|
location.cached_end_code_units_column(cache)
|
|
109
171
|
end
|
|
110
172
|
|
|
111
|
-
#
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
# Delegates to the trailing_comments of the associated location object.
|
|
117
|
-
def trailing_comments
|
|
118
|
-
location.trailing_comments
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
# Delegates to the comments of the associated location object.
|
|
173
|
+
# The comments attached to this node, ordered by start offset. Comments are
|
|
174
|
+
# only attached when the source is parsed with the attach_comments option.
|
|
175
|
+
#
|
|
176
|
+
#: () -> Array[Comment]
|
|
122
177
|
def comments
|
|
123
|
-
|
|
178
|
+
source.comments_for(node_id)
|
|
124
179
|
end
|
|
125
180
|
|
|
181
|
+
# :section:
|
|
182
|
+
|
|
126
183
|
# Returns all of the lines of the source code associated with this node.
|
|
184
|
+
#
|
|
185
|
+
#: () -> Array[String]
|
|
127
186
|
def source_lines
|
|
128
187
|
location.source_lines
|
|
129
188
|
end
|
|
@@ -133,6 +192,8 @@ module Prism
|
|
|
133
192
|
alias script_lines source_lines
|
|
134
193
|
|
|
135
194
|
# Slice the location of the node from the source.
|
|
195
|
+
#
|
|
196
|
+
#: () -> String
|
|
136
197
|
def slice
|
|
137
198
|
location.slice
|
|
138
199
|
end
|
|
@@ -140,28 +201,38 @@ module Prism
|
|
|
140
201
|
# Slice the location of the node from the source, starting at the beginning
|
|
141
202
|
# of the line that the location starts on, ending at the end of the line
|
|
142
203
|
# that the location ends on.
|
|
204
|
+
#
|
|
205
|
+
#: () -> String
|
|
143
206
|
def slice_lines
|
|
144
207
|
location.slice_lines
|
|
145
208
|
end
|
|
146
209
|
|
|
147
210
|
# An bitset of flags for this node. There are certain flags that are common
|
|
148
211
|
# for all nodes, and then some nodes have specific flags.
|
|
149
|
-
|
|
212
|
+
# :stopdoc:
|
|
213
|
+
attr_reader :flags #: Integer
|
|
150
214
|
protected :flags
|
|
215
|
+
# :startdoc:
|
|
151
216
|
|
|
152
217
|
# Returns true if the node has the newline flag set.
|
|
218
|
+
#
|
|
219
|
+
#: () -> bool
|
|
153
220
|
def newline?
|
|
154
221
|
flags.anybits?(NodeFlags::NEWLINE)
|
|
155
222
|
end
|
|
156
223
|
|
|
157
224
|
# Returns true if the node has the static literal flag set.
|
|
225
|
+
#
|
|
226
|
+
#: () -> bool
|
|
158
227
|
def static_literal?
|
|
159
228
|
flags.anybits?(NodeFlags::STATIC_LITERAL)
|
|
160
229
|
end
|
|
161
230
|
|
|
162
231
|
# Similar to inspect, but respects the current level of indentation given by
|
|
163
232
|
# the pretty print object.
|
|
164
|
-
|
|
233
|
+
#
|
|
234
|
+
#: (PP q) -> void
|
|
235
|
+
def pretty_print(q) # :nodoc:
|
|
165
236
|
q.seplist(inspect.chomp.each_line, -> { q.breakable }) do |line|
|
|
166
237
|
q.text(line.chomp)
|
|
167
238
|
end
|
|
@@ -169,6 +240,8 @@ module Prism
|
|
|
169
240
|
end
|
|
170
241
|
|
|
171
242
|
# Convert this node into a graphviz dot graph string.
|
|
243
|
+
#
|
|
244
|
+
#: () -> String
|
|
172
245
|
def to_dot
|
|
173
246
|
# @type self: node
|
|
174
247
|
DotVisitor.new.tap { |visitor| accept(visitor) }.to_dot
|
|
@@ -180,9 +253,11 @@ module Prism
|
|
|
180
253
|
#
|
|
181
254
|
# Important to note is that the column given to this method should be in
|
|
182
255
|
# bytes, as opposed to characters or code units.
|
|
256
|
+
#
|
|
257
|
+
#: (Integer line, Integer column) -> Array[node]
|
|
183
258
|
def tunnel(line, column)
|
|
184
|
-
queue = [self] #: Array[
|
|
185
|
-
result = [] #: Array[
|
|
259
|
+
queue = [self] #: Array[node]
|
|
260
|
+
result = [] #: Array[node]
|
|
186
261
|
offset = source.byte_offset(line, column)
|
|
187
262
|
|
|
188
263
|
while (node = queue.shift)
|
|
@@ -205,8 +280,9 @@ module Prism
|
|
|
205
280
|
#
|
|
206
281
|
# node.breadth_first_search { |node| node.node_id == node_id }
|
|
207
282
|
#
|
|
208
|
-
|
|
209
|
-
|
|
283
|
+
#: () { (node) -> bool } -> node?
|
|
284
|
+
def breadth_first_search(&blk)
|
|
285
|
+
queue = [self] #: Array[node]
|
|
210
286
|
|
|
211
287
|
while (node = queue.shift)
|
|
212
288
|
return node if yield node
|
|
@@ -223,7 +299,8 @@ module Prism
|
|
|
223
299
|
#
|
|
224
300
|
# node.breadth_first_search_all { |node| node.is_a?(Prism::CallNode) }
|
|
225
301
|
#
|
|
226
|
-
|
|
302
|
+
#: () { (node) -> bool } -> Array[node]
|
|
303
|
+
def breadth_first_search_all(&blk)
|
|
227
304
|
queue = [self] #: Array[Prism::node]
|
|
228
305
|
results = [] #: Array[Prism::node]
|
|
229
306
|
|
|
@@ -239,6 +316,8 @@ module Prism
|
|
|
239
316
|
# Returns a list of the fields that exist for this node class. Fields
|
|
240
317
|
# describe the structure of the node. This kind of reflection is useful for
|
|
241
318
|
# things like recursively visiting each node _and_ field in the tree.
|
|
319
|
+
#
|
|
320
|
+
#: () -> Array[Reflection::Field]
|
|
242
321
|
def self.fields
|
|
243
322
|
# This method should only be called on subclasses of Node, not Node
|
|
244
323
|
# itself.
|
|
@@ -248,19 +327,22 @@ module Prism
|
|
|
248
327
|
end
|
|
249
328
|
|
|
250
329
|
# --------------------------------------------------------------------------
|
|
251
|
-
# :section: Node
|
|
252
|
-
# These methods are effectively abstract methods that
|
|
253
|
-
# the various subclasses of Node.
|
|
254
|
-
# with typecheckers.
|
|
330
|
+
# :section: Node Interface
|
|
331
|
+
# These methods are effectively abstract methods that are implemented by
|
|
332
|
+
# the various subclasses of Node.
|
|
255
333
|
# --------------------------------------------------------------------------
|
|
256
334
|
|
|
257
335
|
# Accepts a visitor and calls back into the specialized visit function.
|
|
336
|
+
#
|
|
337
|
+
#: (_Visitor visitor) -> untyped
|
|
258
338
|
def accept(visitor)
|
|
259
339
|
raise NoMethodError, "undefined method `accept' for #{inspect}"
|
|
260
340
|
end
|
|
261
341
|
|
|
262
342
|
# Returns an array of child nodes, including `nil`s in the place of optional
|
|
263
343
|
# nodes that were not present.
|
|
344
|
+
#
|
|
345
|
+
#: () -> Array[node?]
|
|
264
346
|
def child_nodes
|
|
265
347
|
raise NoMethodError, "undefined method `child_nodes' for #{inspect}"
|
|
266
348
|
end
|
|
@@ -270,23 +352,24 @@ module Prism
|
|
|
270
352
|
# With a block given, yields each child node. Without a block, returns
|
|
271
353
|
# an enumerator that contains each child node. Excludes any `nil`s in
|
|
272
354
|
# the place of optional nodes that were not present.
|
|
273
|
-
|
|
355
|
+
#
|
|
356
|
+
#: () -> Enumerator[node, void]
|
|
357
|
+
#: () { (node) -> void } -> void
|
|
358
|
+
def each_child_node(&blk)
|
|
274
359
|
raise NoMethodError, "undefined method `each_child_node' for #{inspect}"
|
|
275
360
|
end
|
|
276
361
|
|
|
277
362
|
# Returns an array of child nodes, excluding any `nil`s in the place of
|
|
278
363
|
# optional nodes that were not present.
|
|
364
|
+
#
|
|
365
|
+
#: () -> Array[node]
|
|
279
366
|
def compact_child_nodes
|
|
280
367
|
raise NoMethodError, "undefined method `compact_child_nodes' for #{inspect}"
|
|
281
368
|
end
|
|
282
369
|
|
|
283
|
-
# Returns an array of child nodes and locations that could potentially have
|
|
284
|
-
# comments attached to them.
|
|
285
|
-
def comment_targets
|
|
286
|
-
raise NoMethodError, "undefined method `comment_targets' for #{inspect}"
|
|
287
|
-
end
|
|
288
|
-
|
|
289
370
|
# Returns a string representation of the node.
|
|
371
|
+
#
|
|
372
|
+
#: () -> String
|
|
290
373
|
def inspect
|
|
291
374
|
raise NoMethodError, "undefined method `inspect' for #{inspect}"
|
|
292
375
|
end
|
|
@@ -303,6 +386,8 @@ module Prism
|
|
|
303
386
|
# it uses a single integer comparison, but also because if you're on CRuby
|
|
304
387
|
# you can take advantage of the fact that case statements with all symbol
|
|
305
388
|
# keys will use a jump table.
|
|
389
|
+
#
|
|
390
|
+
#: () -> Symbol
|
|
306
391
|
def type
|
|
307
392
|
raise NoMethodError, "undefined method `type' for #{inspect}"
|
|
308
393
|
end
|
|
@@ -311,17 +396,25 @@ module Prism
|
|
|
311
396
|
# splitting on the type of the node without having to do a long === chain.
|
|
312
397
|
# Note that like #type, it will still be slower than using == for a single
|
|
313
398
|
# class, but should be faster in a case statement or an array comparison.
|
|
399
|
+
#
|
|
400
|
+
#: () -> Symbol
|
|
314
401
|
def self.type
|
|
315
402
|
raise NoMethodError, "undefined method `type' for #{inspect}"
|
|
316
403
|
end
|
|
317
404
|
end
|
|
318
405
|
<%- nodes.each do |node| -%>
|
|
319
406
|
|
|
320
|
-
<%- node.
|
|
407
|
+
<%- node.each_comment_rdoc_line do |line| -%>
|
|
321
408
|
#<%= line %>
|
|
322
409
|
<%- end -%>
|
|
323
410
|
class <%= node.name -%> < Node
|
|
411
|
+
<%- node.fields.each do |field| -%>
|
|
412
|
+
# @rbs @<%= field.name %>: <%= field.rbs_class %>
|
|
413
|
+
<%- end -%>
|
|
414
|
+
|
|
324
415
|
# Initialize a new <%= node.name %> node.
|
|
416
|
+
#
|
|
417
|
+
#: (Source source, Integer node_id, Location location, Integer flags, <%= node.fields.map { |field| "#{field.rbs_class} #{field.name}" }.join(", ") %>) -> void
|
|
325
418
|
def initialize(<%= ["source", "node_id", "location", "flags", *node.fields.map(&:name)].join(", ") %>)
|
|
326
419
|
@source = source
|
|
327
420
|
@node_id = node_id
|
|
@@ -335,12 +428,27 @@ module Prism
|
|
|
335
428
|
<%- end -%>
|
|
336
429
|
end
|
|
337
430
|
|
|
338
|
-
#
|
|
431
|
+
# ---------
|
|
432
|
+
# :section: Repository
|
|
433
|
+
# Methods related to Relocation.
|
|
434
|
+
# ---------
|
|
435
|
+
|
|
436
|
+
# ----------------------------------------------------------------------------------
|
|
437
|
+
# :section: Node Interface
|
|
438
|
+
# These methods are present on all subclasses of Node.
|
|
439
|
+
# Read the [node interface docs](Node.html#node-interface) for more information.
|
|
440
|
+
# ----------------------------------------------------------------------------------
|
|
441
|
+
|
|
442
|
+
# See Node.accept.
|
|
443
|
+
#
|
|
444
|
+
#: (_Visitor visitor) -> untyped
|
|
339
445
|
def accept(visitor)
|
|
340
446
|
visitor.visit_<%= node.human %>(self)
|
|
341
447
|
end
|
|
342
448
|
|
|
343
|
-
#
|
|
449
|
+
# See Node.child_nodes.
|
|
450
|
+
#
|
|
451
|
+
#: () -> Array[node?]
|
|
344
452
|
def child_nodes
|
|
345
453
|
[<%= node.fields.map { |field|
|
|
346
454
|
case field
|
|
@@ -350,8 +458,11 @@ module Prism
|
|
|
350
458
|
}.compact.join(", ") %>]
|
|
351
459
|
end
|
|
352
460
|
|
|
353
|
-
#
|
|
354
|
-
|
|
461
|
+
# See Node.each_child_node.
|
|
462
|
+
#
|
|
463
|
+
#: () -> Enumerator[node, void]
|
|
464
|
+
#: () { (node) -> void } -> void
|
|
465
|
+
def each_child_node(&blk)
|
|
355
466
|
return to_enum(:each_child_node) unless block_given?
|
|
356
467
|
|
|
357
468
|
<%- node.fields.each do |field| -%>
|
|
@@ -359,14 +470,16 @@ module Prism
|
|
|
359
470
|
<%- when Prism::Template::NodeField -%>
|
|
360
471
|
yield <%= field.name %>
|
|
361
472
|
<%- when Prism::Template::OptionalNodeField -%>
|
|
362
|
-
|
|
473
|
+
if (<%= field.name %> = self.<%= field.name %>); yield <%= field.name %>; end
|
|
363
474
|
<%- when Prism::Template::NodeListField -%>
|
|
364
475
|
<%= field.name %>.each { |node| yield node }
|
|
365
476
|
<%- end -%>
|
|
366
477
|
<%- end -%>
|
|
367
478
|
end
|
|
368
479
|
|
|
369
|
-
#
|
|
480
|
+
# See Node.compact_child_nodes.
|
|
481
|
+
#
|
|
482
|
+
#: () -> Array[node]
|
|
370
483
|
def compact_child_nodes
|
|
371
484
|
<%- if node.fields.any? { |field| field.is_a?(Prism::Template::OptionalNodeField) } -%>
|
|
372
485
|
compact = [] #: Array[Prism::node]
|
|
@@ -375,7 +488,7 @@ module Prism
|
|
|
375
488
|
<%- when Prism::Template::NodeField -%>
|
|
376
489
|
compact << <%= field.name %>
|
|
377
490
|
<%- when Prism::Template::OptionalNodeField -%>
|
|
378
|
-
|
|
491
|
+
if (<%= field.name %> = self.<%= field.name %>); compact << <%= field.name %>; end
|
|
379
492
|
<%- when Prism::Template::NodeListField -%>
|
|
380
493
|
compact.concat(<%= field.name %>)
|
|
381
494
|
<%- end -%>
|
|
@@ -391,60 +504,110 @@ module Prism
|
|
|
391
504
|
<%- end -%>
|
|
392
505
|
end
|
|
393
506
|
|
|
394
|
-
#
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
end
|
|
401
|
-
}.compact.join(", ") %>] #: Array[Prism::node | Location]
|
|
402
|
-
end
|
|
403
|
-
|
|
404
|
-
# def copy: (<%= (["?node_id: Integer", "?location: Location", "?flags: Integer"] + node.fields.map { |field| "?#{field.name}: #{field.rbs_class}" }).join(", ") %>) -> <%= node.name %>
|
|
507
|
+
# :call-seq:
|
|
508
|
+
# copy(**fields) -> <%= node.name %>
|
|
509
|
+
#
|
|
510
|
+
# Creates a copy of self with the given fields, using self as the template.
|
|
511
|
+
#
|
|
512
|
+
#: (?node_id: Integer, ?location: Location, ?flags: Integer, <%= node.fields.map { |field| "?#{field.name}: #{field.rbs_class}" }.join(", ") %>) -> <%= node.name %>
|
|
405
513
|
def copy(<%= (["node_id", "location", "flags"] + node.fields.map(&:name)).map { |field| "#{field}: self.#{field}" }.join(", ") %>)
|
|
406
514
|
<%= node.name %>.new(<%= ["source", "node_id", "location", "flags", *node.fields.map(&:name)].join(", ") %>)
|
|
407
515
|
end
|
|
408
516
|
|
|
409
|
-
# def deconstruct: () -> Array[Node?]
|
|
410
517
|
alias deconstruct child_nodes
|
|
411
518
|
|
|
412
|
-
|
|
413
|
-
def deconstruct_keys(keys)
|
|
414
|
-
|
|
519
|
+
#: (Array[Symbol]? keys) -> Hash[Symbol, untyped]
|
|
520
|
+
def deconstruct_keys(keys) # :nodoc:
|
|
521
|
+
<%- deconstruct = [:node_id, :location, *node.fields.map { |field| field.name.to_sym }, *node.fields.select { |field| field.is_a?(Prism::Template::LocationField) || field.is_a?(Prism::Template::OptionalLocationField) }.map { |field| field.name.delete_suffix("_loc").to_sym }].uniq -%>
|
|
522
|
+
(keys || %i[<%= deconstruct.join(" ") %>]).each_with_object(
|
|
523
|
+
{} #: Hash[Symbol, untyped]
|
|
524
|
+
) do |key, deconstructed|
|
|
525
|
+
case key
|
|
526
|
+
<%- deconstruct.each do |key| -%>
|
|
527
|
+
when <%= "%-24s then" % [key.inspect] %> deconstructed[<%= key.inspect %>] = self.<%= key %>
|
|
528
|
+
<%- end -%>
|
|
529
|
+
end
|
|
530
|
+
end
|
|
531
|
+
end
|
|
532
|
+
|
|
533
|
+
# See `Node#type`.
|
|
534
|
+
#
|
|
535
|
+
#: () -> :<%= node.human %>
|
|
536
|
+
def type
|
|
537
|
+
:<%= node.human %>
|
|
415
538
|
end
|
|
539
|
+
|
|
540
|
+
# See `Node.type`.
|
|
541
|
+
#
|
|
542
|
+
#: () -> :<%= node.human %>
|
|
543
|
+
def self.type
|
|
544
|
+
:<%= node.human %>
|
|
545
|
+
end
|
|
546
|
+
|
|
547
|
+
#: () -> String
|
|
548
|
+
def inspect # :nodoc:
|
|
549
|
+
InspectVisitor.compose(self)
|
|
550
|
+
end
|
|
551
|
+
|
|
552
|
+
# :section:
|
|
553
|
+
|
|
416
554
|
<%- if (node_flags = node.flags) -%>
|
|
417
555
|
<%- node_flags.values.each do |value| -%>
|
|
418
|
-
|
|
419
|
-
#
|
|
556
|
+
# :category: Flags
|
|
557
|
+
# <%= value.comment %>
|
|
558
|
+
#
|
|
559
|
+
#: () -> bool
|
|
420
560
|
def <%= value.name.downcase %>?
|
|
421
561
|
flags.anybits?(<%= node_flags.name %>::<%= value.name %>)
|
|
422
562
|
end
|
|
563
|
+
|
|
423
564
|
<%- end -%>
|
|
424
565
|
<%- end -%>
|
|
425
566
|
<%- node.fields.each do |field| -%>
|
|
426
|
-
|
|
567
|
+
<%- case field -%>
|
|
568
|
+
<%- when Prism::Template::LocationField -%>
|
|
569
|
+
# :category: Locations
|
|
570
|
+
# :call-seq:
|
|
571
|
+
# <%= field.name %> -> <%= field.call_seq_type %>
|
|
572
|
+
#
|
|
427
573
|
<%- if field.comment.nil? -%>
|
|
428
|
-
#
|
|
574
|
+
# Returns the Location represented by `<%= field.name %>`.
|
|
429
575
|
<%- else -%>
|
|
430
|
-
<%- field.
|
|
576
|
+
<%- field.each_comment_rdoc_line do |line| -%>
|
|
431
577
|
#<%= line %>
|
|
432
578
|
<%- end -%>
|
|
433
579
|
<%- end -%>
|
|
434
|
-
|
|
435
|
-
|
|
580
|
+
#
|
|
581
|
+
#: () -> Location
|
|
436
582
|
def <%= field.name %>
|
|
437
583
|
location = @<%= field.name %>
|
|
438
584
|
return location if location.is_a?(Location)
|
|
439
585
|
@<%= field.name %> = Location.new(source, location >> 32, location & 0xFFFFFFFF)
|
|
440
586
|
end
|
|
441
587
|
|
|
588
|
+
# :category: Repository
|
|
442
589
|
# Save the <%= field.name %> location using the given saved source so that
|
|
443
590
|
# it can be retrieved later.
|
|
591
|
+
#
|
|
592
|
+
#: (_Repository repository) -> Relocation::Entry
|
|
444
593
|
def save_<%= field.name %>(repository)
|
|
445
594
|
repository.enter(node_id, :<%= field.name %>)
|
|
446
595
|
end
|
|
596
|
+
|
|
447
597
|
<%- when Prism::Template::OptionalLocationField -%>
|
|
598
|
+
# :category: Locations
|
|
599
|
+
# :call-seq:
|
|
600
|
+
# <%= field.name %> -> <%= field.call_seq_type %>
|
|
601
|
+
#
|
|
602
|
+
<%- if field.comment.nil? -%>
|
|
603
|
+
# Returns the Location represented by `<%= field.name %>`.
|
|
604
|
+
<%- else -%>
|
|
605
|
+
<%- field.each_comment_rdoc_line do |line| -%>
|
|
606
|
+
#<%= line %>
|
|
607
|
+
<%- end -%>
|
|
608
|
+
<%- end -%>
|
|
609
|
+
#
|
|
610
|
+
#: () -> Location?
|
|
448
611
|
def <%= field.name %>
|
|
449
612
|
location = @<%= field.name %>
|
|
450
613
|
case location
|
|
@@ -457,54 +620,69 @@ module Prism
|
|
|
457
620
|
end
|
|
458
621
|
end
|
|
459
622
|
|
|
623
|
+
# :category: Repository
|
|
460
624
|
# Save the <%= field.name %> location using the given saved source so that
|
|
461
625
|
# it can be retrieved later.
|
|
626
|
+
#
|
|
627
|
+
#: (_Repository repository) -> Relocation::Entry?
|
|
462
628
|
def save_<%= field.name %>(repository)
|
|
463
629
|
repository.enter(node_id, :<%= field.name %>) unless @<%= field.name %>.nil?
|
|
464
630
|
end
|
|
465
631
|
<%- else -%>
|
|
466
|
-
|
|
632
|
+
# :call-seq:
|
|
633
|
+
# <%= field.name %> -> <%= field.call_seq_type %>
|
|
634
|
+
#
|
|
635
|
+
<%- if field.comment.nil? -%>
|
|
636
|
+
# Returns the `<%= field.name %>` attribute.
|
|
637
|
+
<%- else -%>
|
|
638
|
+
<%- field.each_comment_rdoc_line do |line| -%>
|
|
639
|
+
#<%= line %>
|
|
467
640
|
<%- end -%>
|
|
468
641
|
<%- end -%>
|
|
642
|
+
#
|
|
643
|
+
#: () -> <%= field.rbs_class %>
|
|
644
|
+
def <%= field.name %>
|
|
645
|
+
@<%= field.name %>
|
|
646
|
+
end
|
|
647
|
+
|
|
648
|
+
<%- end -%>
|
|
649
|
+
<%- end -%>
|
|
650
|
+
# :section: Slicing
|
|
651
|
+
|
|
469
652
|
<%- node.fields.each do |field| -%>
|
|
470
653
|
<%- case field -%>
|
|
471
654
|
<%- when Prism::Template::LocationField -%>
|
|
472
655
|
<%- raise unless field.name.end_with?("_loc") -%>
|
|
473
656
|
<%- next if node.fields.any? { |other| other.name == field.name.delete_suffix("_loc") } -%>
|
|
474
|
-
|
|
475
|
-
#
|
|
657
|
+
# :call-seq:
|
|
658
|
+
# <%= field.name.delete_suffix("_loc") %> -> String
|
|
659
|
+
#
|
|
660
|
+
# Slice the location of <%= field.name %> from the source.
|
|
661
|
+
#
|
|
662
|
+
#: () -> String
|
|
476
663
|
def <%= field.name.delete_suffix("_loc") %>
|
|
477
664
|
<%= field.name %>.slice
|
|
478
665
|
end
|
|
666
|
+
|
|
479
667
|
<%- when Prism::Template::OptionalLocationField -%>
|
|
480
668
|
<%- raise unless field.name.end_with?("_loc") -%>
|
|
481
669
|
<%- next if node.fields.any? { |other| other.name == field.name.delete_suffix("_loc") } -%>
|
|
482
|
-
|
|
483
|
-
#
|
|
670
|
+
# :call-seq:
|
|
671
|
+
# <%= field.name.delete_suffix("_loc") %> -> String | nil
|
|
672
|
+
#
|
|
673
|
+
# Slice the location of <%= field.name %> from the source.
|
|
674
|
+
#
|
|
675
|
+
#: () -> String?
|
|
484
676
|
def <%= field.name.delete_suffix("_loc") %>
|
|
485
677
|
<%= field.name %>&.slice
|
|
486
678
|
end
|
|
679
|
+
|
|
487
680
|
<%- end -%>
|
|
488
681
|
<%- end -%>
|
|
682
|
+
# :section:
|
|
489
683
|
|
|
490
|
-
|
|
491
|
-
def
|
|
492
|
-
InspectVisitor.compose(self)
|
|
493
|
-
end
|
|
494
|
-
|
|
495
|
-
# Return a symbol representation of this node type. See `Node#type`.
|
|
496
|
-
def type
|
|
497
|
-
:<%= node.human %>
|
|
498
|
-
end
|
|
499
|
-
|
|
500
|
-
# Return a symbol representation of this node type. See `Node::type`.
|
|
501
|
-
def self.type
|
|
502
|
-
:<%= node.human %>
|
|
503
|
-
end
|
|
504
|
-
|
|
505
|
-
# Implements case-equality for the node. This is effectively == but without
|
|
506
|
-
# comparing the value of locations. Locations are checked only for presence.
|
|
507
|
-
def ===(other)
|
|
684
|
+
#: (untyped other) -> boolish
|
|
685
|
+
def ===(other) # :nodoc:
|
|
508
686
|
other.is_a?(<%= node.name %>)<%= " &&" if (fields = [*node.flags, *node.fields]).any? %>
|
|
509
687
|
<%- fields.each_with_index do |field, index| -%>
|
|
510
688
|
<%- if field.is_a?(Prism::Template::LocationField) || field.is_a?(Prism::Template::OptionalLocationField) -%>
|