return.go 749 B

1234567891011121314151617181920212223242526272829303132333435
  1. package ast
  2. import (
  3. "code.osinet.fr/fgm/waiig15/token"
  4. "bytes"
  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. }