From 0cc6493a567d65bca8a303eec06123c3a9ea6e9c Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Mon, 19 Aug 2013 00:05:17 -0700 Subject: [PATCH] Allow recipes to end with EOF. --- lex.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lex.go b/lex.go index 7b4364d..8b7a4d0 100644 --- a/lex.go +++ b/lex.go @@ -188,6 +188,14 @@ func (l *lexer) acceptUntil(invalid string) { } } +// Accept until something from the given string is encountered, or the end of th +// file +func (l *lexer) acceptUntilOrEof(invalid string) { + for l.pos < len(l.input) && strings.IndexRune(invalid, l.peek()) < 0 { + l.next() + } +} + // Skip characters from the valid string until the next is not. func (l *lexer) skipRun(valid string) int { prevpos := l.pos @@ -343,7 +351,7 @@ func lexSingleQuotedWord(l *lexer) lexerStateFun { func lexRecipe(l *lexer) lexerStateFun { for { - l.acceptUntil("\n") + l.acceptUntilOrEof("\n") l.acceptRun(" \t\n\r") if !l.indented || l.col == 0 { break