From d7dfa2c0f7243c75170aa998f0e8f9493338d4fa Mon Sep 17 00:00:00 2001 From: Shyngys Zhiyenbek Date: Thu, 12 Oct 2023 09:34:14 +0000 Subject: [PATCH 1/2] Add AttrMap() function for getting rule attributes --- build/rule.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/build/rule.go b/build/rule.go index 44bb161ea..11da78504 100644 --- a/build/rule.go +++ b/build/rule.go @@ -226,6 +226,19 @@ func (r *Rule) AttrKeys() []string { return keys } +// AttrMap returns the map of attribute keys to values. +func (r *Rule) AttrMap() map[string]Expr { + m := make(map[string]Expr) + for _, expr := range r.Call.List { + if as, ok := expr.(*AssignExpr); ok { + if keyExpr, ok := as.LHS.(*Ident); ok { + m[keyExpr.Name] = as + } + } + } + return m +} + // AttrDefn returns the AssignExpr defining the rule's attribute with the given key. // If the rule has no such attribute, AttrDefn returns nil. func (r *Rule) AttrDefn(key string) *AssignExpr { From dc90b249fdcef41f6b3fe0855dff6f00304ed898 Mon Sep 17 00:00:00 2001 From: Shyngys Zhiyenbek Date: Thu, 12 Oct 2023 09:34:14 +0000 Subject: [PATCH 2/2] Add AttrMap() function for getting rule attributes --- build/rule.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/build/rule.go b/build/rule.go index 44bb161ea..650d95aef 100644 --- a/build/rule.go +++ b/build/rule.go @@ -226,6 +226,19 @@ func (r *Rule) AttrKeys() []string { return keys } +// AttrMap returns the map of attribute keys to values. +func (r *Rule) AttrMap() map[string]Expr { + m := make(map[string]Expr) + for _, expr := range r.Call.List { + if as, ok := expr.(*AssignExpr); ok { + if keyExpr, ok := as.LHS.(*Ident); ok { + m[keyExpr.Name] = as.RHS + } + } + } + return m +} + // AttrDefn returns the AssignExpr defining the rule's attribute with the given key. // If the rule has no such attribute, AttrDefn returns nil. func (r *Rule) AttrDefn(key string) *AssignExpr {