1 parent
b790c53838
commit
397d4102e6
2 files changed
+65
-1
No files matched your search
+31
-1
@@ -41,6 +41,36 @@ var gEvalTests = []struct {
|
||||
[]expr{&callExpr{"echo", []string{"hello world"}}},
|
||||
},
|
||||
|
||||
{
|
||||
`echo "hello world"`,
|
||||
[]string{"echo", "hello world", "\n"},
|
||||
[]expr{&callExpr{"echo", []string{"hello world"}}},
|
||||
},
|
||||
|
||||
{
|
||||
`echo "hello\"world"`,
|
||||
[]string{"echo", `hello"world`, "\n"},
|
||||
[]expr{&callExpr{"echo", []string{`hello"world`}}},
|
||||
},
|
||||
|
||||
{
|
||||
`echo "hello\tworld"`,
|
||||
[]string{"echo", "hello\tworld", "\n"},
|
||||
[]expr{&callExpr{"echo", []string{"hello\tworld"}}},
|
||||
},
|
||||
|
||||
{
|
||||
`echo "hello\nworld"`,
|
||||
[]string{"echo", "hello\nworld", "\n"},
|
||||
[]expr{&callExpr{"echo", []string{"hello\nworld"}}},
|
||||
},
|
||||
|
||||
{
|
||||
`echo "hello\zworld"`,
|
||||
[]string{"echo", "helloworld", "\n"},
|
||||
[]expr{&callExpr{"echo", []string{"helloworld"}}},
|
||||
},
|
||||
|
||||
{
|
||||
`echo hello\ world`,
|
||||
[]string{"echo", "hello world", "\n"},
|
||||
@@ -60,7 +90,7 @@ var gEvalTests = []struct {
|
||||
},
|
||||
|
||||
{
|
||||
`echo hello\aworld`,
|
||||
`echo hello\zworld`,
|
||||
[]string{"echo", "helloworld", "\n"},
|
||||
[]expr{&callExpr{"echo", []string{"helloworld"}}},
|
||||
},
|
||||
|
||||
@@ -203,6 +203,40 @@ scan:
|
||||
s.next()
|
||||
}
|
||||
goto scan
|
||||
case s.chr == '"':
|
||||
s.next()
|
||||
var buf []byte
|
||||
for !s.eof && s.chr != '"' {
|
||||
if s.chr == '\\' {
|
||||
s.next()
|
||||
// TODO: octal escape
|
||||
switch s.chr {
|
||||
case '"', '\\':
|
||||
buf = append(buf, s.chr)
|
||||
case 'a':
|
||||
buf = append(buf, '\a')
|
||||
case 'b':
|
||||
buf = append(buf, '\b')
|
||||
case 'f':
|
||||
buf = append(buf, '\f')
|
||||
case 'n':
|
||||
buf = append(buf, '\n')
|
||||
case 'r':
|
||||
buf = append(buf, '\r')
|
||||
case 't':
|
||||
buf = append(buf, '\t')
|
||||
case 'v':
|
||||
buf = append(buf, '\v')
|
||||
}
|
||||
s.next()
|
||||
} else {
|
||||
buf = append(buf, s.chr)
|
||||
s.next()
|
||||
}
|
||||
}
|
||||
s.typ = tokenIdent
|
||||
s.tok = string(buf)
|
||||
s.next()
|
||||
case s.chr == '\'':
|
||||
s.next()
|
||||
beg := s.off
|
||||
|
||||
Reference in new issue
Block a user