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

     1  package ast
     2  
     3  import (
     4  	"github.com/arnodel/golua/token"
     5  )
     6  
     7  // WhileStat represents a while / end statement
     8  type WhileStat struct {
     9  	Location
    10  	CondStat
    11  }
    12  
    13  var _ Stat = WhileStat{}
    14  
    15  // NewWhileStat returns a WhileStat instance representing the statement "while
    16  // <cond> do <body> done".
    17  func NewWhileStat(whileTok, endTok *token.Token, cond ExpNode, body BlockStat) WhileStat {
    18  	return WhileStat{
    19  		Location: LocFromTokens(whileTok, endTok),
    20  		CondStat: CondStat{Cond: cond, Body: body},
    21  	}
    22  }
    23  
    24  // ProcessStat uses the given StatProcessor to process the receiver.
    25  func (s WhileStat) ProcessStat(p StatProcessor) {
    26  	p.ProcessWhileStat(s)
    27  }
    28  
    29  // HWrite prints a tree representation of the node.
    30  func (s WhileStat) HWrite(w HWriter) {
    31  	w.Writef("while: ")
    32  	s.CondStat.HWrite(w)
    33  }