package RakuAST::Name

Represent an identifier name
class RakuAST::Name { }

The RakuAST::Name class represents a name (usually an identifier, but not necessarily so), which consists of zero or more parts, and may have additional colonpair (adverb) specification(s).

Object introspection

RakuAST::Name objects are typically created when parsing Raku Programming Language code. So most developers will only need to know how to introspect the objects created.

These introspection methods are available (in alphabetical order):

base-name

dd $name.base-name;

The base-name method returns a clone of the given RakuAST::Name object, but with the last part removed if the last part is empty.

canonicalize

say $name.canonicalize;

The canonicalize returns a string representing the given RakuAST::Name object, or dies when it is impossible to create a string because there are still unresolved parts.

colonpairs

.say for $name.colonpairs;

The colonpairs method returns the "colonpairs" (aka "adverbs") of the RakuAST::Name object as RakuAST::ColonPair objects. For an identifier such as JSON::Fast:ver<0.21>:auth<zef:timo>, it would return RakuAST::ColonPair objects for :ver<0.21> and :auth<zef:timo>.

first-colonpair

dd $name.first-colonpair("ver");

The first-colonpair method returns the first RakuAST::ColonPair::xxx object that matches the given name. Else it returns False.

first-part

say $name.first-part;

The first-part method returns the first "name" part of the RakuAST::Name object as a RakuAST::Name::Part object. For an identifier such as "IO::Path", it would return a RakuAST::Name::Part::Simple object representing "IO".

has-colonpair

say $name.has-colonpair("ver");  # True or False

The has-colonpair method returns True if there is at least one colonpair that has the given name. Else it returns False.

has-colonpairs

say $name.has-colonpairs;  # True or False

The has-colonpairs method returns True if there either are any colonpairs in the RakuAST::Name object. Else it returns False.

is-anonymous

say $name.is-anonymous;  # True or False

The is-anonymous method returns True if there either are two parts and both are empty. Else it returns False.

is-empty

say $name.is-empty;  # True or False

The is-empty method returns True if there either are no parts, or the only part is empty. Else it returns False.

is-global-lookup

say $name.is-global-lookup;  # True or False

The is-global-lookup method returns True if the first part is a RakuAST::Name::Part::Simple object, and its name is "GLOBAL". Else it returns False.

is-identifier

say $name.is-identifier;  # True or False

The is-identifier method returns True if the name can be considered a valid identifier. Else it returns False.

is-indirect-lookup

say $name.is-indirect-lookup;  # True or False

The is-indirect-lookup method returns True if any part of the RakuAST::Name object is a RakuAST::Name::Part::Expression object. Else it returns False.

is-installable

say $name.is-installable;  # True or False

The is-installable method returns True if the name can be considered a valid, installable identifier. Else it returns False.

is-multi-part

say $name.is-multi-part;  # True or False

The is-multi-part method returns True if there is more than one non-empty part in the RakuAST::Name object. Else it returns False.

is-package-lookup

say $name.is-package-lookup;  # True or False

The is-package-lookup method returns True if the last part is a RakuAST::Name::Part::EmptyEdge part. Else it returns False.

say $name.is-package-search;  # True or False

The is-package-search method returns True if the first part is a RakuAST::Name::Part::EmptyEdge part. Else it returns False.

is-pseudo-package

say $name.is-pseudo-package;  # True or False

The is-pseudo-package method returns True if the RakuAST::Name object represents a pseudo-package. Else it returns False.

is-simple

say $name.is-simple;  # True or False

The is-simple method returns False if there is any non-RakuAST::Name::Part::Simple part. Else it returns True.

last-part

say $name.last-part;

The last-part method returns the last "name" part of the RakuAST::Name object as a RakuAST::Name::Part object. For an identifier such as "IO::Path", it would return a RakuAST::Name::Part::Simple object representing "Path".

parts

.say for $name.parts;

The parts method returns the "name" parts of the RakuAST::Name object as RakuAST::Name::Part objects. For an identifier such as "IO::Path", it would return RakuAST::Name::Part::Simple objects for "IO" and "Path".

root-part

say $name.root-part;

The root-part method returns the root "name" part of the RakuAST::Name object as a RakuAST::Name::Part object. It only differs from first-part if the first part of the name is empty. For an identifier such as "::Foo", it would return a RakuAST::Name::Part::Simple object representing "Foo".

