Merge "Parse variable references with #s"
This commit is contained in:
@@ -222,7 +222,7 @@ func (p *parser) parseDirective() bool {
|
|||||||
if d == "ifdef" || d == "ifndef" || d == "ifeq" || d == "ifneq" {
|
if d == "ifdef" || d == "ifndef" || d == "ifeq" || d == "ifneq" {
|
||||||
d = "el" + d
|
d = "el" + d
|
||||||
p.ignoreSpaces()
|
p.ignoreSpaces()
|
||||||
expression = p.parseExpression()
|
expression = p.parseExpression('#')
|
||||||
expression.TrimRightSpaces()
|
expression.TrimRightSpaces()
|
||||||
} else {
|
} else {
|
||||||
p.errorf("expected ifdef/ifndef/ifeq/ifneq, found %s", d)
|
p.errorf("expected ifdef/ifndef/ifeq/ifneq, found %s", d)
|
||||||
@@ -232,7 +232,7 @@ func (p *parser) parseDirective() bool {
|
|||||||
expression, endPos = p.parseDefine()
|
expression, endPos = p.parseDefine()
|
||||||
default:
|
default:
|
||||||
p.ignoreSpaces()
|
p.ignoreSpaces()
|
||||||
expression = p.parseExpression()
|
expression = p.parseExpression('#')
|
||||||
}
|
}
|
||||||
|
|
||||||
p.nodes = append(p.nodes, &Directive{
|
p.nodes = append(p.nodes, &Directive{
|
||||||
@@ -338,9 +338,6 @@ loop:
|
|||||||
value.appendString(`\` + string(p.tok))
|
value.appendString(`\` + string(p.tok))
|
||||||
}
|
}
|
||||||
p.accept(p.tok)
|
p.accept(p.tok)
|
||||||
case '#':
|
|
||||||
p.parseComment()
|
|
||||||
break loop
|
|
||||||
case '$':
|
case '$':
|
||||||
var variable Variable
|
var variable Variable
|
||||||
variable = p.parseVariable()
|
variable = p.parseVariable()
|
||||||
@@ -522,7 +519,7 @@ func (p *parser) parseAssignment(t string, target *MakeString, ident *MakeString
|
|||||||
// non-whitespace character after the = until the end of the logical line,
|
// non-whitespace character after the = until the end of the logical line,
|
||||||
// which may included escaped newlines
|
// which may included escaped newlines
|
||||||
p.accept('=')
|
p.accept('=')
|
||||||
value := p.parseExpression()
|
value := p.parseExpression('#')
|
||||||
value.TrimLeftSpaces()
|
value.TrimLeftSpaces()
|
||||||
if ident.EndsWith('+') && t == "=" {
|
if ident.EndsWith('+') && t == "=" {
|
||||||
ident.TrimRightOne()
|
ident.TrimRightOne()
|
||||||
|
@@ -34,6 +34,56 @@ var parserTestCases = []struct {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Simple warning",
|
||||||
|
in: `$(warning A warning)`,
|
||||||
|
out: []Node{
|
||||||
|
&Variable{
|
||||||
|
Name: SimpleMakeString("warning A warning", NoPos),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Warning with #",
|
||||||
|
in: `$(warning # A warning)`,
|
||||||
|
out: []Node{
|
||||||
|
&Variable{
|
||||||
|
Name: SimpleMakeString("warning # A warning", NoPos),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Findstring with #",
|
||||||
|
in: `$(findstring x,x a #)`,
|
||||||
|
out: []Node{
|
||||||
|
&Variable{
|
||||||
|
Name: SimpleMakeString("findstring x,x a #", NoPos),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "If statement",
|
||||||
|
in: `ifeq (a,b) # comment
|
||||||
|
endif`,
|
||||||
|
out: []Node{
|
||||||
|
&Directive{
|
||||||
|
NamePos: NoPos,
|
||||||
|
Name: "ifeq",
|
||||||
|
Args: SimpleMakeString("(a,b) ", NoPos),
|
||||||
|
EndPos: NoPos,
|
||||||
|
},
|
||||||
|
&Comment{
|
||||||
|
CommentPos: NoPos,
|
||||||
|
Comment: " comment",
|
||||||
|
},
|
||||||
|
&Directive{
|
||||||
|
NamePos: NoPos,
|
||||||
|
Name: "endif",
|
||||||
|
Args: SimpleMakeString("", NoPos),
|
||||||
|
EndPos: NoPos,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParse(t *testing.T) {
|
func TestParse(t *testing.T) {
|
||||||
|
@@ -254,6 +254,8 @@ def init(g, handle):
|
|||||||
in: `
|
in: `
|
||||||
$(warning this is the warning)
|
$(warning this is the warning)
|
||||||
$(warning)
|
$(warning)
|
||||||
|
$(warning # this warning starts with a pound)
|
||||||
|
$(warning this warning has a # in the middle)
|
||||||
$(info this is the info)
|
$(info this is the info)
|
||||||
$(error this is the error)
|
$(error this is the error)
|
||||||
PRODUCT_NAME:=$(shell echo *)
|
PRODUCT_NAME:=$(shell echo *)
|
||||||
@@ -264,6 +266,8 @@ def init(g, handle):
|
|||||||
cfg = rblf.cfg(handle)
|
cfg = rblf.cfg(handle)
|
||||||
rblf.mkwarning("product.mk", "this is the warning")
|
rblf.mkwarning("product.mk", "this is the warning")
|
||||||
rblf.mkwarning("product.mk", "")
|
rblf.mkwarning("product.mk", "")
|
||||||
|
rblf.mkwarning("product.mk", "# this warning starts with a pound")
|
||||||
|
rblf.mkwarning("product.mk", "this warning has a # in the middle")
|
||||||
rblf.mkinfo("product.mk", "this is the info")
|
rblf.mkinfo("product.mk", "this is the info")
|
||||||
rblf.mkerror("product.mk", "this is the error")
|
rblf.mkerror("product.mk", "this is the error")
|
||||||
cfg["PRODUCT_NAME"] = rblf.shell("echo *")
|
cfg["PRODUCT_NAME"] = rblf.shell("echo *")
|
||||||
|
Reference in New Issue
Block a user