Skip to content

Commit

Permalink
Fix positioning after quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdan committed Jan 23, 2016
1 parent 80fe241 commit 9900ec8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
18 changes: 10 additions & 8 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func (p *parser) next() {
if p.tok == EOF {
return
}
p.col--
p.tok = WORD
return
}
Expand Down Expand Up @@ -171,8 +172,17 @@ func (p *parser) next() {

func (p *parser) strContent(delim byte) {
v := []string{string(delim)}
p.col++
for {
s, err := p.r.ReadString(delim)
for _, r := range s {
if r == '\n' {
p.line++
p.col = 0
} else {
p.col++
}
}
if err == io.EOF {
p.tok = EOF
p.errWanted(rune(delim))
Expand All @@ -189,14 +199,6 @@ func (p *parser) strContent(delim byte) {
break
}
p.val = strings.Join(v, "")
for _, r := range p.val {
if r == '\n' {
p.line++
p.col = 0
} else {
p.col++
}
}
}

func (p *parser) discardUpTo(delim byte) {
Expand Down
8 changes: 4 additions & 4 deletions sh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ func TestParseErr(t *testing.T) {
}{
{
in: "'",
want: `1:1: unexpected token EOF, wanted '\''`,
want: `1:2: unexpected token EOF, wanted '\''`,
},
{
in: "\"",
want: `1:1: unexpected token EOF, wanted '"'`,
want: `1:2: unexpected token EOF, wanted '"'`,
},
{
in: "'\\''",
Expand Down Expand Up @@ -125,11 +125,11 @@ func TestParseErr(t *testing.T) {
},
{
in: "foo'",
want: `1:4: unexpected token EOF, wanted '\''`,
want: `1:5: unexpected token EOF, wanted '\''`,
},
{
in: "foo\"",
want: `1:4: unexpected token EOF, wanted '"'`,
want: `1:5: unexpected token EOF, wanted '"'`,
},
{
in: "foo()",
Expand Down

0 comments on commit 9900ec8

Please sign in to comment.