From f648cfb84bf2fe6794b014c5cc9e9d6b29832c28 Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Sat, 29 Jun 2019 20:37:49 -0700 Subject: [PATCH] all: use ints instead of uints Files are small and these are cheap enough that we should be more worried about overflow errors than the space cost. --- config.go | 13 +++++++------ lexer.go | 8 ++++---- parser.go | 2 +- position.go | 4 ++-- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/config.go b/config.go index f400cef..33e22b7 100644 --- a/config.go +++ b/config.go @@ -45,6 +45,8 @@ import ( const version = "0.5" +var _ = version + type configFinder func() string // UserSettings checks ~/.ssh and /etc/ssh for configuration files. The config @@ -367,7 +369,7 @@ type Host struct { // EOLComment is the comment (if any) terminating the Host line. EOLComment string hasEquals bool - leadingSpace uint16 // TODO: handle spaces vs tabs here. + leadingSpace int // TODO: handle spaces vs tabs here. // The file starts with an implicit "Host *" declaration. implicit bool } @@ -438,7 +440,7 @@ type KV struct { Value string Comment string hasEquals bool - leadingSpace uint16 // Space before the key. TODO handle spaces vs tabs. + leadingSpace int // Space before the key. TODO handle spaces vs tabs. position Position } @@ -467,7 +469,7 @@ func (k *KV) String() string { // Empty is a line in the config file that contains only whitespace or comments. type Empty struct { Comment string - leadingSpace uint16 // TODO handle spaces vs tabs. + leadingSpace int // TODO handle spaces vs tabs. position Position } @@ -494,7 +496,6 @@ type Include struct { // Comment is the contents of any comment at the end of the Include // statement. Comment string - parsed bool // an include directive can include several different files, and wildcards directives []string @@ -504,7 +505,7 @@ type Include struct { matches []string // actual filenames are listed here files map[string]*Config - leadingSpace uint16 + leadingSpace int position Position depth uint8 hasEquals bool @@ -544,7 +545,7 @@ func NewInclude(directives []string, hasEquals bool, pos Position, comment strin directives: directives, files: make(map[string]*Config), position: pos, - leadingSpace: uint16(pos.Col) - 1, + leadingSpace: pos.Col - 1, depth: depth, hasEquals: hasEquals, } diff --git a/lexer.go b/lexer.go index b0c6a86..5c1c39b 100644 --- a/lexer.go +++ b/lexer.go @@ -13,10 +13,10 @@ type sshLexer struct { input *buffruneio.Reader // 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 { diff --git a/parser.go b/parser.go index 02745b4..10a2263 100644 --- a/parser.go +++ b/parser.go @@ -149,7 +149,7 @@ func (p *sshParser) parseKV() sshParserStateFn { Value: val.val, Comment: comment, hasEquals: hasEquals, - leadingSpace: uint16(key.Position.Col) - 1, + leadingSpace: key.Position.Col - 1, position: key.Position, } lastHost.Nodes = append(lastHost.Nodes, kv) diff --git a/position.go b/position.go index 7304bc3..e0b5e3f 100644 --- a/position.go +++ b/position.go @@ -8,8 +8,8 @@ import "fmt" // column number, respectively. Values of zero or less will cause Invalid(), // to return true. type Position struct { - Line uint32 // line within the document - Col uint16 // column within the line + Line int // line within the document + Col int // column within the line } // String representation of the position.