class Macros::MacroId

Overview

A ficticious node representing an idenfitifer like, foo, Bar or something_else.

The parser doesn't create this nodes. Instead, you create them by invoking #id on some nodes. For example, invoking #id on a StringLiteral returns a MacroId for the string's content. Similarly, invoking ID on a SymbolLiteral, Call, Var and Path return MacroIds for the node's content.

This allows you to treat strings, symbols, variables and calls unifomly. For example:

macro getter(name)
  def {{name.id}}
    @{{name.id}}
  end
end

getter unicorns
getter :unicorns
getter "unicorns"

All of the above macro calls work because we invoked #id, and the generated code looks like this:

def unicorns
  @unicorns
end

If we hand't use #id, the generated code would have been this:

def unicorns
  @unicorns
end

def :unicorns
  @:unicorns
end

def "unicorns"
  @"unicorns"
end

The last two definitions are invalid and so will give a compile-time error.

Superclass hierarchy

Object
Reference
Macros::ASTNode
Macros::MacroId

Defined in:

Instance Method Summary

Instance Method Detail

def +(other : StringLiteral | CharLiteral) : MacroId

Similar to String#+.


def =~(range : RegexLiteral) : BoolLiteral

Similar to String#=~.


def [](range : RangeLiteral) : MacroId

Similar to String#[].


def capitalize : MacroId

Similar to String#capitalize.


def chars : Macros::ArrayLiteral(CharLiteral)

Similar to String#chars.


def chomp : MacroId

Similar to String#chomp.


def downcase : MacroId

Similar to String#downcase.


def empty? : BoolLiteral

Similar to String#empty?.


def ends_with?(other : StringLiteral | CharLiteral) : BoolLiteral

Similar to String#ends_with?.


def gsub(regex : RegexLiteral, replacement : StringLiteral) : MacroId

Similar to String#gsub.


def id : MacroId

Returns self.


def length : NumberLiteral

Similar to String#length.


def lines : Macros::ArrayLiteral(StringLiteral)

Similar to String#lines.


def split : Macros::ArrayLiteral(StringLiteral)

Similar to String#split.


def split(node : ASTNode) : Macros::ArrayLiteral(StringLiteral)

Similar to String#split.


def starts_with?(other : StringLiteral | CharLiteral) : BoolLiteral

Similar to String#starts_with?.


def strip : MacroId

Similar to String#strip.


def tr(from : StringLiteral, to : StringLiteral) : MacroId

Similar to String#tr.


def upcase : MacroId

Similar to String#upcase.