class RakuAST::Literal { }

The RakuAST::Literal class represents a literal value (such as `0` or `"foo"). It also serves as a base class for specific literal values:

Object introspection§

RakuAST::Literal 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):

value§

say $literal.value;

The value method returns the value it is representing.

Object creation§

There is one way to create a RakuAST::Literal object.

from-value§

my $literal = RakuAST::Literal.from-value(42);
say $literal.^name;  # RakuAST::IntLiteral

Creates a RakuAST::Literal object from the given value. Note that for some core types, specialized subclasses will be returned:

  • Int value -> RakuAST::IntLiteral

  • Num value -> RakuAST::NumLiteral

  • Str value -> RakuAST::StrLiteral

  • Rat value -> RakuAST::RatLiteral

  • Complex value -> RakuAST::ComplexLiteral

  • Version value -> RakuAST::VersionLiteral

In all other cases a RakuAST::Literal object will be returned.