Skip to content

Commit

Permalink
skip trailing spaces in scanner
Browse files Browse the repository at this point in the history
Related #301
  • Loading branch information
gokcehan committed Jul 4, 2020
1 parent ce4ea6e commit e1b939b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 12 additions & 0 deletions eval_test.go
Expand Up @@ -179,6 +179,18 @@ var gEvalTests = []struct {
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}, 1}, &setExpr{"hidden", ""}},
},

{
"set ratios 1:2:3\n set hidden",
[]string{"set", "ratios", "1:2:3", "\n", "set", "hidden", "\n"},
[]expr{&setExpr{"ratios", "1:2:3"}, &setExpr{"hidden", ""}},
},

{
"set ratios 1:2:3 \nset hidden",
[]string{"set", "ratios", "1:2:3", "\n", "set", "hidden", "\n"},
[]expr{&setExpr{"ratios", "1:2:3"}, &setExpr{"hidden", ""}},
},

{
"map gh cd ~",
[]string{"map", "gh", "cd", "~", "\n"},
Expand Down
5 changes: 1 addition & 4 deletions scan.go
Expand Up @@ -177,9 +177,6 @@ scan:
s.tok = string(s.buf[beg:s.off])
s.cmd = false
s.sem = true
case s.chr == '\r':
s.next()
goto scan
case s.chr == '\n':
if s.sem {
s.typ = tokenSemicolon
Expand All @@ -196,7 +193,7 @@ scan:
}
goto scan
case isSpace(s.chr):
for !s.eof && isSpace(s.chr) {
for !s.eof && isSpace(s.chr) && s.chr != '\n' {
s.next()
}
goto scan
Expand Down

0 comments on commit e1b939b

Please sign in to comment.