parser_return.go 676 B

12345678910111213141516171819202122232425262728293031
  1. package parser
  2. import (
  3. "code.osinet.fr/fgm/waiig15/ast"
  4. "code.osinet.fr/fgm/waiig15/token"
  5. )
  6. func (p *Parser) parseReturnStatement() *ast.ReturnStatement {
  7. stmt := &ast.ReturnStatement{
  8. Token: p.curToken,
  9. }
  10. // There should be an expression to consume here.
  11. p.nextToken()
  12. // Skip the expression for now, progress to the semicolon terminating the
  13. // statement.
  14. for !p.curTokenIs(token.SEMICOLON) {
  15. p.nextToken()
  16. }
  17. return stmt
  18. }
  19. func (p *Parser) registerInfix(tokenType token.TokenType, fn infixParseFn) {
  20. p.infixParseFns[tokenType] = fn
  21. }
  22. func (p *Parser) registerPrefix(tokenType token.TokenType, fn prefixParseFn) {
  23. p.prefixParseFns[tokenType] = fn
  24. }