let.go 738 B

123456789101112131415161718192021222324252627282930313233343536
  1. package ast
  2. import (
  3. "code.osinet.fr/fgm/waiig15/token"
  4. "bytes"
  5. )
  6. // LetStatement is the Node type for Let statements.
  7. type LetStatement struct {
  8. Token token.Token // the token.LET token. Why do we need it ?
  9. Name *Identifier
  10. Value Expression
  11. }
  12. // String implements Node and fmt.Stringer.
  13. func (ls *LetStatement) String() string {
  14. var out bytes.Buffer
  15. out.WriteString(ls.TokenLiteral() + " ")
  16. out.WriteString(ls.Name.String())
  17. out.WriteString(" = ")
  18. if ls.Value != nil {
  19. out.WriteString(ls.Value.String())
  20. }
  21. out.WriteString(";")
  22. return out.String()
  23. }
  24. func (ls *LetStatement) statementNode() {}
  25. // TokenLiteral satisfies the Node interface.
  26. func (ls *LetStatement) TokenLiteral() string {
  27. return ls.Token.Literal
  28. }