diff --git a/go.mod b/go.mod index d533beb..c42d4b1 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module github.com/xo/inputrc go 1.20 require ( - github.com/google/go-cmp v0.5.9 + github.com/google/go-cmp v0.6.0 golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 ) diff --git a/go.sum b/go.sum index 7d7100b..d39c1c2 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,4 @@ -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 h1:5llv2sWeaMSnA3w2kS57ouQQ4pudlXrR0dCgw51QK9o= golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= diff --git a/parse.go b/parse.go index 885edc5..ecae2b7 100644 --- a/parse.go +++ b/parse.go @@ -103,10 +103,10 @@ func (p *Parser) readNext(r []rune, i, end int) (string, string, token, error) { switch { case r[i] == 's' && grab(r, i+1, end) == 'e' && grab(r, i+2, end) == 't' && unicode.IsSpace(grab(r, i+3, end)): // read set - return p.readSymbols(r, i+4, end, tokenSet) + return p.readSymbols(r, i+4, end, tokenSet, true) case r[i] == '$': // read construct - return p.readSymbols(r, i, end, tokenConstruct) + return p.readSymbols(r, i, end, tokenConstruct, false) } // read key seq var seq string @@ -168,12 +168,21 @@ func (p *Parser) readNext(r []rune, i, end int) (string, string, token, error) { } // readSet reads the next two symbols. -func (p *Parser) readSymbols(r []rune, i, end int, tok token) (string, string, token, error) { +func (p *Parser) readSymbols(r []rune, i, end int, tok token, allowStrings bool) (string, string, token, error) { start := findNonSpace(r, i, end) i = findEnd(r, start, end) a := string(r[start:i]) start = findNonSpace(r, i, end) - i = findEnd(r, start, end) + var ok bool + if c := grab(r, start, end); allowStrings || c == '"' || c == '\'' { + var pos int + if pos, ok = findStringEnd(r, start, end); ok { + i = pos + } + } + if !allowStrings || !ok { + i = findEnd(r, start, end) + } return a, string(r[start:i]), tok, nil } diff --git a/testdata/spaces.inputrc b/testdata/spaces.inputrc new file mode 100644 index 0000000..cae93ca --- /dev/null +++ b/testdata/spaces.inputrc @@ -0,0 +1,12 @@ +app: usql +term: xterm-256 +mode: vi +####----#### +set editing-mode vi +set vi-ins-mode-string "\1\e[4 q\2" +set my-other-string 'a b' +####----#### +vars: + editing-mode: vi + my-other-string: 'a b' + vi-ins-mode-string: "\1\e[4 q\2"