From 381f5f3baa5c228ff6bb507b2aac0dcf941062a9 Mon Sep 17 00:00:00 2001 From: Marco Maccaferri Date: Wed, 12 Jun 2024 07:49:33 +0200 Subject: [PATCH] Structure definitiona formatting fixes --- .../propeller/spin2/Spin2FormatterTest.java | 14 ++++++++++++++ .../src/com/maccasoft/propeller/Formatter.java | 6 +++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/spin-tools/src-tests/com/maccasoft/propeller/spin2/Spin2FormatterTest.java b/modules/spin-tools/src-tests/com/maccasoft/propeller/spin2/Spin2FormatterTest.java index 0110d8ef..8a625b81 100644 --- a/modules/spin-tools/src-tests/com/maccasoft/propeller/spin2/Spin2FormatterTest.java +++ b/modules/spin-tools/src-tests/com/maccasoft/propeller/spin2/Spin2FormatterTest.java @@ -582,4 +582,18 @@ void testExpressions() { + "", text); } + @Test + void testStructureDefinition() { + Formatter subject = new Spin2Formatter(); + String text = subject.format("" + + "CON point(x,y)\n" + + " line(point a,point b,color)\n" + + ""); + Assertions.assertEquals("" + + "CON\n" + + " point(x, y)\n" + + " line(point a, point b, color)\n" + + "", text); + } + } diff --git a/modules/spin-tools/src/com/maccasoft/propeller/Formatter.java b/modules/spin-tools/src/com/maccasoft/propeller/Formatter.java index 52fc274a..89eb82eb 100644 --- a/modules/spin-tools/src/com/maccasoft/propeller/Formatter.java +++ b/modules/spin-tools/src/com/maccasoft/propeller/Formatter.java @@ -244,6 +244,10 @@ void formatConstant(FormatterStringBuilder sb) { } break; case 4: + if ("(".equals(token.getText()) || ")".equals(token.getText())) { + sb.append(token); + break; + } if ("=".equals(token.getText())) { sb.append(" "); sb.append(token); @@ -260,7 +264,7 @@ void formatConstant(FormatterStringBuilder sb) { state = 6; break; } - if (sb.lastChar() != ' ') { + if (sb.lastChar() != ' ' && sb.lastChar() != '(') { sb.append(" "); } sb.append(token);