A cache that can be used to quickly compute code unit offsets from byte offsets. It purposefully provides only a single []
method to access the cache in order to minimize surface area.
Note that there are some known issues here that may or may not be addressed in the future:
The first is that there are issues when the cache computes values that are not on character boundaries. This can result in subsequent computations being off by one or more code units.
The second is that this cache is currently unbounded. In theory we could introduce some kind of LRU cache to limit the number of entries, but this has not yet been implemented.
This represents a location in the source.
This represents a magic comment that was encountered during parsing.
A pattern is an object that wraps a Ruby
pattern matching expression. The expression would normally be passed to an ‘in` clause within a `case` expression or a rightward assignment expression. For example, in the following snippet:
case node in ConstantPathNode[ConstantReadNode[name: :Prism], ConstantReadNode[name: :Pattern]] end
the pattern is the ConstantPathNode[...]
expression.
The pattern gets compiled into an object that responds to call by running the compile
method. This method itself will run back through Prism
to parse the expression into a tree, then walk the tree to generate the necessary callable objects. For example, if you wanted to compile the expression above into a callable, you would:
callable = Prism::Pattern.new("ConstantPathNode[ConstantReadNode[name: :Prism], ConstantReadNode[name: :Pattern]]").compile callable.call(node)
The callable object returned by compile
is guaranteed to respond to call with a single argument, which is the node to match against. It also is guaranteed to respond to ===
, which means it itself can be used in a ‘case` expression, as in:
case node when callable end
If the query given to the initializer cannot be compiled into a valid matcher (either because of a syntax error or because it is using syntax we do not yet support) then a Prism::Pattern::CompilationError
will be raised.
BasicSpecification
is an abstract class which implements some common code used by both Specification and StubSpecification.
Base class for all Gem
commands. When creating a new gem command, define initialize, execute
, arguments
, defaults_str
, description
and usage
(as appropriate). See the above mentioned methods for details.
A very good example to look at is Gem::Commands::ContentsCommand