indentation support for notes

This commit is contained in:
René Schmelzer 2019-03-15 12:55:35 +01:00
parent ef19d71ca3
commit 6e55203a21
3 changed files with 419 additions and 25 deletions

View File

@ -350,32 +350,41 @@ Uses prefix (as PREFIX) to choose where to display it:
Plantuml elements like skinparam, rectangle, sprite, package, .
The opening { has to be the last visible character in the line (whitespace
might follow).")
(defvar plantuml-indent-regexp-note-start "^\s*\\(note\s+over\\|note\sas\s.*\\|note\s+\\(\\(?:\\(?:button\\|left\\|right\\|top\\)\\)\\)\\(?:\s+of\\)?\\)"
"Indentation regex for all plantuml note elements")
;; (defconst plantuml-indent-regexp-note-color "\\(?:\s+#\\w+\\)?" "optional color specification")
;; (defconst plantuml-indent-regexp-note-position "\\(?:\s+\\(?:left\\|right\\|top\\|bottom\\)\\)?" "optional position specification")
;; (defconst plantuml-indent-regexp-note-floating "\\(floating\s+\\)?" "optional floating specification")
;; (defvar plantuml-indent-regexp-base-note-start (concat "^\s*" plantuml-indent-regexp-note-floating "note" plantuml-indent-regexp-note-position "\\(?:\s+of\s+[^:]+?\\)?" plantuml-indent-regexp-note-color "$")
;; "Indentation regex for plantuml: note, note right, note left, note bottom, note top, note xxx of")
;; (defvar plantuml-indent-regexp-note-on-link-start (concat "^\s*note" plantuml-indent-regexp-note-position "\s+on\s+link" plantuml-indent-regexp-note-color "$")
;; "Indentation regex for plantuml: note on link")
;; (defvar plantuml-indent-regexp-note-over-start "^\s*note\s+over[^:]+?$"
;; "Indentation regex for plantuml: note over")
(defvar plantuml-indent-regexp-note-start "^\s*\\(floating\s+\\)?[hr]?note[^:]*?$" "simplyfied regex; note syntax is especially inconsistent across diagrams")
(defvar plantuml-indent-regexp-group-start "^\s*\\(alt\\|else\\|opt\\|loop\\|par\\|break\\|critical\\|group\\)\\(?:\s+.+\\|$\\)"
"Indentation regex for plantuml group elements that are defined for sequence diagrams.
Two variants for groups: keyword is either followed by whitespace and some text
or it is followed by line end.")
(defvar plantuml-indent-regexp-activate-start "^\s*activate\s+.+$")
(defvar plantuml-indent-regexp-box-start "^\s*box\s+.+$")
(defvar plantuml-indent-regexp-ref-start "^ref +over +[^:]+?$")
(defvar plantuml-indent-regexp-ref-start "^ref\s+over\s+[^:]+?$")
(defvar plantuml-indent-regexp-title-start "^\s*title$")
(defvar plantuml-indent-regexp-header-start "^\s*\\(?:\\(?:center\\|left\\|right\\)\s+header\\|header\\)$")
(defvar plantuml-indent-regexp-footer-start "^\s*\\(?:\\(?:center\\|left\\|right\\)\s+footer\\|footer\\)$")
(defvar plantuml-indent-regexp-legend-start "^\s*\\(?:legend\\|legend\s+\\(?:bottom\\|top\\)\\|legend\s+\\(?:center\\|left\\|right\\)\\|legend\s+\\(?:bottom\\|top\\)\s+\\(?:center\\|left\\|right\\)\\)$")
(defvar plantuml-indent-regexp-oldif-start "^.*if\s+\".*\"\s+then$")
(defvar plantuml-indent-regexp-oldif-start "^.*if\s+\".*\"\s+then$" "current activity diagram, sometimes already mentioned as deprecated")
(defvar plantuml-indent-regexp-start (list plantuml-indent-regexp-block-start
plantuml-indent-regexp-note-start
plantuml-indent-regexp-group-start
plantuml-indent-regexp-activate-start
plantuml-indent-regexp-box-start
plantuml-indent-regexp-ref-start
plantuml-indent-regexp-legend-start
plantuml-indent-regexp-note-start
plantuml-indent-regexp-oldif-start
plantuml-indent-regexp-title-start
plantuml-indent-regexp-header-start
plantuml-indent-regexp-footer-start
plantuml-indent-regexp-legend-start
plantuml-indent-regexp-oldif-start))
(defvar plantuml-indent-regexp-end "^\s*\\(?:}\\|endif\\|else\s*.*\\|end\\|end\s+note\\|end\s+box\\|end\s+ref\\|deactivate\s+.+\\|end\s+title\\|endheader\\|endfooter\\|endlegend\\)$")
(defvar plantuml-indent-regexp-end "^\s*\\(?:}\\|endif\\|else\s*.*\\|end\\|end\s+note\\|endhnote\\|endrnote\\|end\s+box\\|end\s+ref\\|deactivate\s+.+\\|end\s+title\\|endheader\\|endfooter\\|endlegend\\)$")
(setq plantuml-font-lock-keywords
`(
(,plantuml-types-regexp . font-lock-type-face)

View File

@ -313,22 +313,4 @@ this is no correct legend
endlegend
"))
(ert-deftest plantuml-test-block-indentation/note-as ()
"Test correct indentation of a note-as block."
(plantuml-test-indent-block
"
note as N1
This is a note
end note
"
"
note as N1
This is a note
end note
"
))
(provide 'plantuml-indentation-commons-test)
;;; plantuml-indentation-commons-test.el ends here

View File

@ -0,0 +1,403 @@
;;; plantuml-indentation-notes-test.el --- PlantUML Mode indentation tests -*- lexical-binding: t; -*-
;; Author: René Schmelzer
;; Maintainer: Carlo Sciolla (skuro)
;; URL: https://github.com/skuro/plantuml-mode
;;; Commentary:
;; Test indentation of note elements.
;; Notes are used in almost all diagrams, but not all types of notes
;; are supported in every diagram type.
;;; Code:
(ert-deftest plantuml-test-block-indentation/note-simple ()
"Test correct indentation of a simple note block."
(plantuml-test-indent-block
"
note: single line note
note
multi line note
end note
"
"
note: single line note
note
multi line note
end note
"
))
(ert-deftest plantuml-test-block-indentation/note-left-right ()
"Test correct indentation of a note left/right block."
(plantuml-test-indent-block
"
(*) --> \"Some Activity\"
note right: This activity has to be defined
\"Some Activity\" --> (*)
note right
This note is on
several lines
end note
(*) --> \"Some Activity\"
note left: This activity has to be defined
\"Some Activity\" --> (*)
note left
This note is on
several lines
end note
"
"
(*) --> \"Some Activity\"
note right: This activity has to be defined
\"Some Activity\" --> (*)
note right
This note is on
several lines
end note
(*) --> \"Some Activity\"
note left: This activity has to be defined
\"Some Activity\" --> (*)
note left
This note is on
several lines
end note
" ))
(ert-deftest plantuml-test-block-indentation/note-xxx-of ()
"Test correct indentation of a note xxx of block.
plantuml.com:
You can use the note left of, note right of, note top of,
note bottom of keywords to define notes related to a single
object."
(plantuml-test-indent-block
"
note right of Alice: This is displayed right of Alice.
note left of Alice #aqua
This is displayed
left of Alice.
end note
note left of Alice: This is displayed left of Alice.
note right of Alice #aqua
This is displayed
right of Alice.
end note
note right of (Use)
A note can also
be on several lines
end note
note left of HTTP : Web Service only
note right of [First Component]
A note can also
be on several lines
end note
"
"
note right of Alice: This is displayed right of Alice.
note left of Alice #aqua
This is displayed
left of Alice.
end note
note left of Alice: This is displayed left of Alice.
note right of Alice #aqua
This is displayed
right of Alice.
end note
note right of (Use)
A note can also
be on several lines
end note
note left of HTTP : Web Service only
note right of [First Component]
A note can also
be on several lines
end note
"
))
(ert-deftest plantuml-test-block-indentation/note-on-link ()
"Test correct indentation of a note xxx of block.
plantuml.com:
You can also use note left on link, note right on link,
note top on link, note bottom on link if you want to change
the relative position of the note with the label."
(plantuml-test-indent-block
"
class Dummy
Dummy --> Foo : A link
note on link #red: note that is red
Dummy --> Foo2 : Another link
note right on link #blue
this is my note on right link
and in blue
end note
note left on link #00FFFF
this is my note on left link
and in color as number
end note
"
"
class Dummy
Dummy --> Foo : A link
note on link #red: note that is red
Dummy --> Foo2 : Another link
note right on link #blue
this is my note on right link
and in blue
end note
note left on link #00FFFF
this is my note on left link
and in color as number
end note
"
))
(ert-deftest plantuml-test-block-indentation/note-over ()
"Test correct indentation of a note-over block."
(plantuml-test-indent-block
"
note over Alice: This is displayed over Alice.
note over Alice, Bob #FFAAAA: This is displayed over Bob and Alice.
note over Bob, Alice
This is yet another
example of
a long note.
end note
"
"
note over Alice: This is displayed over Alice.
note over Alice, Bob #FFAAAA: This is displayed over Bob and Alice.
note over Bob, Alice
This is yet another
example of
a long note.
end note
"
))
;; Here we have an inconsistency (again) in plantuml syntax
;; single line note as …’ does not contain a ?:
;;
;; (ert-deftest plantuml-test-block-indentation/note-as ()
;; "Test correct indentation of a note-as block."
;; (plantuml-test-indent-block
;; "
;; :Main Admin: as Admin
;; (Use the application) as (Use)
;; User -> (Start)
;; User --> (Use)
;; Admin ---> (Use)
;; note right of Admin : This is an example.
;; note right of (Use)
;; A note can also
;; be on several lines
;; end note
;; note \"This note is connected to several objects.\" as N2 #RED
;; (Start) .. N2
;; N2 .. (Use)
;; note as N3 #blue
;; This note is connected
;; to several objects as well.
;; end note
;; (Start) .. N3
;; N3 .. Admin
;; "
;; "
;; :Main Admin: as Admin
;; (Use the application) as (Use)
;; User -> (Start)
;; User --> (Use)
;; Admin ---> (Use)
;; note right of Admin : This is an example.
;; note right of (Use)
;; A note can also
;; be on several lines
;; end note
;; note \"This note is connected to several objects.\" as N2 #RED
;; (Start) .. N2
;; N2 .. (Use)
;; note as N3 #blue
;; This note is connected
;; to several objects as well.
;; end note
;; (Start) .. N3
;; N3 .. Admin
;; "
;; ))
(ert-deftest plantuml-test-block-indentation/note-floating ()
"Test correct indentation of a floating note block."
(plantuml-test-indent-block
"
floating note left: This is a note
:foo2;
floating note right
This note is on several
//lines// and can
contain <b>HTML</b>
====
* Calling the method \"\"foo()\"\" is prohibited
end note
"
"
floating note left: This is a note
:foo2;
floating note right
This note is on several
//lines// and can
contain <b>HTML</b>
====
* Calling the method \"\"foo()\"\" is prohibited
end note
"
))
(ert-deftest plantuml-test-block-indentation/note-h-r-note ()
"Test correct indentation of a [hr]note block."
(plantuml-test-indent-block
"
caller -> server : conReq
rnote over caller : idle
hnote over caller : idle
caller <- server : conConf
rnote over server
r as rectangle
h as hexagon
endrnote
hnote over server
r as rectangle
h as hexagon
endrnote
"
"
caller -> server : conReq
rnote over caller : idle
hnote over caller : idle
caller <- server : conConf
rnote over server
r as rectangle
h as hexagon
endrnote
hnote over server
r as rectangle
h as hexagon
endrnote
"
))
(ert-deftest plantuml-test-block-indentation/note-creole-html ()
"Test correct indentation of a note block with creole/html."
(plantuml-test-indent-block
"
participant Alice
participant \"The **Famous** Bob\" as Bob
Alice -> Bob : hello --there--
... Some ~~long delay~~ ...
Bob -> Alice : ok
note left
This is **bold**
This is //italics//
This is \"\"monospaced\"\"
This is --stroked--
This is __underlined__
This is ~~waved~~
end note
Alice -> Bob : A //well formatted// message
note right of Alice
This is <back:cadetblue><size:18>displayed</size></back>
__left of__ Alice.
end note
note left of Bob
<u:red>This</u> is <color #118888>displayed</color>
**<color purple>left of</color> <s:red>Alice</strike> Bob**.
end note
note over Alice, Bob
<w:#FF33FF>This is hosted</w> by <img sourceforge.jpg>
end note
"
"
participant Alice
participant \"The **Famous** Bob\" as Bob
Alice -> Bob : hello --there--
... Some ~~long delay~~ ...
Bob -> Alice : ok
note left
This is **bold**
This is //italics//
This is \"\"monospaced\"\"
This is --stroked--
This is __underlined__
This is ~~waved~~
end note
Alice -> Bob : A //well formatted// message
note right of Alice
This is <back:cadetblue><size:18>displayed</size></back>
__left of__ Alice.
end note
note left of Bob
<u:red>This</u> is <color #118888>displayed</color>
**<color purple>left of</color> <s:red>Alice</strike> Bob**.
end note
note over Alice, Bob
<w:#FF33FF>This is hosted</w> by <img sourceforge.jpg>
end note
"
))
;;; plantuml-indentation-notes-test.el ends here