Skip to content

Commit

Permalink
Fix issue with set and quoted strings
Browse files Browse the repository at this point in the history
  • Loading branch information
kenshaw committed Dec 4, 2023
1 parent c9eee2c commit 06ebe54
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
17 changes: 13 additions & 4 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
12 changes: 12 additions & 0 deletions testdata/spaces.inputrc
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 06ebe54

Please sign in to comment.