prism 2.0.0.rc1-x86_64-linux-gnu
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.so +0 -0
- data/lib/prism/3.4/prism.so +0 -0
- data/lib/prism/4.0/prism.so +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,134 @@
|
|
|
1
|
+
# typed: true
|
|
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
|
+
sig { params(repr: String).void }
|
|
44
|
+
def initialize(repr); end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# The query that this pattern was initialized with.
|
|
48
|
+
sig { returns(String) }
|
|
49
|
+
attr_reader :query
|
|
50
|
+
|
|
51
|
+
# Create a new pattern with the given query. The query should be a string
|
|
52
|
+
# containing a Ruby pattern matching expression.
|
|
53
|
+
sig { params(query: String).void }
|
|
54
|
+
def initialize(query); end
|
|
55
|
+
|
|
56
|
+
# Compile the query into a callable object that can be used to match against
|
|
57
|
+
# nodes.
|
|
58
|
+
sig { returns(Proc) }
|
|
59
|
+
def compile; end
|
|
60
|
+
|
|
61
|
+
# Scan the given node and all of its children for nodes that match the
|
|
62
|
+
# pattern. If a block is given, it will be called with each node that
|
|
63
|
+
# matches the pattern. If no block is given, an enumerator will be returned
|
|
64
|
+
# that will yield each node that matches the pattern.
|
|
65
|
+
sig { params(root: Node).returns(T::Enumerator[Node]) }
|
|
66
|
+
sig { params(root: Node, blk: ::T.proc.params(arg0: Node).void).void }
|
|
67
|
+
def scan(root, &blk); end
|
|
68
|
+
|
|
69
|
+
# Shortcut for combining two procs into one that returns true if both return
|
|
70
|
+
# true.
|
|
71
|
+
sig { params(left: Proc, right: Proc).returns(Proc) }
|
|
72
|
+
private def combine_and(left, right); end
|
|
73
|
+
|
|
74
|
+
# Shortcut for combining two procs into one that returns true if either
|
|
75
|
+
# returns true.
|
|
76
|
+
sig { params(left: Proc, right: Proc).returns(Proc) }
|
|
77
|
+
private def combine_or(left, right); end
|
|
78
|
+
|
|
79
|
+
# Raise an error because the given node is not supported. Note purposefully
|
|
80
|
+
# not typing this method since it is a no return method that Steep does not
|
|
81
|
+
# understand.
|
|
82
|
+
sig { params(node: Node).returns(::T.noreturn) }
|
|
83
|
+
private def compile_error(node); end
|
|
84
|
+
|
|
85
|
+
# in [foo, bar, baz]
|
|
86
|
+
sig { params(node: ArrayPatternNode).returns(Proc) }
|
|
87
|
+
private def compile_array_pattern_node(node); end
|
|
88
|
+
|
|
89
|
+
# in foo | bar
|
|
90
|
+
sig { params(node: AlternationPatternNode).returns(Proc) }
|
|
91
|
+
private def compile_alternation_pattern_node(node); end
|
|
92
|
+
|
|
93
|
+
# in Prism::ConstantReadNode
|
|
94
|
+
sig { params(node: ConstantPathNode).returns(Proc) }
|
|
95
|
+
private def compile_constant_path_node(node); end
|
|
96
|
+
|
|
97
|
+
# in ConstantReadNode
|
|
98
|
+
# in String
|
|
99
|
+
sig { params(node: ConstantReadNode).returns(Proc) }
|
|
100
|
+
private def compile_constant_read_node(node); end
|
|
101
|
+
|
|
102
|
+
# Compile a name associated with a constant.
|
|
103
|
+
sig { params(node: ::T.any(ConstantPathNode, ConstantReadNode), name: Symbol).returns(Proc) }
|
|
104
|
+
private def compile_constant_name(node, name); end
|
|
105
|
+
|
|
106
|
+
# in InstanceVariableReadNode[name: Symbol]
|
|
107
|
+
# in { name: Symbol }
|
|
108
|
+
sig { params(node: HashPatternNode).returns(Proc) }
|
|
109
|
+
private def compile_hash_pattern_node(node); end
|
|
110
|
+
|
|
111
|
+
# in nil
|
|
112
|
+
sig { params(node: NilNode).returns(Proc) }
|
|
113
|
+
private def compile_nil_node(node); end
|
|
114
|
+
|
|
115
|
+
# in /foo/
|
|
116
|
+
sig { params(node: RegularExpressionNode).returns(Proc) }
|
|
117
|
+
private def compile_regular_expression_node(node); end
|
|
118
|
+
|
|
119
|
+
# in ""
|
|
120
|
+
# in "foo"
|
|
121
|
+
sig { params(node: StringNode).returns(Proc) }
|
|
122
|
+
private def compile_string_node(node); end
|
|
123
|
+
|
|
124
|
+
# in :+
|
|
125
|
+
# in :foo
|
|
126
|
+
sig { params(node: SymbolNode).returns(Proc) }
|
|
127
|
+
private def compile_symbol_node(node); end
|
|
128
|
+
|
|
129
|
+
# Compile any kind of node. Dispatch out to the individual compilation
|
|
130
|
+
# methods based on the type of node.
|
|
131
|
+
sig { params(node: Node).returns(Proc) }
|
|
132
|
+
private def compile_node(node); end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# typed: true
|
|
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
|
+
sig { returns(Symbol) }
|
|
13
|
+
attr_reader :name
|
|
14
|
+
|
|
15
|
+
# Initializes the field with the given name.
|
|
16
|
+
sig { params(name: Symbol).void }
|
|
17
|
+
def initialize(name); end
|
|
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; end
|
|
23
|
+
|
|
24
|
+
# An optional node field represents a single child node in the syntax tree
|
|
25
|
+
# that may or may not be present. It resolves to either a Prism::Node or nil
|
|
26
|
+
# in Ruby.
|
|
27
|
+
class OptionalNodeField < Field; end
|
|
28
|
+
|
|
29
|
+
# A node list field represents a list of child nodes in the syntax tree. It
|
|
30
|
+
# resolves to an array of Prism::Node instances in Ruby.
|
|
31
|
+
class NodeListField < Field; end
|
|
32
|
+
|
|
33
|
+
# A constant field represents a constant value on a node. Effectively, it
|
|
34
|
+
# represents an identifier found within the source. It resolves to a symbol
|
|
35
|
+
# in Ruby.
|
|
36
|
+
class ConstantField < Field; end
|
|
37
|
+
|
|
38
|
+
# An optional constant field represents a constant value on a node that may
|
|
39
|
+
# or may not be present. It resolves to either a symbol or nil in Ruby.
|
|
40
|
+
class OptionalConstantField < Field; end
|
|
41
|
+
|
|
42
|
+
# A constant list field represents a list of constant values on a node. It
|
|
43
|
+
# resolves to an array of symbols in Ruby.
|
|
44
|
+
class ConstantListField < Field; end
|
|
45
|
+
|
|
46
|
+
# A string field represents a string value on a node. It almost always
|
|
47
|
+
# represents the unescaped value of a string-like literal. It resolves to a
|
|
48
|
+
# string in Ruby.
|
|
49
|
+
class StringField < Field; end
|
|
50
|
+
|
|
51
|
+
# A location field represents the location of some part of the node in the
|
|
52
|
+
# source code. For example, the location of a keyword or an operator. It
|
|
53
|
+
# resolves to a Prism::Location in Ruby.
|
|
54
|
+
class LocationField < Field; end
|
|
55
|
+
|
|
56
|
+
# An optional location field represents the location of some part of the
|
|
57
|
+
# node in the source code that may or may not be present. It resolves to
|
|
58
|
+
# either a Prism::Location or nil in Ruby.
|
|
59
|
+
class OptionalLocationField < Field; end
|
|
60
|
+
|
|
61
|
+
# An integer field represents an integer value. It is used to represent the
|
|
62
|
+
# value of an integer literal, the depth of local variables, and the number
|
|
63
|
+
# of a numbered reference. It resolves to an Integer in Ruby.
|
|
64
|
+
class IntegerField < Field; end
|
|
65
|
+
|
|
66
|
+
# A float field represents a double-precision floating point value. It is
|
|
67
|
+
# used exclusively to represent the value of a floating point literal. It
|
|
68
|
+
# resolves to a Float in Ruby.
|
|
69
|
+
class FloatField < Field; end
|
|
70
|
+
|
|
71
|
+
# A flags field represents a bitset of flags on a node. It resolves to an
|
|
72
|
+
# integer in Ruby. Note that the flags cannot be accessed directly on the
|
|
73
|
+
# node because the integer is kept private. Instead, the various flags in
|
|
74
|
+
# the bitset should be accessed through their query methods.
|
|
75
|
+
class FlagsField < Field
|
|
76
|
+
# The names of the flags in the bitset.
|
|
77
|
+
sig { returns(T::Array[Symbol]) }
|
|
78
|
+
attr_reader :flags
|
|
79
|
+
|
|
80
|
+
# Initializes the flags field with the given name and flags.
|
|
81
|
+
sig { params(name: Symbol, flags: T::Array[Symbol]).void }
|
|
82
|
+
def initialize(name, flags); end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Returns the fields for the given node.
|
|
86
|
+
sig { params(node: ::T.class_of(Node)).returns(T::Array[Field]) }
|
|
87
|
+
def self.fields_for(node); end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
# typed: true
|
|
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
|
+
# An entry in a repository that will lazily reify its values when they are
|
|
15
|
+
# first accessed.
|
|
16
|
+
class Entry
|
|
17
|
+
# Raised if a value that could potentially be on an entry is missing
|
|
18
|
+
# because it was either not configured on the repository or it has not yet
|
|
19
|
+
# been fetched.
|
|
20
|
+
class MissingValueError < StandardError; end
|
|
21
|
+
|
|
22
|
+
# Initialize a new entry with the given repository.
|
|
23
|
+
sig { params(repository: Repository).void }
|
|
24
|
+
def initialize(repository); end
|
|
25
|
+
|
|
26
|
+
# Fetch the filepath of the value.
|
|
27
|
+
sig { returns(String) }
|
|
28
|
+
def filepath; end
|
|
29
|
+
|
|
30
|
+
# Fetch the start line of the value.
|
|
31
|
+
sig { returns(Integer) }
|
|
32
|
+
def start_line; end
|
|
33
|
+
|
|
34
|
+
# Fetch the end line of the value.
|
|
35
|
+
sig { returns(Integer) }
|
|
36
|
+
def end_line; end
|
|
37
|
+
|
|
38
|
+
# Fetch the start byte offset of the value.
|
|
39
|
+
sig { returns(Integer) }
|
|
40
|
+
def start_offset; end
|
|
41
|
+
|
|
42
|
+
# Fetch the end byte offset of the value.
|
|
43
|
+
sig { returns(Integer) }
|
|
44
|
+
def end_offset; end
|
|
45
|
+
|
|
46
|
+
# Fetch the start character offset of the value.
|
|
47
|
+
sig { returns(Integer) }
|
|
48
|
+
def start_character_offset; end
|
|
49
|
+
|
|
50
|
+
# Fetch the end character offset of the value.
|
|
51
|
+
sig { returns(Integer) }
|
|
52
|
+
def end_character_offset; end
|
|
53
|
+
|
|
54
|
+
# Fetch the start code units offset of the value, for the encoding that
|
|
55
|
+
# was configured on the repository.
|
|
56
|
+
sig { returns(Integer) }
|
|
57
|
+
def start_code_units_offset; end
|
|
58
|
+
|
|
59
|
+
# Fetch the end code units offset of the value, for the encoding that was
|
|
60
|
+
# configured on the repository.
|
|
61
|
+
sig { returns(Integer) }
|
|
62
|
+
def end_code_units_offset; end
|
|
63
|
+
|
|
64
|
+
# Fetch the start byte column of the value.
|
|
65
|
+
sig { returns(Integer) }
|
|
66
|
+
def start_column; end
|
|
67
|
+
|
|
68
|
+
# Fetch the end byte column of the value.
|
|
69
|
+
sig { returns(Integer) }
|
|
70
|
+
def end_column; end
|
|
71
|
+
|
|
72
|
+
# Fetch the start character column of the value.
|
|
73
|
+
sig { returns(Integer) }
|
|
74
|
+
def start_character_column; end
|
|
75
|
+
|
|
76
|
+
# Fetch the end character column of the value.
|
|
77
|
+
sig { returns(Integer) }
|
|
78
|
+
def end_character_column; end
|
|
79
|
+
|
|
80
|
+
# Fetch the start code units column of the value, for the encoding that
|
|
81
|
+
# was configured on the repository.
|
|
82
|
+
sig { returns(Integer) }
|
|
83
|
+
def start_code_units_column; end
|
|
84
|
+
|
|
85
|
+
# Fetch the end code units column of the value, for the encoding that was
|
|
86
|
+
# configured on the repository.
|
|
87
|
+
sig { returns(Integer) }
|
|
88
|
+
def end_code_units_column; end
|
|
89
|
+
|
|
90
|
+
# Reify the values on this entry with the given values. This is an
|
|
91
|
+
# internal-only API that is called from the repository when it is time to
|
|
92
|
+
# reify the values.
|
|
93
|
+
sig { params(values: T::Hash[Symbol, ::T.untyped]).void }
|
|
94
|
+
def reify!(values); end
|
|
95
|
+
|
|
96
|
+
# Fetch a value from the entry, raising an error if it is missing.
|
|
97
|
+
sig { params(name: Symbol).returns(::T.untyped) }
|
|
98
|
+
private def fetch_value(name); end
|
|
99
|
+
|
|
100
|
+
# Return the values from the repository, reifying them if necessary.
|
|
101
|
+
sig { returns(T::Hash[Symbol, ::T.untyped]) }
|
|
102
|
+
private def values; end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Represents the source of a repository that will be reparsed.
|
|
106
|
+
class Source
|
|
107
|
+
# The value that will need to be reparsed.
|
|
108
|
+
sig { returns(::T.untyped) }
|
|
109
|
+
attr_reader :value
|
|
110
|
+
|
|
111
|
+
# Initialize the source with the given value.
|
|
112
|
+
sig { params(value: ::T.untyped).void }
|
|
113
|
+
def initialize(value); end
|
|
114
|
+
|
|
115
|
+
# Reparse the value and return the parse result.
|
|
116
|
+
sig { returns(ParseResult) }
|
|
117
|
+
def result; end
|
|
118
|
+
|
|
119
|
+
# Create a code units cache for the given encoding.
|
|
120
|
+
sig { params(encoding: Encoding).returns(::T.untyped) }
|
|
121
|
+
def code_units_cache(encoding); end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# A source that is represented by a file path.
|
|
125
|
+
class SourceFilepath < Source
|
|
126
|
+
# Reparse the file and return the parse result.
|
|
127
|
+
sig { returns(ParseResult) }
|
|
128
|
+
def result; end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# A source that is represented by a string.
|
|
132
|
+
class SourceString < Source
|
|
133
|
+
# Reparse the string and return the parse result.
|
|
134
|
+
sig { returns(ParseResult) }
|
|
135
|
+
def result; end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# A field that represents the file path.
|
|
139
|
+
class FilepathField
|
|
140
|
+
# The file path that this field represents.
|
|
141
|
+
sig { returns(String) }
|
|
142
|
+
attr_reader :value
|
|
143
|
+
|
|
144
|
+
# Initialize a new field with the given file path.
|
|
145
|
+
sig { params(value: String).void }
|
|
146
|
+
def initialize(value); end
|
|
147
|
+
|
|
148
|
+
# Fetch the file path.
|
|
149
|
+
sig { params(_value: ::T.untyped).returns(T::Hash[Symbol, ::T.untyped]) }
|
|
150
|
+
def fields(_value); end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# A field representing the start and end lines.
|
|
154
|
+
class LinesField
|
|
155
|
+
# Fetches the start and end line of a value.
|
|
156
|
+
sig { params(value: ::T.untyped).returns(T::Hash[Symbol, ::T.untyped]) }
|
|
157
|
+
def fields(value); end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# A field representing the start and end byte offsets.
|
|
161
|
+
class OffsetsField
|
|
162
|
+
# Fetches the start and end byte offset of a value.
|
|
163
|
+
sig { params(value: ::T.untyped).returns(T::Hash[Symbol, ::T.untyped]) }
|
|
164
|
+
def fields(value); end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# A field representing the start and end character offsets.
|
|
168
|
+
class CharacterOffsetsField
|
|
169
|
+
# Fetches the start and end character offset of a value.
|
|
170
|
+
sig { params(value: ::T.untyped).returns(T::Hash[Symbol, ::T.untyped]) }
|
|
171
|
+
def fields(value); end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
# A field representing the start and end code unit offsets.
|
|
175
|
+
class CodeUnitOffsetsField
|
|
176
|
+
# A pointer to the repository object that is used for lazily creating a
|
|
177
|
+
# code units cache.
|
|
178
|
+
sig { returns(Repository) }
|
|
179
|
+
attr_reader :repository
|
|
180
|
+
|
|
181
|
+
# The associated encoding for the code units.
|
|
182
|
+
sig { returns(Encoding) }
|
|
183
|
+
attr_reader :encoding
|
|
184
|
+
|
|
185
|
+
# Initialize a new field with the associated repository and encoding.
|
|
186
|
+
sig { params(repository: Repository, encoding: Encoding).void }
|
|
187
|
+
def initialize(repository, encoding); end
|
|
188
|
+
|
|
189
|
+
# Fetches the start and end code units offset of a value for a particular
|
|
190
|
+
# encoding.
|
|
191
|
+
sig { params(value: ::T.untyped).returns(T::Hash[Symbol, ::T.untyped]) }
|
|
192
|
+
def fields(value); end
|
|
193
|
+
|
|
194
|
+
# Lazily create a code units cache for the associated encoding.
|
|
195
|
+
sig { returns(::T.untyped) }
|
|
196
|
+
private def cache; end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
# A field representing the start and end byte columns.
|
|
200
|
+
class ColumnsField
|
|
201
|
+
# Fetches the start and end byte column of a value.
|
|
202
|
+
sig { params(value: ::T.untyped).returns(T::Hash[Symbol, ::T.untyped]) }
|
|
203
|
+
def fields(value); end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
# A field representing the start and end character columns.
|
|
207
|
+
class CharacterColumnsField
|
|
208
|
+
# Fetches the start and end character column of a value.
|
|
209
|
+
sig { params(value: ::T.untyped).returns(T::Hash[Symbol, ::T.untyped]) }
|
|
210
|
+
def fields(value); end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
# A field representing the start and end code unit columns for a specific
|
|
214
|
+
# encoding.
|
|
215
|
+
class CodeUnitColumnsField
|
|
216
|
+
# The repository object that is used for lazily creating a code units
|
|
217
|
+
# cache.
|
|
218
|
+
sig { returns(Repository) }
|
|
219
|
+
attr_reader :repository
|
|
220
|
+
|
|
221
|
+
# The associated encoding for the code units.
|
|
222
|
+
sig { returns(Encoding) }
|
|
223
|
+
attr_reader :encoding
|
|
224
|
+
|
|
225
|
+
# Initialize a new field with the associated repository and encoding.
|
|
226
|
+
sig { params(repository: Repository, encoding: Encoding).void }
|
|
227
|
+
def initialize(repository, encoding); end
|
|
228
|
+
|
|
229
|
+
# Fetches the start and end code units column of a value for a particular
|
|
230
|
+
# encoding.
|
|
231
|
+
sig { params(value: ::T.untyped).returns(T::Hash[Symbol, ::T.untyped]) }
|
|
232
|
+
def fields(value); end
|
|
233
|
+
|
|
234
|
+
# Lazily create a code units cache for the associated encoding.
|
|
235
|
+
sig { returns(::T.untyped) }
|
|
236
|
+
private def cache; end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
# A repository is a configured collection of fields and a set of entries
|
|
240
|
+
# that knows how to reparse a source and reify the values.
|
|
241
|
+
class Repository
|
|
242
|
+
# Raised when multiple fields of the same type are configured on the same
|
|
243
|
+
# repository.
|
|
244
|
+
class ConfigurationError < StandardError; end
|
|
245
|
+
|
|
246
|
+
# The source associated with this repository. This will be either a
|
|
247
|
+
# SourceFilepath (the most common use case) or a SourceString.
|
|
248
|
+
sig { returns(Source) }
|
|
249
|
+
attr_reader :source
|
|
250
|
+
|
|
251
|
+
# The fields that have been configured on this repository.
|
|
252
|
+
sig { returns(T::Hash[Symbol, ::T.untyped]) }
|
|
253
|
+
attr_reader :fields
|
|
254
|
+
|
|
255
|
+
# The entries that have been saved on this repository.
|
|
256
|
+
sig { returns(T::Hash[Integer, T::Hash[Symbol, Entry]]) }
|
|
257
|
+
attr_reader :entries
|
|
258
|
+
|
|
259
|
+
# Initialize a new repository with the given source.
|
|
260
|
+
sig { params(source: Source).void }
|
|
261
|
+
def initialize(source); end
|
|
262
|
+
|
|
263
|
+
# Create a code units cache for the given encoding from the source.
|
|
264
|
+
sig { params(encoding: Encoding).returns(::T.untyped) }
|
|
265
|
+
def code_units_cache(encoding); end
|
|
266
|
+
|
|
267
|
+
# Configure the filepath field for this repository and return self.
|
|
268
|
+
sig { returns(::T.self_type) }
|
|
269
|
+
def filepath; end
|
|
270
|
+
|
|
271
|
+
# Configure the lines field for this repository and return self.
|
|
272
|
+
sig { returns(::T.self_type) }
|
|
273
|
+
def lines; end
|
|
274
|
+
|
|
275
|
+
# Configure the offsets field for this repository and return self.
|
|
276
|
+
sig { returns(::T.self_type) }
|
|
277
|
+
def offsets; end
|
|
278
|
+
|
|
279
|
+
# Configure the character offsets field for this repository and return
|
|
280
|
+
# self.
|
|
281
|
+
sig { returns(::T.self_type) }
|
|
282
|
+
def character_offsets; end
|
|
283
|
+
|
|
284
|
+
# Configure the code unit offsets field for this repository for a specific
|
|
285
|
+
# encoding and return self.
|
|
286
|
+
sig { params(encoding: Encoding).returns(::T.self_type) }
|
|
287
|
+
def code_unit_offsets(encoding); end
|
|
288
|
+
|
|
289
|
+
# Configure the columns field for this repository and return self.
|
|
290
|
+
sig { returns(::T.self_type) }
|
|
291
|
+
def columns; end
|
|
292
|
+
|
|
293
|
+
# Configure the character columns field for this repository and return
|
|
294
|
+
# self.
|
|
295
|
+
sig { returns(::T.self_type) }
|
|
296
|
+
def character_columns; end
|
|
297
|
+
|
|
298
|
+
# Configure the code unit columns field for this repository for a specific
|
|
299
|
+
# encoding and return self.
|
|
300
|
+
sig { params(encoding: Encoding).returns(::T.self_type) }
|
|
301
|
+
def code_unit_columns(encoding); end
|
|
302
|
+
|
|
303
|
+
# This method is called from nodes and locations when they want to enter
|
|
304
|
+
# themselves into the repository. It it internal-only and meant to be
|
|
305
|
+
# called from the #save* APIs.
|
|
306
|
+
sig { params(node_id: Integer, field_name: Symbol).returns(Entry) }
|
|
307
|
+
def enter(node_id, field_name); end
|
|
308
|
+
|
|
309
|
+
# This method is called from the entries in the repository when they need
|
|
310
|
+
# to reify their values. It is internal-only and meant to be called from
|
|
311
|
+
# the various value APIs.
|
|
312
|
+
sig { void }
|
|
313
|
+
def reify!; end
|
|
314
|
+
|
|
315
|
+
# Append the given field to the repository and return the repository so
|
|
316
|
+
# that these calls can be chained.
|
|
317
|
+
sig { params(name: Symbol, arg0: ::T.untyped).returns(::T.self_type) }
|
|
318
|
+
private def field(name, arg0); end
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
# Create a new repository for the given filepath.
|
|
322
|
+
sig { params(value: String).returns(Repository) }
|
|
323
|
+
def self.filepath(value); end
|
|
324
|
+
|
|
325
|
+
# Create a new repository for the given string.
|
|
326
|
+
sig { params(value: String).returns(Repository) }
|
|
327
|
+
def self.string(value); end
|
|
328
|
+
end
|
|
329
|
+
end
|