simple-identifier

if $name.simple-identifier -> $identifier {
    say $identifier;
}
else {
    say "not a simple identifier";
}

The simple-identifier method returns the string of a simple one-part identifier, or the empty string.

without-colonpair

my $without = $name.without-colonpair("ver");

The without-colonpair method returns a clone of the given RakuAST::Name object without any RakuAST::ColonPair::xxx object that matches the given name.

without-first-part

my $without = $name.without-first-part;

The without-colonpair method returns a clone of the given RakuAST::Name object without the first part.

first-part

say $name.first-part;

The first-part method returns the first "name" part of the RakuAST::Name object as a RakuAST::Name::Part object. For an identifier such as "IO::Path", it would return a RakuAST::Name::Part::Simple object representing "IO".

has-colonpair

say $name.has-colonpair("ver");  # True or False

The has-colonpair method returns True if there is at least one colonpair that has the given name. Else it returns False.

has-colonpairs

say $name.has-colonpairs;  # True or False

The has-colonpairs method returns True if there either are any colonpairs in the RakuAST::Name object. Else it returns False.

is-anonymous

say $name.is-anonymous;  # True or False

The is-anonymous method returns True if there either are two parts and both are empty. Else it returns False.

is-empty

say $name.is-empty;  # True or False

The is-empty method returns True if there either are no parts, or the only part is empty. Else it returns False.

is-identifier

say $name.is-identifier;  # True or False

The is-identifier method returns True if the name can be considered a valid identifier. Else it returns False.

is-indirect-lookup

say $name.is-indirect-lookup;  # True or False

The is-indirect-lookup method returns True if any part of the RakuAST::Name object is a RakuAST::Name::Part::Expression object. Else it returns False.

is-installable

say $name.is-installable;  # True or False

The is-installable method returns True if the name can be considered a valid, installable identifier. Else it returns False.

is-multi-part

say $name.is-multi-part;  # True or False

The is-multi-part method returns True if there is more than one non-empty part in the RakuAST::Name object. Else it returns False.

is-package-lookup

say $name.is-package-lookup;  # True or False

=head2 Object creation

There are several ways to create a C<RakuAST::Name> object.  For simple
identifiers (without adverbs, aka "colonpairs") it is recommended to use
the alternate C<.from-identifier> and C<.from-identifier-parts> methods
to create a C<RakuAST::Name> object.  Otherwise one can use the standard
C<.new> method.

=head3 new

=begin code
my $name = RakuAST::Name.new(
  RakuAST::Name::Part::Simple.new("Foo"),
  colonpairs => (
    RakuAST::ColonPair::Value.new(
      key   => "ver",
      value => RakuAST::StrLiteral.new("1.1")
    ),
  )
);
dd $name;  # Foo:ver("1.1")

Creates a RakuAST::Name object from the given positional arguments (the name parts, which should be RakuAST::Name::Part::xxx objects) and an optional list of RakuAST::ColonPair::xxx objects (which represent the "adverbs" on the name).

from-identifier

my $name = RakuAST::Name.from-identifier('$foo');
dd $name;  # $foo

Creates a RakuAST::Name object from the given simple identifier string (which may not contain any :: separators).

from-identifier-parts

my $name = RakuAST::Name.from-identifier-parts('IO','Path');
dd $name;  # IO::Path

Creates a RakuAST::Name object from the given simple identifier string parts (which may not contain any :: separators).

Object modifiers

These methods can be used to change an existing RakuAST::Name object.

add-colonpair

my $name = RakuAST::Name.from-identifier("Foo");
$name.add-colonpair(
  RakuAST::ColonPair::Value.new(
    key   => "ver",
    value => RakuAST::StrLiteral.new("1.1")
  )
);
dd $name;  # Foo:ver("1.1")

Adds a RakuAST::ColonPair::xxx object to the list of colonpairs.

See Also

class int

Native integer

class Allomorph

Dual value number and string

class Any

Thing/object

class AST

Abstract representation of a piece of source code

class atomicint

