diff --git a/expand.go b/expand.go index 7dde531..2965467 100644 --- a/expand.go +++ b/expand.go @@ -78,7 +78,11 @@ func expand(input string, vars map[string][]string, expandBackticks bool) []stri // Expand following a '\\' func expandEscape(input string) (string, int) { c, w := utf8.DecodeRuneInString(input) - return string(c), w + if c == '\t' || c == ' ' { + return string(c), w + } else { + return "\\" + string(c), w + } } // Expand a double quoted string starting after a '\"' diff --git a/lex.go b/lex.go index 8b7a4d0..011ac53 100644 --- a/lex.go +++ b/lex.go @@ -283,10 +283,6 @@ func lexTopLevel(l *lexer) lexerStateFun { return lexBackQuotedWord } - if strings.IndexRune(nonBareRunes, c) >= 0 { - l.lexerror(fmt.Sprintf("expected a unquoted string, but found '%c'", c)) - } - return lexBareWord } @@ -366,12 +362,27 @@ func lexRecipe(l *lexer) lexerStateFun { func lexBareWord(l *lexer) lexerStateFun { l.acceptUntil(nonBareRunes) - if l.peek() == '"' { + c := l.peek() + if c == '"' { return lexDoubleQuotedWord - } else if l.peek() == '\'' { + } else if c == '\'' { return lexSingleQuotedWord - } else if l.peek() == '`' { + } else if c == '`' { return lexBackQuotedWord + } else if c == '\\' { + c1 := l.peekN(1) + if c1 == '\n' || c1 == '\r' { + if l.start < l.pos { + l.emit(tokenWord) + } + l.skip() + l.skip() + return lexTopLevel + } else { + l.next() + l.next() + return lexBareWord + } } if l.start < l.pos {