mirror of https://github.com/golang/go.git
cmd/compile: normalize spaces in rewrite rule comments.
In addition to look nicer to the eye, this allows to reformat and indent rules without causing spurious changes to the generated file, making it easier to spot functional changes. After this CL, all CLs that will aggregate rules through the new "|" functionality should cause no changes to the generated files. Change-Id: Icec283585ba8d7b91c79d76513c1d83dca4b30aa Reviewed-on: https://go-review.googlesource.com/95216 Run-TryBot: Giovanni Bajo <rasky@develer.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
4dc25ceda4
commit
70fd25e4e1
|
|
@ -60,18 +60,22 @@ func (r Rule) String() string {
|
|||
return fmt.Sprintf("rule %q at %s", r.rule, r.loc)
|
||||
}
|
||||
|
||||
func normalizeSpaces(s string) string {
|
||||
return strings.Join(strings.Fields(strings.TrimSpace(s)), " ")
|
||||
}
|
||||
|
||||
// parse returns the matching part of the rule, additional conditions, and the result.
|
||||
func (r Rule) parse() (match, cond, result string) {
|
||||
s := strings.Split(r.rule, "->")
|
||||
if len(s) != 2 {
|
||||
log.Fatalf("no arrow in %s", r)
|
||||
}
|
||||
match = strings.TrimSpace(s[0])
|
||||
result = strings.TrimSpace(s[1])
|
||||
match = normalizeSpaces(s[0])
|
||||
result = normalizeSpaces(s[1])
|
||||
cond = ""
|
||||
if i := strings.Index(match, "&&"); i >= 0 {
|
||||
cond = strings.TrimSpace(match[i+2:])
|
||||
match = strings.TrimSpace(match[:i])
|
||||
cond = normalizeSpaces(match[i+2:])
|
||||
match = normalizeSpaces(match[:i])
|
||||
}
|
||||
return match, cond, result
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue