struct Bindgen::Graph::Path

Overview

Pathing logic for the graph. See Path.local to find a locally-qualified path between two nodes. Or use .from to build a path from a string.

The structure doesn't store any origin by itself.

Defined in:

bindgen/graph/path.cr

Constructors

Instance Method Summary

Constructor Detail

def self.from(path : String) : Path #

Returns a new Path on path. Supports generic parts.

BUG Doesn't support nested generics, like Foo(Bar(Baz))::Quux.


[View source]
def self.from(path : Enumerable(String)) : Path #

ditto


[View source]
def self.from(path : Nil) : Path #

Returns a self-referencing path.


[View source]
def self.global(node : Graph::Node) : Path #

Returns the global path to node.


[View source]
def self.local(node : Graph::Node, wants : Graph::Node) : Path #

Finds the local path to go from node to wants, in terms of constant resolution for Crystal.

BUG Fails if Foo::Node, Foo::Wants and Foo::Node::Wants exist. The affected branches are marked with !!.


[View source]
def self.new(nodes : Nil | Array(String) = [] of String) #

[View source]

Instance Method Detail

def [](range : Range) : Path #

Returns the path parts in range. If #nodes is nil, the returneed path will also have a nil-#nodes.


[View source]
def global? #

Is this a global path?


[View source]
def inspect(io) #

Much like #to_s, but tells the user when this path points to itself.


[View source]
def last #

Returns the Path with only the last element in #nodes, thus pointing at the child in #parent.


[View source]
def last_part : String #

Returns the last element of #nodes itself. If #nodes is nil, raises.


[View source]
def local? #

Is this a local path? Also true if this is a #self? path.


[View source]
def lookup(base : Node) : Node | Nil #

Does a local look-up starting at base for path. The look-up will begin in base itself. If not found, it'll try to find the path by going up to the parent(s).

If the path starts with :: (An empty element), the look-up will always start at the global scope. If :: is given, the root node is returned. Otherwise, the first part of the path must be the name of the root node: ::RootNameHere::And::So::On instead of ::And::So::On.

If not found, returns nil. This method does not raise.


[View source]
def nodes : Array(String) | Nil #

Node path. If nil, the path points to itself.


[View source]
def parent #

Returns the Path excluding the last element in #nodes, thus pointing to the parent of this path.


[View source]
def self? #

Does this path point to itself?


[View source]
def to_global(base : Node) : Path #

Returns a global path from this local path, starting look-up at base. Does a full look-up under the hood, thus, the path has to be valid.

If this is already a #global? path, it is returned without further checks.


[View source]
def to_s(io) #

Gives the path as Crystal constants look-up path.


[View source]