github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/ast/name.go (about)

     1  package ast
     2  
     3  import (
     4  	"github.com/arnodel/golua/token"
     5  )
     6  
     7  // Name is an expression token representing a name (identifier).
     8  type Name struct {
     9  	Location
    10  	Val string
    11  }
    12  
    13  var _ Var = Name{}
    14  
    15  // NewName returns a Name instance with value taken from the given token.
    16  func NewName(id *token.Token) Name {
    17  	return Name{
    18  		Location: LocFromToken(id),
    19  		Val:      string(id.Lit),
    20  	}
    21  }
    22  
    23  // ProcessExp uses the given ExpProcessor to process the receiver.
    24  func (n Name) ProcessExp(p ExpProcessor) {
    25  	p.ProcessNameExp(n)
    26  }
    27  
    28  // ProcessVar process the receiver using the given VarProcessor.
    29  func (n Name) ProcessVar(p VarProcessor) {
    30  	p.ProcessNameVar(n)
    31  }
    32  
    33  // HWrite prints a tree representation of the node.
    34  func (n Name) HWrite(w HWriter) {
    35  	w.Writef(n.Val)
    36  }
    37  
    38  // FunctionName returns the string associated with the name.
    39  func (n Name) FunctionName() string {
    40  	return n.Val
    41  }
    42  
    43  // AstString returns a String with the same value and location as the receiver.
    44  func (n Name) AstString() String {
    45  	return String{Location: n.Location, Val: []byte(n.Val)}
    46  }