diff options
-rw-r--r-- | shell.go | 28 |
1 files changed, 10 insertions, 18 deletions
@@ -52,12 +52,12 @@ const ( type class int const ( - clBreak class = iota + clOther class = iota + clBreak clNewline clQuote clSingle clDouble - clOther ) type action int @@ -140,21 +140,13 @@ var update = [...][]struct { }, } -func classOf(b byte) class { - switch b { - case ' ', '\t': - return clBreak - case '\n': - return clNewline - case '\\': - return clQuote - case '\'': - return clSingle - case '"': - return clDouble - default: - return clOther - } +var classOf = [256]class{ + ' ': clBreak, + '\t': clBreak, + '\n': clNewline, + '\\': clQuote, + '\'': clSingle, + '"': clDouble, } // A Scanner partitions input from a reader into tokens divided on space, tab, @@ -190,7 +182,7 @@ func (s *Scanner) Next() bool { } else if err != nil { return false } - next := update[s.st][classOf(c)] + next := update[s.st][classOf[c]] s.st = next.state switch next.action { case push: |