A fictitious 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 uniformly. 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.
Similar to String#+
.
Similar to String#=~
.
Similar to String#[]
.
Similar to String#capitalize
.
Similar to String#chars
.
Similar to String#chomp
.
Similar to String#downcase
.
Similar to String#empty?
.
Similar to String#ends_with?
.
Similar to String#gsub
.
Returns self.
Similar to String#includes?
.
Similar to String#lines
.
Similar to String#size
.
Similar to String#split
.
Similar to String#split
.
Similar to String#starts_with?
.
Similar to String#strip
.
Similar to String#titleize
.
Similar to String#tr
.
Similar to String#upcase
.
Crystal::Macros::ASTNode
Reference
Reference
Object
Object
Similar to String#+
.
Similar to String#=~
.
Similar to String#[]
.
Similar to String#capitalize
.
Similar to String#chars
.
Similar to String#chomp
.
Similar to String#downcase
.
Similar to String#empty?
.
Similar to String#ends_with?
.
Similar to String#gsub
.
Similar to String#includes?
.
Similar to String#lines
.
Similar to String#size
.
Similar to String#split
.
Similar to String#split
.
Similar to String#starts_with?
.
Similar to String#strip
.
Similar to String#titleize
.
Similar to String#tr
.
Similar to String#upcase
.
© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/Crystal/Macros/MacroId.html