Fixes for parsing regex meta-rules.

This commit is contained in:
Daniel Jones 2014-02-01 18:19:26 -08:00
parent 0cc6493a56
commit b9a5986fc7
2 changed files with 23 additions and 8 deletions

View file

@ -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 '\"'

25
lex.go
View file

@ -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 {