prism 2.0.0.rc1-arm64-darwin
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 +7 -0
- data/BSDmakefile +58 -0
- data/CHANGELOG.md +870 -0
- data/CODE_OF_CONDUCT.md +76 -0
- data/CONTRIBUTING.md +58 -0
- data/LICENSE.md +7 -0
- data/Makefile +145 -0
- data/README.md +81 -0
- data/config.yml +4752 -0
- data/docs/build_system.md +119 -0
- data/docs/configuration.md +69 -0
- data/docs/cruby_compilation.md +27 -0
- data/docs/design.md +53 -0
- data/docs/encoding.md +121 -0
- data/docs/fuzzing.md +81 -0
- data/docs/heredocs.md +36 -0
- data/docs/javascript.md +133 -0
- data/docs/local_variable_depth.md +229 -0
- data/docs/mapping.md +117 -0
- data/docs/parser_translation.md +24 -0
- data/docs/parsing_rules.md +22 -0
- data/docs/releasing.md +147 -0
- data/docs/relocation.md +32 -0
- data/docs/ripper_translation.md +63 -0
- data/docs/ruby_api.md +45 -0
- data/docs/ruby_parser_translation.md +19 -0
- data/docs/serialization.md +230 -0
- data/docs/testing.md +72 -0
- data/ext/prism/api_node.c +7005 -0
- data/ext/prism/extconf.rb +126 -0
- data/ext/prism/extension.c +1783 -0
- data/ext/prism/extension.h +19 -0
- data/include/prism/arena.h +37 -0
- data/include/prism/ast.h +10371 -0
- data/include/prism/buffer.h +52 -0
- data/include/prism/comments.h +55 -0
- data/include/prism/compiler/accel.h +24 -0
- data/include/prism/compiler/align.h +36 -0
- data/include/prism/compiler/assume.h +25 -0
- data/include/prism/compiler/exported.h +24 -0
- data/include/prism/compiler/fallthrough.h +22 -0
- data/include/prism/compiler/filesystem.h +32 -0
- data/include/prism/compiler/flex_array.h +19 -0
- data/include/prism/compiler/force_inline.h +21 -0
- data/include/prism/compiler/format.h +25 -0
- data/include/prism/compiler/inline.h +17 -0
- data/include/prism/compiler/nodiscard.h +22 -0
- data/include/prism/compiler/nonnull.h +18 -0
- data/include/prism/compiler/unused.h +18 -0
- data/include/prism/constant_pool.h +81 -0
- data/include/prism/diagnostic.h +93 -0
- data/include/prism/errors_format.h +53 -0
- data/include/prism/excludes.h +29 -0
- data/include/prism/integer.h +41 -0
- data/include/prism/internal/allocator.h +68 -0
- data/include/prism/internal/allocator_debug.h +88 -0
- data/include/prism/internal/arena.h +108 -0
- data/include/prism/internal/bit.h +42 -0
- data/include/prism/internal/buffer.h +91 -0
- data/include/prism/internal/char.h +145 -0
- data/include/prism/internal/comments.h +53 -0
- data/include/prism/internal/constant_pool.h +152 -0
- data/include/prism/internal/diagnostic.h +389 -0
- data/include/prism/internal/encoding.h +242 -0
- data/include/prism/internal/integer.h +68 -0
- data/include/prism/internal/isinf.h +16 -0
- data/include/prism/internal/line_offset_list.h +34 -0
- data/include/prism/internal/list.h +62 -0
- data/include/prism/internal/magic_comments.h +23 -0
- data/include/prism/internal/memchr.h +15 -0
- data/include/prism/internal/node.h +38 -0
- data/include/prism/internal/options.h +232 -0
- data/include/prism/internal/parser.h +984 -0
- data/include/prism/internal/regexp.h +26 -0
- data/include/prism/internal/serialize.h +39 -0
- data/include/prism/internal/source.h +72 -0
- data/include/prism/internal/static_literals.h +100 -0
- data/include/prism/internal/stringy.h +35 -0
- data/include/prism/internal/strncasecmp.h +18 -0
- data/include/prism/internal/strpbrk.h +33 -0
- data/include/prism/internal/tokens.h +11 -0
- data/include/prism/json.h +32 -0
- data/include/prism/line_offset_list.h +61 -0
- data/include/prism/magic_comments.h +35 -0
- data/include/prism/node.h +94 -0
- data/include/prism/options.h +354 -0
- data/include/prism/parser.h +404 -0
- data/include/prism/prettyprint.h +31 -0
- data/include/prism/serialize.h +115 -0
- data/include/prism/source.h +155 -0
- data/include/prism/stream.h +28 -0
- data/include/prism/string_query.h +63 -0
- data/include/prism/stringy.h +72 -0
- data/include/prism/version.h +38 -0
- data/include/prism.h +131 -0
- data/lib/prism/3.3/prism.bundle +0 -0
- data/lib/prism/3.4/prism.bundle +0 -0
- data/lib/prism/4.0/prism.bundle +0 -0
- data/lib/prism/compiler.rb +815 -0
- data/lib/prism/desugar_compiler.rb +463 -0
- data/lib/prism/dispatcher.rb +2383 -0
- data/lib/prism/dot_visitor.rb +4848 -0
- data/lib/prism/dsl.rb +1369 -0
- data/lib/prism/ffi.rb +740 -0
- data/lib/prism/inspect_visitor.rb +2425 -0
- data/lib/prism/lex_compat.rb +953 -0
- data/lib/prism/mutation_compiler.rb +780 -0
- data/lib/prism/node.rb +33204 -0
- data/lib/prism/node_ext.rb +504 -0
- data/lib/prism/node_find.rb +215 -0
- data/lib/prism/parse_result/errors.rb +72 -0
- data/lib/prism/parse_result/newlines.rb +423 -0
- data/lib/prism/parse_result.rb +1221 -0
- data/lib/prism/pattern.rb +314 -0
- data/lib/prism/polyfill/append_as_bytes.rb +15 -0
- data/lib/prism/polyfill/byteindex.rb +13 -0
- data/lib/prism/polyfill/scan_byte.rb +14 -0
- data/lib/prism/polyfill/unpack1.rb +14 -0
- data/lib/prism/polyfill/warn.rb +36 -0
- data/lib/prism/reflection.rb +427 -0
- data/lib/prism/relocation.rb +567 -0
- data/lib/prism/serialize.rb +5308 -0
- data/lib/prism/string_query.rb +46 -0
- data/lib/prism/translation/parser/builder.rb +70 -0
- data/lib/prism/translation/parser/compiler.rb +2226 -0
- data/lib/prism/translation/parser/lexer.rb +769 -0
- data/lib/prism/translation/parser.rb +376 -0
- data/lib/prism/translation/parser_current.rb +26 -0
- data/lib/prism/translation/parser_versions.rb +36 -0
- data/lib/prism/translation/ripper/filter.rb +53 -0
- data/lib/prism/translation/ripper/lexer.rb +133 -0
- data/lib/prism/translation/ripper/sexp.rb +118 -0
- data/lib/prism/translation/ripper/shim.rb +7 -0
- data/lib/prism/translation/ripper.rb +4278 -0
- data/lib/prism/translation/ruby_parser.rb +1721 -0
- data/lib/prism/translation.rb +20 -0
- data/lib/prism/visitor.rb +1440 -0
- data/lib/prism.rb +168 -0
- data/prism.gemspec +234 -0
- data/rbi/generated/prism/compiler.rbi +489 -0
- data/rbi/generated/prism/desugar_compiler.rbi +306 -0
- data/rbi/generated/prism/dispatcher.rbi +1138 -0
- data/rbi/generated/prism/dot_visitor.rbi +618 -0
- data/rbi/generated/prism/dsl.rbi +751 -0
- data/rbi/generated/prism/inspect_visitor.rbi +503 -0
- data/rbi/generated/prism/lex_compat.rbi +162 -0
- data/rbi/generated/prism/mutation_compiler.rbi +464 -0
- data/rbi/generated/prism/node.rbi +13681 -0
- data/rbi/generated/prism/node_ext.rbi +259 -0
- data/rbi/generated/prism/node_find.rbi +79 -0
- data/rbi/generated/prism/parse_result/errors.rbi +21 -0
- data/rbi/generated/prism/parse_result/newlines.rbi +208 -0
- data/rbi/generated/prism/parse_result.rbi +764 -0
- data/rbi/generated/prism/pattern.rbi +134 -0
- data/rbi/generated/prism/reflection.rbi +89 -0
- data/rbi/generated/prism/relocation.rbi +329 -0
- data/rbi/generated/prism/serialize.rbi +181 -0
- data/rbi/generated/prism/string_query.rbi +36 -0
- data/rbi/generated/prism/translation.rbi +7 -0
- data/rbi/generated/prism/visitor.rbi +650 -0
- data/rbi/generated/prism.rbi +86 -0
- data/rbi/prism/translation/parser.rbi +11 -0
- data/rbi/prism/translation/parser_versions.rbi +28 -0
- data/rbi/prism/translation/ripper.rbi +15 -0
- data/rbi/rubyvm/node_find.rbi +14 -0
- data/sig/generated/prism/compiler.rbs +492 -0
- data/sig/generated/prism/desugar_compiler.rbs +305 -0
- data/sig/generated/prism/dispatcher.rbs +1292 -0
- data/sig/generated/prism/dot_visitor.rbs +635 -0
- data/sig/generated/prism/dsl.rbs +928 -0
- data/sig/generated/prism/inspect_visitor.rbs +509 -0
- data/sig/generated/prism/lex_compat.rbs +166 -0
- data/sig/generated/prism/mutation_compiler.rbs +464 -0
- data/sig/generated/prism/node.rbs +20160 -0
- data/sig/generated/prism/node_ext.rbs +290 -0
- data/sig/generated/prism/node_find.rbs +90 -0
- data/sig/generated/prism/parse_result/errors.rbs +22 -0
- data/sig/generated/prism/parse_result/newlines.rbs +223 -0
- data/sig/generated/prism/parse_result.rbs +859 -0
- data/sig/generated/prism/pattern.rbs +156 -0
- data/sig/generated/prism/reflection.rbs +101 -0
- data/sig/generated/prism/relocation.rbs +428 -0
- data/sig/generated/prism/serialize.rbs +195 -0
- data/sig/generated/prism/string_query.rbs +36 -0
- data/sig/generated/prism/translation.rbs +8 -0
- data/sig/generated/prism/visitor.rbs +1111 -0
- data/sig/generated/prism.rbs +84 -0
- data/sig/manifest.yaml +2 -0
- data/src/arena.c +117 -0
- data/src/buffer.c +380 -0
- data/src/char.c +289 -0
- data/src/comments.c +454 -0
- data/src/constant_pool.c +406 -0
- data/src/diagnostic.c +886 -0
- data/src/encoding.c +5345 -0
- data/src/errors_format.c +519 -0
- data/src/integer.c +681 -0
- data/src/json.c +5733 -0
- data/src/line_offset_list.c +100 -0
- data/src/list.c +24 -0
- data/src/memchr.c +37 -0
- data/src/node.c +4515 -0
- data/src/options.c +451 -0
- data/src/parser.c +349 -0
- data/src/prettyprint.c +9024 -0
- data/src/prism.c +23739 -0
- data/src/regexp.c +1706 -0
- data/src/serialize.c +2309 -0
- data/src/source.c +518 -0
- data/src/static_literals.c +685 -0
- data/src/string_query.c +166 -0
- data/src/stringy.c +91 -0
- data/src/strncasecmp.c +37 -0
- data/src/strpbrk.c +447 -0
- data/src/tokens.c +724 -0
- metadata +259 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# Generated from lib/prism/pattern.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Prism
|
|
4
|
+
# A pattern is an object that wraps a Ruby pattern matching expression. The
|
|
5
|
+
# expression would normally be passed to an `in` clause within a `case`
|
|
6
|
+
# expression or a rightward assignment expression. For example, in the
|
|
7
|
+
# following snippet:
|
|
8
|
+
#
|
|
9
|
+
# case node
|
|
10
|
+
# in ConstantPathNode[ConstantReadNode[name: :Prism], ConstantReadNode[name: :Pattern]]
|
|
11
|
+
# end
|
|
12
|
+
#
|
|
13
|
+
# the pattern is the <tt>ConstantPathNode[...]</tt> expression.
|
|
14
|
+
#
|
|
15
|
+
# The pattern gets compiled into an object that responds to #call by running
|
|
16
|
+
# the #compile method. This method itself will run back through Prism to
|
|
17
|
+
# parse the expression into a tree, then walk the tree to generate the
|
|
18
|
+
# necessary callable objects. For example, if you wanted to compile the
|
|
19
|
+
# expression above into a callable, you would:
|
|
20
|
+
#
|
|
21
|
+
# callable = Prism::Pattern.new("ConstantPathNode[ConstantReadNode[name: :Prism], ConstantReadNode[name: :Pattern]]").compile
|
|
22
|
+
# callable.call(node)
|
|
23
|
+
#
|
|
24
|
+
# The callable object returned by #compile is guaranteed to respond to #call
|
|
25
|
+
# with a single argument, which is the node to match against. It also is
|
|
26
|
+
# guaranteed to respond to #===, which means it itself can be used in a `case`
|
|
27
|
+
# expression, as in:
|
|
28
|
+
#
|
|
29
|
+
# case node
|
|
30
|
+
# when callable
|
|
31
|
+
# end
|
|
32
|
+
#
|
|
33
|
+
# If the query given to the initializer cannot be compiled into a valid
|
|
34
|
+
# matcher (either because of a syntax error or because it is using syntax we
|
|
35
|
+
# do not yet support) then a Prism::Pattern::CompilationError will be
|
|
36
|
+
# raised.
|
|
37
|
+
class Pattern
|
|
38
|
+
# Raised when the query given to a pattern is either invalid Ruby syntax or
|
|
39
|
+
# is using syntax that we don't yet support.
|
|
40
|
+
class CompilationError < StandardError
|
|
41
|
+
# Create a new CompilationError with the given representation of the node
|
|
42
|
+
# that caused the error.
|
|
43
|
+
#
|
|
44
|
+
# : (String repr) -> void
|
|
45
|
+
def initialize: (String repr) -> void
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# The query that this pattern was initialized with.
|
|
49
|
+
attr_reader query: String
|
|
50
|
+
|
|
51
|
+
@compiled: Proc?
|
|
52
|
+
|
|
53
|
+
# Create a new pattern with the given query. The query should be a string
|
|
54
|
+
# containing a Ruby pattern matching expression.
|
|
55
|
+
#
|
|
56
|
+
# : (String query) -> void
|
|
57
|
+
def initialize: (String query) -> void
|
|
58
|
+
|
|
59
|
+
# Compile the query into a callable object that can be used to match against
|
|
60
|
+
# nodes.
|
|
61
|
+
#
|
|
62
|
+
# : () -> Proc
|
|
63
|
+
def compile: () -> Proc
|
|
64
|
+
|
|
65
|
+
# Scan the given node and all of its children for nodes that match the
|
|
66
|
+
# pattern. If a block is given, it will be called with each node that
|
|
67
|
+
# matches the pattern. If no block is given, an enumerator will be returned
|
|
68
|
+
# that will yield each node that matches the pattern.
|
|
69
|
+
#
|
|
70
|
+
# : (node root) -> Enumerator[node, void]
|
|
71
|
+
# : (node root) { (node) -> void } -> void
|
|
72
|
+
def scan: (node root) -> Enumerator[node, void]
|
|
73
|
+
| (node root) { (node) -> void } -> void
|
|
74
|
+
|
|
75
|
+
private
|
|
76
|
+
|
|
77
|
+
# Shortcut for combining two procs into one that returns true if both return
|
|
78
|
+
# true.
|
|
79
|
+
#
|
|
80
|
+
# : (Proc left, Proc right) -> Proc
|
|
81
|
+
def combine_and: (Proc left, Proc right) -> Proc
|
|
82
|
+
|
|
83
|
+
# Shortcut for combining two procs into one that returns true if either
|
|
84
|
+
# returns true.
|
|
85
|
+
#
|
|
86
|
+
# : (Proc left, Proc right) -> Proc
|
|
87
|
+
def combine_or: (Proc left, Proc right) -> Proc
|
|
88
|
+
|
|
89
|
+
# Raise an error because the given node is not supported. Note purposefully
|
|
90
|
+
# not typing this method since it is a no return method that Steep does not
|
|
91
|
+
# understand.
|
|
92
|
+
#
|
|
93
|
+
# : (node node) -> bot
|
|
94
|
+
def compile_error: (node node) -> bot
|
|
95
|
+
|
|
96
|
+
# in [foo, bar, baz]
|
|
97
|
+
#
|
|
98
|
+
# : (ArrayPatternNode node) -> Proc
|
|
99
|
+
def compile_array_pattern_node: (ArrayPatternNode node) -> Proc
|
|
100
|
+
|
|
101
|
+
# in foo | bar
|
|
102
|
+
#
|
|
103
|
+
# : (AlternationPatternNode node) -> Proc
|
|
104
|
+
def compile_alternation_pattern_node: (AlternationPatternNode node) -> Proc
|
|
105
|
+
|
|
106
|
+
# in Prism::ConstantReadNode
|
|
107
|
+
#
|
|
108
|
+
# : (ConstantPathNode node) -> Proc
|
|
109
|
+
def compile_constant_path_node: (ConstantPathNode node) -> Proc
|
|
110
|
+
|
|
111
|
+
# in ConstantReadNode
|
|
112
|
+
# in String
|
|
113
|
+
#
|
|
114
|
+
# : (ConstantReadNode node) -> Proc
|
|
115
|
+
def compile_constant_read_node: (ConstantReadNode node) -> Proc
|
|
116
|
+
|
|
117
|
+
# Compile a name associated with a constant.
|
|
118
|
+
#
|
|
119
|
+
# : ((ConstantPathNode | ConstantReadNode) node, Symbol name) -> Proc
|
|
120
|
+
def compile_constant_name: (ConstantPathNode | ConstantReadNode node, Symbol name) -> Proc
|
|
121
|
+
|
|
122
|
+
# in InstanceVariableReadNode[name: Symbol]
|
|
123
|
+
# in { name: Symbol }
|
|
124
|
+
#
|
|
125
|
+
# : (HashPatternNode node) -> Proc
|
|
126
|
+
def compile_hash_pattern_node: (HashPatternNode node) -> Proc
|
|
127
|
+
|
|
128
|
+
# in nil
|
|
129
|
+
#
|
|
130
|
+
# : (NilNode node) -> Proc
|
|
131
|
+
def compile_nil_node: (NilNode node) -> Proc
|
|
132
|
+
|
|
133
|
+
# in /foo/
|
|
134
|
+
#
|
|
135
|
+
# : (RegularExpressionNode node) -> Proc
|
|
136
|
+
def compile_regular_expression_node: (RegularExpressionNode node) -> Proc
|
|
137
|
+
|
|
138
|
+
# in ""
|
|
139
|
+
# in "foo"
|
|
140
|
+
#
|
|
141
|
+
# : (StringNode node) -> Proc
|
|
142
|
+
def compile_string_node: (StringNode node) -> Proc
|
|
143
|
+
|
|
144
|
+
# in :+
|
|
145
|
+
# in :foo
|
|
146
|
+
#
|
|
147
|
+
# : (SymbolNode node) -> Proc
|
|
148
|
+
def compile_symbol_node: (SymbolNode node) -> Proc
|
|
149
|
+
|
|
150
|
+
# Compile any kind of node. Dispatch out to the individual compilation
|
|
151
|
+
# methods based on the type of node.
|
|
152
|
+
#
|
|
153
|
+
# : (node node) -> Proc
|
|
154
|
+
def compile_node: (node node) -> Proc
|
|
155
|
+
end
|
|
156
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Generated from lib/prism/reflection.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Prism
|
|
4
|
+
# The Reflection module provides the ability to reflect on the structure of
|
|
5
|
+
# the syntax tree itself, as opposed to looking at a single syntax tree. This
|
|
6
|
+
# is useful in metaprogramming contexts.
|
|
7
|
+
module Reflection
|
|
8
|
+
# A field represents a single piece of data on a node. It is the base class
|
|
9
|
+
# for all other field types.
|
|
10
|
+
class Field
|
|
11
|
+
# The name of the field.
|
|
12
|
+
attr_reader name: Symbol
|
|
13
|
+
|
|
14
|
+
# Initializes the field with the given name.
|
|
15
|
+
#
|
|
16
|
+
# : (Symbol name) -> void
|
|
17
|
+
def initialize: (Symbol name) -> void
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# A node field represents a single child node in the syntax tree. It
|
|
21
|
+
# resolves to a Prism::Node in Ruby.
|
|
22
|
+
class NodeField < Field
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# An optional node field represents a single child node in the syntax tree
|
|
26
|
+
# that may or may not be present. It resolves to either a Prism::Node or nil
|
|
27
|
+
# in Ruby.
|
|
28
|
+
class OptionalNodeField < Field
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# A node list field represents a list of child nodes in the syntax tree. It
|
|
32
|
+
# resolves to an array of Prism::Node instances in Ruby.
|
|
33
|
+
class NodeListField < Field
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# A constant field represents a constant value on a node. Effectively, it
|
|
37
|
+
# represents an identifier found within the source. It resolves to a symbol
|
|
38
|
+
# in Ruby.
|
|
39
|
+
class ConstantField < Field
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# An optional constant field represents a constant value on a node that may
|
|
43
|
+
# or may not be present. It resolves to either a symbol or nil in Ruby.
|
|
44
|
+
class OptionalConstantField < Field
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# A constant list field represents a list of constant values on a node. It
|
|
48
|
+
# resolves to an array of symbols in Ruby.
|
|
49
|
+
class ConstantListField < Field
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# A string field represents a string value on a node. It almost always
|
|
53
|
+
# represents the unescaped value of a string-like literal. It resolves to a
|
|
54
|
+
# string in Ruby.
|
|
55
|
+
class StringField < Field
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# A location field represents the location of some part of the node in the
|
|
59
|
+
# source code. For example, the location of a keyword or an operator. It
|
|
60
|
+
# resolves to a Prism::Location in Ruby.
|
|
61
|
+
class LocationField < Field
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# An optional location field represents the location of some part of the
|
|
65
|
+
# node in the source code that may or may not be present. It resolves to
|
|
66
|
+
# either a Prism::Location or nil in Ruby.
|
|
67
|
+
class OptionalLocationField < Field
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# An integer field represents an integer value. It is used to represent the
|
|
71
|
+
# value of an integer literal, the depth of local variables, and the number
|
|
72
|
+
# of a numbered reference. It resolves to an Integer in Ruby.
|
|
73
|
+
class IntegerField < Field
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# A float field represents a double-precision floating point value. It is
|
|
77
|
+
# used exclusively to represent the value of a floating point literal. It
|
|
78
|
+
# resolves to a Float in Ruby.
|
|
79
|
+
class FloatField < Field
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# A flags field represents a bitset of flags on a node. It resolves to an
|
|
83
|
+
# integer in Ruby. Note that the flags cannot be accessed directly on the
|
|
84
|
+
# node because the integer is kept private. Instead, the various flags in
|
|
85
|
+
# the bitset should be accessed through their query methods.
|
|
86
|
+
class FlagsField < Field
|
|
87
|
+
# The names of the flags in the bitset.
|
|
88
|
+
attr_reader flags: Array[Symbol]
|
|
89
|
+
|
|
90
|
+
# Initializes the flags field with the given name and flags.
|
|
91
|
+
#
|
|
92
|
+
# : (Symbol name, Array[Symbol] flags) -> void
|
|
93
|
+
def initialize: (Symbol name, Array[Symbol] flags) -> void
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Returns the fields for the given node.
|
|
97
|
+
#
|
|
98
|
+
# : (singleton(Node) node) -> Array[Field]
|
|
99
|
+
def self.fields_for: (singleton(Node) node) -> Array[Field]
|
|
100
|
+
end
|
|
101
|
+
end
|
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
# Generated from lib/prism/relocation.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Prism
|
|
4
|
+
# Prism parses deterministically for the same input. This provides a nice
|
|
5
|
+
# property that is exposed through the #node_id API on nodes. Effectively this
|
|
6
|
+
# means that for the same input, these values will remain consistent every
|
|
7
|
+
# time the source is parsed. This means we can reparse the source same with a
|
|
8
|
+
# #node_id value and find the exact same node again.
|
|
9
|
+
#
|
|
10
|
+
# The Relocation module provides an API around this property. It allows you to
|
|
11
|
+
# "save" nodes and locations using a minimal amount of memory (just the
|
|
12
|
+
# node_id and a field identifier) and then reify them later.
|
|
13
|
+
module Relocation
|
|
14
|
+
type entry_value = untyped
|
|
15
|
+
|
|
16
|
+
type entry_values = Hash[Symbol, entry_value]
|
|
17
|
+
|
|
18
|
+
interface _Value
|
|
19
|
+
def start_line: () -> Integer
|
|
20
|
+
|
|
21
|
+
def end_line: () -> Integer
|
|
22
|
+
|
|
23
|
+
def start_offset: () -> Integer
|
|
24
|
+
|
|
25
|
+
def end_offset: () -> Integer
|
|
26
|
+
|
|
27
|
+
def start_character_offset: () -> Integer
|
|
28
|
+
|
|
29
|
+
def end_character_offset: () -> Integer
|
|
30
|
+
|
|
31
|
+
def cached_start_code_units_offset: (_CodeUnitsCache cache) -> Integer
|
|
32
|
+
|
|
33
|
+
def cached_end_code_units_offset: (_CodeUnitsCache cache) -> Integer
|
|
34
|
+
|
|
35
|
+
def start_column: () -> Integer
|
|
36
|
+
|
|
37
|
+
def end_column: () -> Integer
|
|
38
|
+
|
|
39
|
+
def start_character_column: () -> Integer
|
|
40
|
+
|
|
41
|
+
def end_character_column: () -> Integer
|
|
42
|
+
|
|
43
|
+
def cached_start_code_units_column: (_CodeUnitsCache cache) -> Integer
|
|
44
|
+
|
|
45
|
+
def cached_end_code_units_column: (_CodeUnitsCache cache) -> Integer
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
interface _Field
|
|
49
|
+
def fields: (_Value value) -> entry_values
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# An entry in a repository that will lazily reify its values when they are
|
|
53
|
+
# first accessed.
|
|
54
|
+
class Entry
|
|
55
|
+
# Raised if a value that could potentially be on an entry is missing
|
|
56
|
+
# because it was either not configured on the repository or it has not yet
|
|
57
|
+
# been fetched.
|
|
58
|
+
class MissingValueError < StandardError
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
@values: Hash[Symbol, untyped]?
|
|
62
|
+
|
|
63
|
+
@repository: Repository?
|
|
64
|
+
|
|
65
|
+
# Initialize a new entry with the given repository.
|
|
66
|
+
#
|
|
67
|
+
# : (Repository repository) -> void
|
|
68
|
+
def initialize: (Repository repository) -> void
|
|
69
|
+
|
|
70
|
+
# Fetch the filepath of the value.
|
|
71
|
+
#
|
|
72
|
+
# : () -> String
|
|
73
|
+
def filepath: () -> String
|
|
74
|
+
|
|
75
|
+
# Fetch the start line of the value.
|
|
76
|
+
#
|
|
77
|
+
# : () -> Integer
|
|
78
|
+
def start_line: () -> Integer
|
|
79
|
+
|
|
80
|
+
# Fetch the end line of the value.
|
|
81
|
+
#
|
|
82
|
+
# : () -> Integer
|
|
83
|
+
def end_line: () -> Integer
|
|
84
|
+
|
|
85
|
+
# Fetch the start byte offset of the value.
|
|
86
|
+
#
|
|
87
|
+
# : () -> Integer
|
|
88
|
+
def start_offset: () -> Integer
|
|
89
|
+
|
|
90
|
+
# Fetch the end byte offset of the value.
|
|
91
|
+
#
|
|
92
|
+
# : () -> Integer
|
|
93
|
+
def end_offset: () -> Integer
|
|
94
|
+
|
|
95
|
+
# Fetch the start character offset of the value.
|
|
96
|
+
#
|
|
97
|
+
# : () -> Integer
|
|
98
|
+
def start_character_offset: () -> Integer
|
|
99
|
+
|
|
100
|
+
# Fetch the end character offset of the value.
|
|
101
|
+
#
|
|
102
|
+
# : () -> Integer
|
|
103
|
+
def end_character_offset: () -> Integer
|
|
104
|
+
|
|
105
|
+
# Fetch the start code units offset of the value, for the encoding that
|
|
106
|
+
# was configured on the repository.
|
|
107
|
+
#
|
|
108
|
+
# : () -> Integer
|
|
109
|
+
def start_code_units_offset: () -> Integer
|
|
110
|
+
|
|
111
|
+
# Fetch the end code units offset of the value, for the encoding that was
|
|
112
|
+
# configured on the repository.
|
|
113
|
+
#
|
|
114
|
+
# : () -> Integer
|
|
115
|
+
def end_code_units_offset: () -> Integer
|
|
116
|
+
|
|
117
|
+
# Fetch the start byte column of the value.
|
|
118
|
+
#
|
|
119
|
+
# : () -> Integer
|
|
120
|
+
def start_column: () -> Integer
|
|
121
|
+
|
|
122
|
+
# Fetch the end byte column of the value.
|
|
123
|
+
#
|
|
124
|
+
# : () -> Integer
|
|
125
|
+
def end_column: () -> Integer
|
|
126
|
+
|
|
127
|
+
# Fetch the start character column of the value.
|
|
128
|
+
#
|
|
129
|
+
# : () -> Integer
|
|
130
|
+
def start_character_column: () -> Integer
|
|
131
|
+
|
|
132
|
+
# Fetch the end character column of the value.
|
|
133
|
+
#
|
|
134
|
+
# : () -> Integer
|
|
135
|
+
def end_character_column: () -> Integer
|
|
136
|
+
|
|
137
|
+
# Fetch the start code units column of the value, for the encoding that
|
|
138
|
+
# was configured on the repository.
|
|
139
|
+
#
|
|
140
|
+
# : () -> Integer
|
|
141
|
+
def start_code_units_column: () -> Integer
|
|
142
|
+
|
|
143
|
+
# Fetch the end code units column of the value, for the encoding that was
|
|
144
|
+
# configured on the repository.
|
|
145
|
+
#
|
|
146
|
+
# : () -> Integer
|
|
147
|
+
def end_code_units_column: () -> Integer
|
|
148
|
+
|
|
149
|
+
# Reify the values on this entry with the given values. This is an
|
|
150
|
+
# internal-only API that is called from the repository when it is time to
|
|
151
|
+
# reify the values.
|
|
152
|
+
#
|
|
153
|
+
# : (entry_values values) -> void
|
|
154
|
+
def reify!: (entry_values values) -> void
|
|
155
|
+
|
|
156
|
+
private
|
|
157
|
+
|
|
158
|
+
# Fetch a value from the entry, raising an error if it is missing.
|
|
159
|
+
#
|
|
160
|
+
# : (Symbol name) -> entry_value
|
|
161
|
+
def fetch_value: (Symbol name) -> entry_value
|
|
162
|
+
|
|
163
|
+
# Return the values from the repository, reifying them if necessary.
|
|
164
|
+
#
|
|
165
|
+
# : () -> entry_values
|
|
166
|
+
def values: () -> entry_values
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# Represents the source of a repository that will be reparsed.
|
|
170
|
+
class Source
|
|
171
|
+
# The value that will need to be reparsed.
|
|
172
|
+
attr_reader value: untyped
|
|
173
|
+
|
|
174
|
+
# Initialize the source with the given value.
|
|
175
|
+
#
|
|
176
|
+
# : (untyped value) -> void
|
|
177
|
+
def initialize: (untyped value) -> void
|
|
178
|
+
|
|
179
|
+
# Reparse the value and return the parse result.
|
|
180
|
+
#
|
|
181
|
+
# : () -> ParseResult
|
|
182
|
+
def result: () -> ParseResult
|
|
183
|
+
|
|
184
|
+
# Create a code units cache for the given encoding.
|
|
185
|
+
#
|
|
186
|
+
# : (Encoding encoding) -> _CodeUnitsCache
|
|
187
|
+
def code_units_cache: (Encoding encoding) -> _CodeUnitsCache
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# A source that is represented by a file path.
|
|
191
|
+
class SourceFilepath < Source
|
|
192
|
+
# Reparse the file and return the parse result.
|
|
193
|
+
#
|
|
194
|
+
# : () -> ParseResult
|
|
195
|
+
def result: () -> ParseResult
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
# A source that is represented by a string.
|
|
199
|
+
class SourceString < Source
|
|
200
|
+
# Reparse the string and return the parse result.
|
|
201
|
+
#
|
|
202
|
+
# : () -> ParseResult
|
|
203
|
+
def result: () -> ParseResult
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
# A field that represents the file path.
|
|
207
|
+
class FilepathField
|
|
208
|
+
# The file path that this field represents.
|
|
209
|
+
attr_reader value: String
|
|
210
|
+
|
|
211
|
+
# Initialize a new field with the given file path.
|
|
212
|
+
#
|
|
213
|
+
# : (String value) -> void
|
|
214
|
+
def initialize: (String value) -> void
|
|
215
|
+
|
|
216
|
+
# Fetch the file path.
|
|
217
|
+
#
|
|
218
|
+
# : (_Value _value) -> entry_values
|
|
219
|
+
def fields: (_Value _value) -> entry_values
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
# A field representing the start and end lines.
|
|
223
|
+
class LinesField
|
|
224
|
+
# Fetches the start and end line of a value.
|
|
225
|
+
#
|
|
226
|
+
# : (_Value value) -> entry_values
|
|
227
|
+
def fields: (_Value value) -> entry_values
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
# A field representing the start and end byte offsets.
|
|
231
|
+
class OffsetsField
|
|
232
|
+
# Fetches the start and end byte offset of a value.
|
|
233
|
+
#
|
|
234
|
+
# : (_Value value) -> entry_values
|
|
235
|
+
def fields: (_Value value) -> entry_values
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
# A field representing the start and end character offsets.
|
|
239
|
+
class CharacterOffsetsField
|
|
240
|
+
# Fetches the start and end character offset of a value.
|
|
241
|
+
#
|
|
242
|
+
# : (_Value value) -> entry_values
|
|
243
|
+
def fields: (_Value value) -> entry_values
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
# A field representing the start and end code unit offsets.
|
|
247
|
+
class CodeUnitOffsetsField
|
|
248
|
+
# A pointer to the repository object that is used for lazily creating a
|
|
249
|
+
# code units cache.
|
|
250
|
+
attr_reader repository: Repository
|
|
251
|
+
|
|
252
|
+
# The associated encoding for the code units.
|
|
253
|
+
attr_reader encoding: Encoding
|
|
254
|
+
|
|
255
|
+
@cache: _CodeUnitsCache?
|
|
256
|
+
|
|
257
|
+
# Initialize a new field with the associated repository and encoding.
|
|
258
|
+
#
|
|
259
|
+
# : (Repository repository, Encoding encoding) -> void
|
|
260
|
+
def initialize: (Repository repository, Encoding encoding) -> void
|
|
261
|
+
|
|
262
|
+
# Fetches the start and end code units offset of a value for a particular
|
|
263
|
+
# encoding.
|
|
264
|
+
#
|
|
265
|
+
# : (_Value value) -> entry_values
|
|
266
|
+
def fields: (_Value value) -> entry_values
|
|
267
|
+
|
|
268
|
+
private
|
|
269
|
+
|
|
270
|
+
# Lazily create a code units cache for the associated encoding.
|
|
271
|
+
#
|
|
272
|
+
# : () -> _CodeUnitsCache
|
|
273
|
+
def cache: () -> _CodeUnitsCache
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
# A field representing the start and end byte columns.
|
|
277
|
+
class ColumnsField
|
|
278
|
+
# Fetches the start and end byte column of a value.
|
|
279
|
+
#
|
|
280
|
+
# : (_Value value) -> entry_values
|
|
281
|
+
def fields: (_Value value) -> entry_values
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
# A field representing the start and end character columns.
|
|
285
|
+
class CharacterColumnsField
|
|
286
|
+
# Fetches the start and end character column of a value.
|
|
287
|
+
#
|
|
288
|
+
# : (_Value value) -> entry_values
|
|
289
|
+
def fields: (_Value value) -> entry_values
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
# A field representing the start and end code unit columns for a specific
|
|
293
|
+
# encoding.
|
|
294
|
+
class CodeUnitColumnsField
|
|
295
|
+
# The repository object that is used for lazily creating a code units
|
|
296
|
+
# cache.
|
|
297
|
+
attr_reader repository: Repository
|
|
298
|
+
|
|
299
|
+
# The associated encoding for the code units.
|
|
300
|
+
attr_reader encoding: Encoding
|
|
301
|
+
|
|
302
|
+
@cache: _CodeUnitsCache?
|
|
303
|
+
|
|
304
|
+
# Initialize a new field with the associated repository and encoding.
|
|
305
|
+
#
|
|
306
|
+
# : (Repository repository, Encoding encoding) -> void
|
|
307
|
+
def initialize: (Repository repository, Encoding encoding) -> void
|
|
308
|
+
|
|
309
|
+
# Fetches the start and end code units column of a value for a particular
|
|
310
|
+
# encoding.
|
|
311
|
+
#
|
|
312
|
+
# : (_Value value) -> entry_values
|
|
313
|
+
def fields: (_Value value) -> entry_values
|
|
314
|
+
|
|
315
|
+
private
|
|
316
|
+
|
|
317
|
+
# Lazily create a code units cache for the associated encoding.
|
|
318
|
+
#
|
|
319
|
+
# : () -> _CodeUnitsCache
|
|
320
|
+
def cache: () -> _CodeUnitsCache
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
# A repository is a configured collection of fields and a set of entries
|
|
324
|
+
# that knows how to reparse a source and reify the values.
|
|
325
|
+
class Repository
|
|
326
|
+
# Raised when multiple fields of the same type are configured on the same
|
|
327
|
+
# repository.
|
|
328
|
+
class ConfigurationError < StandardError
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
# The source associated with this repository. This will be either a
|
|
332
|
+
# SourceFilepath (the most common use case) or a SourceString.
|
|
333
|
+
attr_reader source: Source
|
|
334
|
+
|
|
335
|
+
# The fields that have been configured on this repository.
|
|
336
|
+
attr_reader fields: Hash[Symbol, _Field]
|
|
337
|
+
|
|
338
|
+
# The entries that have been saved on this repository.
|
|
339
|
+
attr_reader entries: Hash[Integer, Hash[Symbol, Entry]]
|
|
340
|
+
|
|
341
|
+
# Initialize a new repository with the given source.
|
|
342
|
+
#
|
|
343
|
+
# : (Source source) -> void
|
|
344
|
+
def initialize: (Source source) -> void
|
|
345
|
+
|
|
346
|
+
# Create a code units cache for the given encoding from the source.
|
|
347
|
+
#
|
|
348
|
+
# : (Encoding encoding) -> _CodeUnitsCache
|
|
349
|
+
def code_units_cache: (Encoding encoding) -> _CodeUnitsCache
|
|
350
|
+
|
|
351
|
+
# Configure the filepath field for this repository and return self.
|
|
352
|
+
#
|
|
353
|
+
# : () -> self
|
|
354
|
+
def filepath: () -> self
|
|
355
|
+
|
|
356
|
+
# Configure the lines field for this repository and return self.
|
|
357
|
+
#
|
|
358
|
+
# : () -> self
|
|
359
|
+
def lines: () -> self
|
|
360
|
+
|
|
361
|
+
# Configure the offsets field for this repository and return self.
|
|
362
|
+
#
|
|
363
|
+
# : () -> self
|
|
364
|
+
def offsets: () -> self
|
|
365
|
+
|
|
366
|
+
# Configure the character offsets field for this repository and return
|
|
367
|
+
# self.
|
|
368
|
+
#
|
|
369
|
+
# : () -> self
|
|
370
|
+
def character_offsets: () -> self
|
|
371
|
+
|
|
372
|
+
# Configure the code unit offsets field for this repository for a specific
|
|
373
|
+
# encoding and return self.
|
|
374
|
+
#
|
|
375
|
+
# : (Encoding encoding) -> self
|
|
376
|
+
def code_unit_offsets: (Encoding encoding) -> self
|
|
377
|
+
|
|
378
|
+
# Configure the columns field for this repository and return self.
|
|
379
|
+
#
|
|
380
|
+
# : () -> self
|
|
381
|
+
def columns: () -> self
|
|
382
|
+
|
|
383
|
+
# Configure the character columns field for this repository and return
|
|
384
|
+
# self.
|
|
385
|
+
#
|
|
386
|
+
# : () -> self
|
|
387
|
+
def character_columns: () -> self
|
|
388
|
+
|
|
389
|
+
# Configure the code unit columns field for this repository for a specific
|
|
390
|
+
# encoding and return self.
|
|
391
|
+
#
|
|
392
|
+
# : (Encoding encoding) -> self
|
|
393
|
+
def code_unit_columns: (Encoding encoding) -> self
|
|
394
|
+
|
|
395
|
+
# This method is called from nodes and locations when they want to enter
|
|
396
|
+
# themselves into the repository. It it internal-only and meant to be
|
|
397
|
+
# called from the #save* APIs.
|
|
398
|
+
#
|
|
399
|
+
# : (Integer node_id, Symbol field_name) -> Entry
|
|
400
|
+
def enter: (Integer node_id, Symbol field_name) -> Entry
|
|
401
|
+
|
|
402
|
+
# This method is called from the entries in the repository when they need
|
|
403
|
+
# to reify their values. It is internal-only and meant to be called from
|
|
404
|
+
# the various value APIs.
|
|
405
|
+
#
|
|
406
|
+
# : () -> void
|
|
407
|
+
def reify!: () -> void
|
|
408
|
+
|
|
409
|
+
private
|
|
410
|
+
|
|
411
|
+
# Append the given field to the repository and return the repository so
|
|
412
|
+
# that these calls can be chained.
|
|
413
|
+
#
|
|
414
|
+
# : (Symbol name, _Field) -> self
|
|
415
|
+
def field: (Symbol name, _Field) -> self
|
|
416
|
+
end
|
|
417
|
+
|
|
418
|
+
# Create a new repository for the given filepath.
|
|
419
|
+
#
|
|
420
|
+
# : (String value) -> Repository
|
|
421
|
+
def self.filepath: (String value) -> Repository
|
|
422
|
+
|
|
423
|
+
# Create a new repository for the given string.
|
|
424
|
+
#
|
|
425
|
+
# : (String value) -> Repository
|
|
426
|
+
def self.string: (String value) -> Repository
|
|
427
|
+
end
|
|
428
|
+
end
|