# Xù - an MscGen super set _**It is MscGen, but not as we know it**_ ## Inline expressions [SDL][2] has a feature called _inline expressions_. They allow you to group a bunch of arcs and label them somehow. To define a loop, for instance. Or a conditional statement. [UML2][3] sequence diagrams have a similar concept called "combined fragments" (see paragraph 14.3.3 of the linked document for details). Behaviour specification is not a particularly strong suit of interaction diagrams (sequence charts/ diagrams/ collaboration diagrams), as Martin Fowler correctly notes in [UML distilled][1]. At this time (November 2015) MscGen does not support them. Nonetheless inline expressions are damn handy. Hence Xù - a superset of MscGen that includes them. ## An example This is an example of a Xù script describing an interaction that loops over a list of changes and sorts the old ones to a deletion queue, and the rest to a birth queue: ```xu msc { width=700, hscale=0.8; a, b [label="change store"], c, d [label="necro queue"], e [label="natalis queue"]; a =>> b [label="get change list()"]; a alt e [label="changes found"] { b >> a [label="list of changes"]; a =>> c [label="cull old stuff (list of changes)"]; b loop e [label="for each change"] { c =>> b [label="get change()"]; b >> c [label="change"]; c alt e [label="change too old"] { c =>> d [label="queue(change)"]; --- [label="change newer than latest run"]; c =>> e [label="queue(change)"]; --- [label="all other cases"]; ||| [label="leave well alone"]; }; }; c >> a [label="done processing"]; --- [label="nothing found"]; b >> a [label="nothing"]; a note a [label="silent exit"]; }; } ``` Rendered (e.g. with the [online interpreter](https://sverweij.github.io/mscgen_js/index.html?utm_source=wikum.xu&lang=xu&msc=msc%20{%0A%20%20width%3D700%2C%20hscale%3D0.8%3B%0A%20%20a%2C%20b%20[label%3D%22change%20store%22]%2C%20c%2C%20d%20[label%3D%22necro%20queue%22]%2C%0A%20%20e%20[label%3D%22natalis%20queue%22]%3B%0A%0A%20%20a%20%3D%3E%3E%20b%20[label%3D%22get%20change%20list%28%29%22]%3B%0A%20%20a%20alt%20e%20[label%3D%22changes%20found%22]%20{%0A%20%20%20%20b%20%3E%3E%20a%20[label%3D%22list%20of%20changes%22]%3B%0A%20%20%20%20a%20%3D%3E%3E%20c%20[label%3D%22cull%20old%20stuff%20%28list%20of%20changes%29%22]%3B%0A%20%20%20%20b%20loop%20e%20[label%3D%22for%20each%20change%22]%20{%0A%20%20%20%20%20%20c%20%3D%3E%3E%20b%20[label%3D%22get%20change%28%29%22]%3B%0A%20%20%20%20%20%20b%20%3E%3E%20c%20[label%3D%22change%22]%3B%0A%20%20%20%20%20%20c%20alt%20e%20[label%3D%22change%20too%20old%22]%20{%0A%20%20%20%20%20%20%20%20c%20%3D%3E%3E%20d%20[label%3D%22queue%28change%29%22]%3B%0A%20%20%20%20%20%20%20%20---%20[label%3D%22change%20newer%20than%20latest%20run%22]%3B%0A%20%20%20%20%20%20%20%20c%20%3D%3E%3E%20e%20[label%3D%22queue%28change%29%22]%3B%0A%20%20%20%20%20%20%20%20---%20[label%3D%22all%20other%20cases%22]%3B%0A%20%20%20%20%20%20%20%20|||%20[label%3D%22leave%20well%20alone%22]%3B%0A%20%20%20%20%20%20}%3B%0A%20%20%20%20}%3B%0A%20%20%20%20c%20%3E%3E%20a%20[label%3D%22done%20processing%22]%3B%0A%20%20%20%20---%20[label%3D%22nothing%20found%22]%3B%0A%20%20%20%20b%20%3E%3E%20a%20[label%3D%22nothing%22]%3B%0A%20%20%20%20a%20note%20a%20[label%3D%22silent%20exit%22]%3B%0A%20%20}%3B%0A}) ) this looks like so:  ## Syntax ### Inline expression syntax As you can see, the syntax of the inline expressions is very similar to that of regular arcs, the only difference being that inline expressions have a section of arcs, enclosed by curly brackets. ```peggy spanarc = _ from:identifier _ kind:spanarctoken _ to:identifier _ al:("[" al:attributelist "]" {return al})? _ "{" _ arclist:arclist _ "}" _ ";" ``` To compare, this is how a regular arc looks: ```peggy regulararc = _ from:identifier _ kind:arctoken _ to:identifier _ ("[" attributelist "]")? _ ";" ``` Some more examples ```xu break { a => b [label="Can you do this?"]; b >> a [label="Fatal error"]; }; ``` Arguments go into the label as free text. ```xu loop [label="for each grain of sand on the beach"] { a => beach [label="get grain"]; a => progeny [label="add"]; }; ``` ```xu msc { john, shed, bike; john alt bike [label="wheather is nice"] { john =>> shed [label="get(bike)"]; shed >> john [label="bike"]; john =>> bike [label="use"]; --- [label="else"]; ||| [label="john stays at home"]; }; } ``` To separate sections to execute in parallel you can use a comment line, like so: ```xu par { a => b; b >> a; ---; a => c; c => d; } ``` If you're interested in the complete grammar: the parsing expression grammar we use to generate the parser is [included in the source][4]. ### start token MscGen uses `msc` as a start token. As Xù was designed as an extension to MscGen the same goes for Xù. If you want to be expressly clear your script is a Xù script you can also use that: ```xu xu { arcgradient=20; a,b,c; a par c [label="Saying hello"] { a =>> * [label="hi"]; ---; b =>> * [label="hi"]; ---; c =>> * [label="hi"]; }; a aboxc [label="Now we know each other a bit"]; } ``` ### watermark Just like msgenny, Xù supports a "watermark" _option_: `watermark="xù rocks!"`; that puts a watermark diagonally on the rendered chart. ### autowrapping options MscGen has an option to automatically wrap text on regular arcs (`wordwraparcs`), which is off by default. Text in any box (`note`, `box`, `rbox` and `abox`) or entity always automatically wraps to fit into the box. Both Xù and MsGenny have options to also switch that off - `wordwrapboxes` on false makes sure no text in any box gets wrapped. Likewise `wordwrapentities` on false makes sure no text in entities gets wrapped. ### title attribute - for tool tips From version 1.9.0 the xù language supports the `title` attribute. In SVG output the graphics renderer packaged with mscgenjs renders these as `
| feature | SDL-RT 2.3 inline expression | UML 2 combined fragment | xù |
|---|---|---|---|
| Alternatives - if with an optional else | alt | alt, else | alt |
| Alternatives - if with noelse | opt | opt | opt |
| Break - an exception occurred. After this nothing happens. | exc | break | excbreak
|
| Parralel - do several things at once | par | par | par |
| Weak sequencing - stuff within here can happen in any order across the instances | seq | seq | seq |
| Strict sequencing - stuff within here can happen in only this order across the instances | _not available_ | strict | strict |
| Negative - this is not happening | _not available_ | neg | neg |
| Critical region - this is important, execute at once | _not available_ | critical | critical |
| Ignore/ consider | _not available_ | ignore, consider | considerignore |
| Assertion - this stuff must be true | _not available_ | assert | assert |
| Loop - repeat this | loop | loop | loop |
| Reference - it's not here, but there's a diagram somewhere else detailing this | not available as an "inline expression" but as 'MSC reference' | _not available_ | ref |