fix(format): keep statement separators and canonical macro bodies
Assisted-by: GLM 5.3 Flash
This commit is contained in:
+16
-6
@@ -254,11 +254,12 @@ func renderPreproc(line []token.Token) string {
|
||||
line[2].Kind == token.String {
|
||||
return "#include " + line[2].Text
|
||||
}
|
||||
parts := make([]string, 0, len(line)-1)
|
||||
for _, t := range line[1:] {
|
||||
parts = append(parts, t.Text)
|
||||
}
|
||||
return "#" + strings.Join(parts, " ")
|
||||
// The body of a directive, a macro definition included, is an ordinary
|
||||
// token run: rendering it through renderOps applies the same punctuation
|
||||
// rules as everywhere else, so a macro body keeps its canonical spelling
|
||||
// ($v, (a, b), the ';' separators between statements) instead of being
|
||||
// spread with a space between every token.
|
||||
return "#" + renderOps(line[1:])
|
||||
}
|
||||
|
||||
// renderOps re-spaces a run of operand tokens into canonical form. It never
|
||||
@@ -348,6 +349,13 @@ func spaceBetween(prev, cur token.Token) bool {
|
||||
return false
|
||||
case token.Comma:
|
||||
return false
|
||||
case token.Semicolon:
|
||||
// A ';' is a statement separator on the assembly path, not an
|
||||
// operand: dropping it would fuse two statements into a line the
|
||||
// assembler rejects, so it must survive as punctuation. It glues
|
||||
// to the statement it ends and the next statement takes one space,
|
||||
// matching the toolchain's listing style.
|
||||
return false
|
||||
case token.Star, token.Plus, token.Minus, token.Slash, token.Pipe:
|
||||
return false
|
||||
case token.LShift, token.RShift, token.Arrow, token.At:
|
||||
@@ -376,7 +384,9 @@ func spaceBetween(prev, cur token.Token) bool {
|
||||
return false
|
||||
case token.LAngle, token.RAngle:
|
||||
return false
|
||||
case token.Comma:
|
||||
case token.Comma, token.Semicolon:
|
||||
// The statement after a ';' separator takes its own space, exactly
|
||||
// like the operand after a comma.
|
||||
return true
|
||||
}
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user