return.go 750 B

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