Skip to content

Commit

Permalink
Make isSymbolPrefix to lookup table.
Browse files Browse the repository at this point in the history
  • Loading branch information
harukasan committed Oct 4, 2016
1 parent e5ba9aa commit b57d649
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,31 @@ func scanDiv(s *Scanner) (token.Token, []byte) {
return token.Div, nil
}

var symbolPrefixMap = [...]bool{
'!': true,
'"': true,
'$': true,
'%': true,
'&': true,
'\'': true,
'*': true,
'+': true,
'-': true,
'/': true,
'<': true,
'=': true,
'>': true,
'@': true,
'[': true,
'^': true,
'_': true,
'`': true,
'|': true,
'~': true,
}

func isSymbolPrefix(c byte) bool {
return (('!' <= c && c != '#' && c <= '\'') ||
('*' <= c && c != ',' && c != '.' && c <= '9') ||
('<' <= c && c != '?' && c <= '[') ||
('^' <= c && c <= 'z') ||
c == '~')
return token.IsAlnum(c) || symbolPrefixMap[c]
}

func scanColon(s *Scanner) (token.Token, []byte) {
Expand Down

0 comments on commit b57d649

Please sign in to comment.