Parse else ifxxx statement

More recent versions of make provide "else ifdef/ifndef/ifeq/ifneq" directive:
ifdef FOO
...
else ifdef BAR
...
endif
Fix the parser to handle it. It returns the same Directive as the respective ifxxx
counterpart, only that the Name is set to "elifdef/elifndef/elifeq/elifneq".

Test: treehugger
Change-Id: I74c6a2c7224bce1dd3465012fa84880fae21349b
This commit is contained in:
Sasha Smundak 2020-11-17 22:58:55 -08:00
parent 9240f955cb
commit 9c35d8bfde

View file

@ -212,8 +212,21 @@ func (p *parser) parseDirective() bool {
expression := SimpleMakeString("", pos) expression := SimpleMakeString("", pos)
switch d { switch d {
case "endif", "endef", "else": case "endif", "endef":
// Nothing // Nothing
case "else":
p.ignoreSpaces()
if p.tok != '\n' {
d = p.scanner.TokenText()
p.accept(scanner.Ident)
if d == "ifdef" || d == "ifndef" || d == "ifeq" || d == "ifneq" {
d = "el" + d
p.ignoreSpaces()
expression = p.parseExpression()
} else {
p.errorf("expected ifdef/ifndef/ifeq/ifneq, found %s", d)
}
}
case "define": case "define":
expression, endPos = p.parseDefine() expression, endPos = p.parseDefine()
default: default: