diff --git a/rules/lex.go b/rules/lex.go index f5f9aa8..e869501 100644 --- a/rules/lex.go +++ b/rules/lex.go @@ -298,8 +298,6 @@ func lexTopLevel(l *lexer) lexerStateFun { return lexSingleQuotedWord case '`': return lexBackQuotedWord - // case '[': - // return lexBracketedWord } return lexBareWord @@ -317,25 +315,6 @@ func lexComment(l *lexer) lexerStateFun { return lexTopLevel } -// func lexBracketedWord(l *lexer) lexerStateFun { -// l.skip() // '[' -// for l.peek() != ']' && l.peek() != eof { -// l.acceptUntil("\\]") -// if l.accept("\\") { -// l.accept("]") -// } -// } -// -// if l.peek() == eof { -// l.lexError("end of file encountered while parsing a bracketed string.") -// } -// -// l.pushtmp() -// -// l.skip() // ']' -// return lexBareWord -// } - func lexDoubleQuotedWord(l *lexer) lexerStateFun { l.skip() // '"' for l.peek() != '"' && l.peek() != eof { @@ -356,11 +335,11 @@ func lexDoubleQuotedWord(l *lexer) lexerStateFun { } func lexBackQuotedWord(l *lexer) lexerStateFun { - l.skip() // '`' + l.next() // '`' l.acceptUntil("`") - l.pushtmp() - l.skip() // '`' - return lexBareWord + l.next() // '`' + l.emit(tokenWord) + return lexTopLevel } func lexSingleQuotedWord(l *lexer) lexerStateFun { diff --git a/rules/parse.go b/rules/parse.go index 84aefcb..c84a6ee 100644 --- a/rules/parse.go +++ b/rules/parse.go @@ -282,6 +282,22 @@ func parseRecipe(p *parser, t token) parserStateFun { // prereqs base.prereqs = make([]string, 0) for k := j + 1; k < len(p.tokenbuf); k++ { + // pretty hacky method to handle applying attributes to multiple prereqs at once with `prereqs`[attrs] syntax + if strings.HasPrefix(p.tokenbuf[k].val, "`") && strings.HasSuffix(p.tokenbuf[k].val, "`") { + length := len(p.tokenbuf[k].val) + inner := lex(p.tokenbuf[k].val[1:length-1], p.tokenbuf[k].line) + attrs := "" + if len(p.tokenbuf) > k+1 && strings.HasPrefix(p.tokenbuf[k+1].val, "[") { + attrs = p.tokenbuf[k+1].val + } + for t := inner.nextToken(); t.typ != tokenEnd; t = inner.nextToken() { + if t.typ == tokenError { + break + } + base.prereqs = append(base.prereqs, t.val+attrs) + } + continue + } base.prereqs = append(base.prereqs, p.tokenbuf[k].val) }