From 471505e5d8f63ff6dede3a508281e344b7199774 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sat, 10 Jul 2021 16:17:47 +0200 Subject: [PATCH 1/2] Support indentation for switch statement --- plantuml-mode.el | 4 ++ .../plantuml-indentation-activity-new-test.el | 38 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/plantuml-mode.el b/plantuml-mode.el index e40ba0d..13b5706 100644 --- a/plantuml-mode.el +++ b/plantuml-mode.el @@ -589,6 +589,7 @@ or it is followed by line end.") (defvar plantuml-indent-regexp-newif-start "^\s*\\(?:else\\)?if\s+(.*)\s+then\s*.*$") (defvar plantuml-indent-regexp-loop-start "^\s*\\(?:repeat\s*\\|while\s+(.*).*\\)$") (defvar plantuml-indent-regexp-fork-start "^\s*\\(?:fork\\|split\\)\\(?:\s+again\\)?\s*$") + (defvar plantuml-indent-regexp-case-start "^\s*\\(?:switch\\|case\\)\s-*(.*)\s*$") (defvar plantuml-indent-regexp-macro-start "^\s*!definelong.*$") (defvar plantuml-indent-regexp-user-control-start "^.*'.*\s*PLANTUML_MODE_INDENT_INCREASE\s*.*$") (defvar plantuml-indent-regexp-start (list plantuml-indent-regexp-block-start @@ -601,6 +602,7 @@ or it is followed by line end.") plantuml-indent-regexp-newif-start plantuml-indent-regexp-loop-start plantuml-indent-regexp-fork-start + plantuml-indent-regexp-case-start plantuml-indent-regexp-title-start plantuml-indent-regexp-header-start plantuml-indent-regexp-footer-start @@ -621,6 +623,7 @@ or it is followed by line end.") (defvar plantuml-indent-regexp-newif-end "^\s*\\(endif\\|elseif\\|else\\)\s*.*$") (defvar plantuml-indent-regexp-loop-end "^\s*\\(repeat\s*while\\|endwhile\\)\s*.*$") (defvar plantuml-indent-regexp-fork-end "^\s*\\(\\(fork\\|split\\)\s+again\\|end\s+\\(fork\\|split\\)\\)\s*$") + (defvar plantuml-indent-regexp-case-end "^\s*\\(case\s-*([^)]*)\\|endswitch\\)\s*\\('.*\\)?$") (defvar plantuml-indent-regexp-macro-end "^\s*!enddefinelong\s*\\('.*\\)?$") (defvar plantuml-indent-regexp-user-control-end "^.*'.*\s*PLANTUML_MODE_INDENT_DECREASE\s*.*$") (defvar plantuml-indent-regexp-end (list plantuml-indent-regexp-block-end @@ -633,6 +636,7 @@ or it is followed by line end.") plantuml-indent-regexp-newif-end plantuml-indent-regexp-loop-end plantuml-indent-regexp-fork-end + plantuml-indent-regexp-case-end plantuml-indent-regexp-title-end plantuml-indent-regexp-header-end plantuml-indent-regexp-footer-end diff --git a/test/plantuml-indentation-activity-new-test.el b/test/plantuml-indentation-activity-new-test.el index 98f6e2d..1f6167b 100644 --- a/test/plantuml-indentation-activity-new-test.el +++ b/test/plantuml-indentation-activity-new-test.el @@ -384,6 +384,44 @@ stop @enduml")) +(ert-deftest plantuml-test-indentation/activity-new/switch () + "Test correct indentation of plantuml activity-new complete example +These code examples are taken from www.plantuml.com" + (plantuml-test-indent-block + "@startuml +start +switch (test?) +case ( condition A ) +:Text 1; +case ( condition B ) +:Text 2; +case ( condition C ) +:Text 3; +case ( condition D ) +:Text 4; +case ( condition E ) +:Text 5; +endswitch +stop +@enduml" + + "@startuml +start +switch (test?) +case ( condition A ) + :Text 1; +case ( condition B ) + :Text 2; +case ( condition C ) + :Text 3; +case ( condition D ) + :Text 4; +case ( condition E ) + :Text 5; +endswitch +stop +@enduml")) + (provide 'plantuml-indentation-activity-new-test) ;;; plantuml-indentation-activity-old-test.el ends here From 31cc2e9a7af0e24d8b44a2132255f0bc33661a2a Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Tue, 3 Aug 2021 17:15:07 +0200 Subject: [PATCH 2/2] Fix regular expression for end of switch statement The original regular expression tried to look for a matching closing parenthesis, which failed in case of nested parentheses inside the case statement. This is fixed now, we do not care anymore about whether parentheses match or not. --- plantuml-mode.el | 2 +- .../plantuml-indentation-activity-new-test.el | 40 ++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/plantuml-mode.el b/plantuml-mode.el index 13b5706..caa978c 100644 --- a/plantuml-mode.el +++ b/plantuml-mode.el @@ -623,7 +623,7 @@ or it is followed by line end.") (defvar plantuml-indent-regexp-newif-end "^\s*\\(endif\\|elseif\\|else\\)\s*.*$") (defvar plantuml-indent-regexp-loop-end "^\s*\\(repeat\s*while\\|endwhile\\)\s*.*$") (defvar plantuml-indent-regexp-fork-end "^\s*\\(\\(fork\\|split\\)\s+again\\|end\s+\\(fork\\|split\\)\\)\s*$") - (defvar plantuml-indent-regexp-case-end "^\s*\\(case\s-*([^)]*)\\|endswitch\\)\s*\\('.*\\)?$") + (defvar plantuml-indent-regexp-case-end "^\s*\\(case\s-*(.*)\\|endswitch\\)\s*\\('.*\\)?$") (defvar plantuml-indent-regexp-macro-end "^\s*!enddefinelong\s*\\('.*\\)?$") (defvar plantuml-indent-regexp-user-control-end "^.*'.*\s*PLANTUML_MODE_INDENT_DECREASE\s*.*$") (defvar plantuml-indent-regexp-end (list plantuml-indent-regexp-block-end diff --git a/test/plantuml-indentation-activity-new-test.el b/test/plantuml-indentation-activity-new-test.el index 1f6167b..176b01e 100644 --- a/test/plantuml-indentation-activity-new-test.el +++ b/test/plantuml-indentation-activity-new-test.el @@ -384,7 +384,7 @@ stop @enduml")) -(ert-deftest plantuml-test-indentation/activity-new/switch () +(ert-deftest plantuml-test-indentation/activity-new/switch-1 () "Test correct indentation of plantuml activity-new complete example These code examples are taken from www.plantuml.com" (plantuml-test-indent-block @@ -422,6 +422,44 @@ endswitch stop @enduml")) +(ert-deftest plantuml-test-indentation/activity-new/switch-2 () + "Test correct indentation of plantuml activity-new complete example +These code examples are taken from www.plantuml.com" + (plantuml-test-indent-block + "@startuml +start +switch (test? (is it?)) +case ( condition (A) ) +:Text 1; +case ( condition B (we do not care whether parentheses match or not) +:Text 2; +case ( condition C ))) +:Text 3; +case ( condition D ) +:Text 4; +case ( condition E ) +:Text 5; +endswitch +stop +@enduml" + + "@startuml +start +switch (test? (is it?)) +case ( condition (A) ) + :Text 1; +case ( condition B (we do not care whether parentheses match or not) + :Text 2; +case ( condition C ))) + :Text 3; +case ( condition D ) + :Text 4; +case ( condition E ) + :Text 5; +endswitch +stop +@enduml")) + (provide 'plantuml-indentation-activity-new-test) ;;; plantuml-indentation-activity-old-test.el ends here