Integer (native storage at the platform's atomic operation size)

class Block

Code object with its own lexical scope

class CallFrame

Captures the current frame state

class Code

Code object

class Collation

Encapsulates instructions about how strings should be sorted

class Compiler

Information related to the compiler that is being used

class Complex

Complex number

class ComplexStr

Dual value complex number and string

class Cool

Object that can be treated as both a string and number

class CurrentThreadScheduler

Scheduler that synchronously executes code on the current thread

class Date

Calendar date

class DateTime

Calendar date with time

class Distribution::Hash

Distribution::Hash

class Distribution::Locally

Distribution::Locally

class Distribution::Path

Distribution::Path

class Distribution::Resource

Every one of the resources installed with a distribution

class Duration

Length of time

class Encoding::Registry

Management of available encodings

class FatRat

Rational number (arbitrary-precision)

class ForeignCode

Rakudo-specific class that wraps around code in other languages (generally NQP)

class Format

Convert values to a string given a format specification

class Formatter

Produce Callable for given format specification

class HyperSeq

An object for performing batches of work in parallel with ordered output

class HyperWhatever

Placeholder for multiple unspecified values/arguments

class Instant

Specific moment in time

class Int

Integer (arbitrary-precision)

class IntStr

Dual value integer and string

class Junction

Logical superposition of values

class Label

Tagged location in the source code

class Lock::Async

A non-blocking, non-re-entrant, mutual exclusion lock

class Macro

Compile-time routine

class Method

Member function

class Mu

The root of the Raku type hierarchy.

class Nil

Absence of a value

class Num

Floating-point number

role Numeric

Number or object that can act as a number

class NumStr

Dual value floating-point number and string

class ObjAt

Unique identification for an object

class Parameter

Element of a Signature

class Perl

Perl related information

class Proxy

Item container with custom storage and retrieval

class RaceSeq

Performs batches of work in parallel without respecting original order.

class Raku

Raku related information

package RakuAST

Namespace for holding RakuAST related classes

class RakuAST::Doc::Block

Contains the information of a RakuDoc block

class RakuAST::Doc::Declarator

Contains the declarator docs of a RakuAST object

class RakuAST::Doc::Markup

Contains the information about RakuDoc markup

class RakuAST::Doc::Paragraph

Contains the information about a RakuDoc paragraph

class RakuAST::Name::Part

Base class for representing a part of a RakuAST::Name

class RakuAST::Name::Part::EmptyEdge

Represent an empty part at the start/end of a RakuAST::Name

class RakuAST::Name::Part::Expression

Represent an expression as part of a RakuAST::Name

class RakuAST::Name::Part::Simple

Represent a string part of a RakuAST::Name

class RakuAST::Type

Base class for representing a type

class RakuAST::Type::Capture

Represent a type without any additional features

class RakuAST::Type::Coercion

Represent a Raku type that coerces

class RakuAST::Type::Definedness

Represent a Raku type that constrains on (un)defined

class RakuAST::Type::Enum

Represent a type without any additional features

class RakuAST::Type::Parameterized

Represent a Raku type with parameterization

class RakuAST::Type::Setting

Represent a core-type

class RakuAST::Type::Simple

Represent a type without any additional features

class RakuAST::Type::Subset

Represent a type without any additional features

class Rat

Rational number (limited-precision)

class RatStr

Dual value rational number and string

class Routine

Code object with its own lexical scope and return handling

class Routine::WrapHandle

Holds all information needed to unwrap a wrapped routine.

class Scalar

A mostly transparent container used for indirections

class Signature

Parameter list pattern

class Str

String of characters

class StrDistance

Contains the result of a string transformation.

class Sub

Subroutine

class Submethod

Member function that is not inherited by subclasses

class Telemetry::Instrument::Thread

Instrument for collecting Thread data

class Telemetry::Instrument::ThreadPool

Instrument for collecting ThreadPoolScheduler data

class Telemetry::Instrument::Usage

Instrument for collecting getrusage data

class Telemetry::Period

Performance data over a period

class Telemetry::Sampler

Telemetry instrument pod

Subset UInt

Unsigned integer (arbitrary-precision)

class ValueObjAt

Unique identification for value types

class Variable

Object representation of a variable for use in traits

class Version

Module version descriptor

class Whatever

Placeholder for the value of an unspecified argument

class WhateverCode

Code object constructed by Whatever priming

The Camelia image is copyright 2009 by Larry Wall. "Raku" is a trademark of the Yet Another Society. All rights reserved.

Built with Podlite — the markup and publishing tools behind this site.