diff options
| author | 2024-09-03 22:18:51 +0000 | |
|---|---|---|
| committer | 2024-09-03 22:18:51 +0000 | |
| commit | aebccc735a9173454faa7124ebf7a640cd9741d9 (patch) | |
| tree | 08421df6dc0a39497de91293fd26447f1e54d8ec | |
| parent | fc4607a412603104b400c9d4bd86cdf0cb5a3b6d (diff) | |
| parent | e9cc403553a2886a608a59c24f2ee7aab12946fd (diff) | |
Merge "Fix End() of Rule" into main
| -rw-r--r-- | androidmk/parser/ast.go | 3 | ||||
| -rw-r--r-- | androidmk/parser/parser.go | 1 | ||||
| -rw-r--r-- | androidmk/parser/parser_test.go | 22 |
3 files changed, 25 insertions, 1 deletions
diff --git a/androidmk/parser/ast.go b/androidmk/parser/ast.go index d5d135443..c3d198f94 100644 --- a/androidmk/parser/ast.go +++ b/androidmk/parser/ast.go @@ -84,6 +84,7 @@ type Rule struct { Prerequisites *MakeString RecipePos Pos Recipe string + RecipeEndPos Pos } func (x *Rule) Dump() string { @@ -95,7 +96,7 @@ func (x *Rule) Dump() string { } func (x *Rule) Pos() Pos { return x.Target.Pos() } -func (x *Rule) End() Pos { return Pos(int(x.RecipePos) + len(x.Recipe)) } +func (x *Rule) End() Pos { return x.RecipeEndPos } type Variable struct { Name *MakeString diff --git a/androidmk/parser/parser.go b/androidmk/parser/parser.go index 8a20bb052..f2477db3a 100644 --- a/androidmk/parser/parser.go +++ b/androidmk/parser/parser.go @@ -448,6 +448,7 @@ loop: Prerequisites: prerequisites, Recipe: recipe, RecipePos: recipePos, + RecipeEndPos: p.pos(), }) } } diff --git a/androidmk/parser/parser_test.go b/androidmk/parser/parser_test.go index fb03c2324..e238f8b11 100644 --- a/androidmk/parser/parser_test.go +++ b/androidmk/parser/parser_test.go @@ -124,3 +124,25 @@ func TestParse(t *testing.T) { }) } } + +func TestRuleEnd(t *testing.T) { + name := "ruleEndTest" + in := `all: +ifeq (A, A) + echo foo + echo foo + echo foo + echo foo +endif + echo bar +` + p := NewParser(name, bytes.NewBufferString(in)) + got, errs := p.Parse() + if len(errs) != 0 { + t.Fatalf("Unexpected errors while parsing: %v", errs) + } + + if got[0].End() < got[len(got) -1].Pos() { + t.Errorf("Rule's end (%d) is smaller than directive that inside of rule's start (%v)\n", got[0].End(), got[len(got) -1].Pos()) + } +} |