diff --git a/scanner/scanner.go b/scanner/scanner.go index 3d5a4a1..cdf4e14 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -364,23 +364,25 @@ func (scanner *Scanner) NextToken() *token.Token { scanner.unreadPosition(pos) // Check for async/await - // literal := positions.String() - // if literal == "async" || literal == "await" { - // if scanner.asyncDef { - // switch literal { - // case "async": - // return positions.AsToken(token.ASYNC) - // case "await": - // return positions.AsToken(token.AWAIT) - // } - // } else if literal == "async" { - // nextToken := scanner.NextToken() - // if nextToken.ID == token.NAME && nextToken.Literal == "def" { - // scanner.asyncDef = true - // return positions.AsToken(token.ASYNC) - // } - // } - // } + literal := positions.String() + if literal == "async" || literal == "await" { + if scanner.asyncDef { + switch literal { + case "async": + return positions.AsToken(token.ASYNC) + case "await": + return positions.AsToken(token.AWAIT) + } + } else if literal == "async" { + nextToken := scanner.NextToken() + if nextToken.ID == token.NAME && nextToken.Literal == "def" { + scanner.asyncDef = true + scanner.unreadToken(nextToken) + return positions.AsToken(token.ASYNC) + } + scanner.unreadToken(nextToken) + } + } return positions.AsToken(token.NAME) case ch == '\n':