diff options
Diffstat (limited to 'vendor/github.com/kevinburke/ssh_config/lexer.go')
-rw-r--r-- | vendor/github.com/kevinburke/ssh_config/lexer.go | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/vendor/github.com/kevinburke/ssh_config/lexer.go b/vendor/github.com/kevinburke/ssh_config/lexer.go index b0c6a8650c..11680b4c74 100644 --- a/vendor/github.com/kevinburke/ssh_config/lexer.go +++ b/vendor/github.com/kevinburke/ssh_config/lexer.go @@ -1,22 +1,22 @@ package ssh_config import ( - "io" - - buffruneio "github.com/pelletier/go-buffruneio" + "bytes" ) // Define state functions type sshLexStateFn func() sshLexStateFn type sshLexer struct { - input *buffruneio.Reader // Textual source - buffer []rune // Runes composing the current token + inputIdx int + input []rune // Textual source + + buffer []rune // Runes composing the current token tokens chan token - line uint32 - col uint16 - endbufferLine uint32 - endbufferCol uint16 + line int + col int + endbufferLine int + endbufferCol int } func (s *sshLexer) lexComment(previousState sshLexStateFn) sshLexStateFn { @@ -114,16 +114,14 @@ func (s *sshLexer) lexRvalue() sshLexStateFn { } func (s *sshLexer) read() rune { - r, _, err := s.input.ReadRune() - if err != nil { - panic(err) - } + r := s.peek() if r == '\n' { s.endbufferLine++ s.endbufferCol = 1 } else { s.endbufferCol++ } + s.inputIdx++ return r } @@ -197,21 +195,22 @@ func (s *sshLexer) emitWithValue(t tokenType, value string) { } func (s *sshLexer) peek() rune { - r, _, err := s.input.ReadRune() - if err != nil { - panic(err) + if s.inputIdx >= len(s.input) { + return eof } - s.input.UnreadRune() + + r := s.input[s.inputIdx] return r } func (s *sshLexer) follow(next string) bool { + inputIdx := s.inputIdx for _, expectedRune := range next { - r, _, err := s.input.ReadRune() - defer s.input.UnreadRune() - if err != nil { - panic(err) + if inputIdx >= len(s.input) { + return false } + r := s.input[inputIdx] + inputIdx++ if expectedRune != r { return false } @@ -226,10 +225,10 @@ func (s *sshLexer) run() { close(s.tokens) } -func lexSSH(input io.Reader) chan token { - bufferedInput := buffruneio.NewReader(input) +func lexSSH(input []byte) chan token { + runes := bytes.Runes(input) l := &sshLexer{ - input: bufferedInput, + input: runes, tokens: make(chan token), line: 1, col: 1, |