Docs · Reference
Copy as Markdown
Grammar
The text of a UJN diagram, from @startujn to @endujn, as a formal grammar: section 22 made exact, and tested on every build of this site.
UJN 0.1 draft · revision 23 · November 29, 2026 · Changes
Check a file#
The checker is plain Python, standard library only. It reads the grammar file as written, so what it checks is exactly the grammar on this page.
Command line
python ujn_grammar.py checkout.pumlpython ujn_grammar.py --strict checkout.puml # values only in the forms of section 5python run_tests.py # the test setsDownload: ujn.ebnf · ujn_grammar.py · the whole kit with its test sets (zip)
How it is tested#
This page is built only when every test passes:
- 121 of 121 valid files pass: every example of the spec and of these docs, the site's journeys, and edge cases for every comment, block, arrow token, label and value form.
- 88 of 88 invalid files fail; the module rejects each of them with a syntax error.
- 34 more files pin the known differences with the module, listed below.
The grammar#
ujn.ebnf
(* ===================================================================================================== UJN grammar: the text of a UI Journey Notation diagram, from @startujn to @endujn. Written for spec revision 23 (proposal/ujn-language-v23.md): section 22 made exact, and checked line by line against the PlantUML module (UjnParser.java, UjnValues.java) and the PlantUML code that reads a file before UJN does (diagram splitting, comments, the preprocessor). Tested by ujn_grammar.py and run_tests.py. --------------------------------------------------------------------------------------------------- The notation of this file --------------------------------------------------------------------------------------------------- name = expression ; a rule. Names are letters, digits, "-" and "_". The first rule is the start. "text" a terminal, matched exactly (case matters). Inside it, \" is a quote, \\ a backslash, \n a line end and \t a tab. /regex/ a lexical class: a Python regular expression, matched at the current place (one match, as Python's re finds it). Inside it, \/ is a slash, and <<NAME>> stands for the regex of the rule NAME (a rule made of one /regex/). [ e ] e, or nothing. { e } e, zero or more times. ( e ) a group. e1 e2 e1, then e2. e1 | e2 e1 or e2. comments from a left parenthesis and a star to the next star and right parenthesis. A choice and a repetition try every way, not only the first that fits: the grammar is an ordinary context-free grammar over its terminals and lexical classes, read with backtracking. A file is valid when the start rule, `file`, covers all of it. UPPER-CASE names are lexical classes (as in section 22); lower-case names are the syntax. Names that start with raw- are the text the module reads as a value whatever its key; `ujn_grammar.py --strict` drops them, so that every value must take one of the forms of section 5. --------------------------------------------------------------------------------------------------- How a file is read --------------------------------------------------------------------------------------------------- Line ends are "\n". As PlantUML does, the checker reads CR LF and a CR alone as a line end, and drops a byte order mark at the start of the file. The grammar covers files made of printable characters, tabs and line ends. Other control characters (U+0000 to U+001F except tab, line feed and carriage return) and the characters Java treats as line ends inside a line (U+0085, U+2028, U+2029), and U+E103 (a PlantUML line break), are out of scope: the rule SCOPE refuses a file that holds one. Also out of scope, because they are PlantUML features with no place in a UJN file: - @pause, @unpause and @append lines (PlantUML drops or adds lines with them); - a line where @start follows only punctuation, such as `' @startujn` or `# @startujn` (PlantUML starts a diagram there, and removes that punctuation from the lines after it); - inside block comments and preprocessor blocks, and in text outside a diagram, the grammar follows a line that ends with one backslash only as far as noted at each rule. --------------------------------------------------------------------------------------------------- What the grammar covers, and what it leaves to the module --------------------------------------------------------------------------------------------------- The grammar follows the module's parser line by line, and the PlantUML steps before it: how a file is cut into diagrams, which lines are comments, which lines the preprocessor takes. Everything the module only warns about (21) is valid here: an unknown key, a key that does not apply, a value of the wrong kind, a missing title. Which value form a key takes depends on the key (section 5 and the key tables of each section), so `value` lists every form of section 5 and ends with `raw-value`. Left to the module, because they need more than a grammar: - two nodes with the same handle, display id, unique id or friendly id, and an arrow to a handle that no statement declares (syntax errors in the module, 21); - what the preprocessor does with the lines it takes. They are skipped here, not run: an !if without its !endif (or an !endif, !else or !endwhile alone), a failed !assert, a missing !include or theme, a Python error, or a function without !return is not caught (pinned in differ/, named module-only-preprocessor-...); - two module bugs, where the module crashes: a number too large for it (`view_start: 99999999999`), and a block comment or preprocessor block that is never closed after the journey line alone (pinned in differ/, named module-only-crash-...). Stricter than the module on purpose (each case is pinned by a file in differ/, named module-reads-...): - a guard that starts with a double quote and is not one closed string (`"x" or "y`, `"abc`): the module checks only the first character (a module bug); - a guard that starts with [ and has no ] (`: [Save`), or that starts with [ after a trigger; and, after a trigger whose double quote is not closed, a guard that holds a double quote other than as one closed string; - a line that ends with one backslash: PlantUML joins it to the next line before UJN reads it; - braces that do not pair, on a line that ends with }: a line that closes a block (`title: a } b }`), a block that opens and closes on one line (`view a { title: x }{{auto}}`), or a line that opens a block; and a value where a brace pair holds a square bracket that does not pair (`title: {[}`); - lines the preprocessor writes: the grammar reads a preprocessor line as a line to skip, and every other line as written, so a statement that a macro, a procedure, an !foreach, the branch of an !if that is not taken, or a !{...} line writes is not seen; - a /'''name'''/ comment inside a word (PlantUML removes it anywhere; the grammar only between tokens). ===================================================================================================== *) (* ---------------------------------------------------------------- the file and its diagrams (2, 3) *) (* As PlantUML does, a file may hold text outside its diagrams, other PlantUML diagrams, and more than one UJN diagram. A diagram runs from a line that starts with @start (or \start) to the next line that starts with @end (or \end); one that a new @start line interrupts is dropped. *) file = SCOPE { outside } diagram { outside | diagram } ; SCOPE = /(?![\s\S]*[\x00-\x08\x0B\x0C\x0E-\x1F\x85\u2028\u2029\uE103])/ ; outside = OUTSIDE-LINE | OTHER-DIAGRAM | DROPPED-START ; OUTSIDE-LINE = /(?!<<START>>)(?:[^\n]*(?<!\\)\\\n(?:[ \t]*'[^\n]*\n)*)*(?:[^\n]*\n|[^\n]+(?![\s\S]))/ ; (* a line that is not a start line; one that ends with one backslash takes in the next line (after comment lines), even a start line *)OTHER-DIAGRAM = /[ \t]*[@\\]start(?![uU][jJ][nN])[^\n]+\n(?:(?!<<DIRECTIVE>>)[^\n]*\n)*[ \t]*[@\\]end[^\n]*(?:\n|(?![\s\S]))/ ;DROPPED-START = /<<START>>[^\n]*\n(?:(?!<<DIRECTIVE>>)[^\n]*\n)*(?:(?=<<START>>)|(?!<<DIRECTIVE>>)[^\n]*(?![\s\S]))/ ; (* a start line with no end line before the next start line or the end of the file *) START = /[ \t]*[@\\]start[^\n]/ ;DIRECTIVE = /[ \t]*[@\\](?:start[^\n]|end)/ ; (* a start line or an end line *)LINE = /[^\n]*(?<![^\\]\\)\n/ ; (* the rest of a line that does not end with one backslash (see NL) *) diagram = start-line [ yaml-header ] { skip | top-statement } (* before the journey: increment, render and color blocks (2) *) journey-line { skip | journey-entry } (* key: value lines right under the journey line (3) *) { skip | statement } (* one statement per line; a block may run over several lines (2) *) end-line ; start-line = /[ \t]*[@\\]start[uU][jJ][nN][^\n]*/ NL ; (* @startujn, any case after start; anything may follow, such as @startujn(id=x) *)end-line = /[ \t]*[@\\]end(?:[^\n]*(?<!\\)\\\n)*[^\n]*/ ( /\n/ | EOF ) ; (* any line that starts with @end: @endujn, @enduml, @end foo *)yaml-header = /---\n(?:(?!---\n)(?!<<DIRECTIVE>>)<<LINE>>)*---/ NL ; (* a PlantUML header right after the start line: lines between two lines that are exactly --- *) (* ---------------------------------------------------------------- lines to skip (2) *) skip = blank-line | comment-line | block-comment | preproc ; blank-line = _ NL ; comment-line = /[ \t]*'[^\n]*/ NL ; (* first non-blank character is ' *) block-comment = /[ \t]*\/'[^\n]*'\/[ \t]*\n/ (* a line that starts with /' and ends with '/ *) | /[ \t]*\/'\/[ \t]*\n/ (* a line that holds only /'/ is blank *) | /[ \t]*\/'(?!\/)(?![^\n]*'\/)<<LINE>>(?:(?!<<DIRECTIVE>>)(?![^\n]*'\/[ \t]*\n)<<LINE>>)*(?:(?!<<DIRECTIVE>>)[^\n]*'\/[ \t]*\n|(?=[ \t]*[@\\]end))/ ; (* /' on a line with no '/, then every line up to the first that ends with '/; with none, the rest of the diagram (PlantUML drops it) *) (* The preprocessor takes these lines; the grammar skips them without running them. *) preproc = /[ \t]*(?:<<LEAD-COMMENT>>[ \t]*)?!(?:<<PP-OPENER>>)<<LINE>>(?:(?!<<DIRECTIVE>>)(?!<<PP-CLOSER>>)<<LINE>>)*(?:<<PP-CLOSER>><<LINE>>|(?=[ \t]*[@\\]end))/ (* a procedure, a function or a definelong, up to the first !endprocedure, !endfunction or !enddefinelong (any of the three); with none, the rest of the diagram *) | /[ \t]*!python[ \t]*\n(?:(?!<<DIRECTIVE>>)(?![ \t]*!endpy[ \t]*\n)<<LINE>>)*[ \t]*!endpy[ \t]*\n/ | /[ \t]*(?:<<LEAD-COMMENT>>[ \t]*)?!/ pp-line /[^\n]*/ NL | /[ \t]*!exit[ \t]*\n(?:(?!<<DIRECTIVE>>)<<LINE>>)*(?=[ \t]*[@\\]end)/ ; (* !exit: PlantUML drops the rest of the diagram *) PP-OPENER = /(?:(?:unquoted|final)[ \t])*procedure[ \t]+\$?[^\W\d]\w*[ \t]*\(|(?:(?:unquoted|final)[ \t])*function[ \t]+\$?[^\W\d]\w*[ \t]*\((?![^\n]*\)[ \t]*!?return\b)|definelong[ \t]+[^\W\d]/ ;PP-CLOSER = /[ \t]*!end[ \t]*(?:function|definelong|procedure)\b/ ; (* The one-line directives, after the ! (TLineType and PythonLine in PlantUML). Any other line that starts with ! (`!pragma`, `!!x`, `!{...}`, `! if`, `!define` alone, `!return` outside a function) is handed to UJN, which refuses it. *) pp-line = /[ \t]*[(\[0-9@]/ (* a Python statement or decorator *) | /[ \t]*(?!<<PP-WORD>>)[^\W\d]/ (* a Python statement: !x = 1, !print(...) *) | /define[ \t]+[^\W\d]/ | /(?:ifdef|undef|ifndef|assert|if|else|elseif|endif|while|endwhile|foreach|endfor|theme|includedef|import|startsub|endsub|includesub|log|dump_memory|option)\b/ | /include[ \t]*(?:url|_many|_once)?\b/ | /end[ \t]*(?:function|definelong|procedure)\b/ | /[ \t]*(?:(?:local|global)[ \t]+\$?[^\W\d]\w*|\$[^\W\d]\w*)[ \t]*\??=/ | /[ \t]*[^\W\d]\w*[ \t]*\?=/ | /(?:(?:unquoted|final)[ \t])*function[ \t]+\$?[^\W\d]\w*[ \t]*\((?=[^\n]*\)[ \t]*!?return\b)/ ; (* a function and its !return on one line *) PP-WORD = /(?:python|endpy|define|definelong|enddefinelong|undef|ifdef|ifndef|if|elseif|else|endif|while|endwhile|foreach|endfor|function|procedure|unquoted|final|end|endfunction|endprocedure|return|include|includeurl|include_many|include_once|include_sprites|includedef|includesub|import|startsub|endsub|theme|log|dump_memory|option|assert|local|pragma|assume|exit)(?!\w)/ ; (* ---------------------------------------------------------------- the start and end of a content line *) (* PlantUML removes block comments before UJN reads a line, without looking at quotes: - a line that starts with /' and ends with '/ is a comment (block-comment above); - a line that starts with /' : the comment runs to the first '/ (it may share the ', as in /'/); - a line that ends with '/ : the comment runs from the last /' (TCUT); - a /'''name'''/ comment (letters, digits, _ and -) is removed from the rest of the line. Then UJN removes a comment that starts with a ' after a blank, outside double quotes. (2) *) lead = /[ \t]*/ [ LEAD-COMMENT _ ] ;LEAD-COMMENT = /\/'(?![^\n]*'\/[ \t]*\n)(?:\/|(?!\/)(?:(?!'\/)[^\n])*'\/)/ ; line-end = ( WS "'" COMMENT-TEXT | _ ) [ TAIL-COMMENT ] NL ;quoted-end = _ [ TAIL-COMMENT ] NL ; (* a line that ends inside double quotes: a ' is text there, not a comment *)COMMENT-TEXT = /(?:(?!<<TCUT>>)[^\n])*/ ;TAIL-COMMENT = /(?=<<TCUT>>)[^\n]*/ ; TCUT = /\/'(?:(?!\/')[^\n])*(?<='\/)[ \t]*\n/ ; (* from the last /' of a line that ends with '/ to the line end. No text class below runs into it, so such a line can only end with TAIL-COMMENT. *) (* ---------------------------------------------------------------- the journey line (3) *) journey-line = lead "journey" WS JOURNEY-ID WS STRING line-end ; journey-entry = lead /(?!journey[ \t])/ KEY _ ":" [ _ journey-value ] line-end ; (* one entry per line, and the colon is required. A line that starts with journey and a blank is read as a journey line, so the key is not journey there. *) journey-value = value | raw-line-value ; (* ---------------------------------------------------------------- statements (4, 6, 10.2, 13, 19.1) *) top-statement = lead top-head block-part ; statement = lead ( top-head | node-head | arrow-head ) block-part | lead ( node-head-q | arrow-head-q ) quoted-end [ later-block ] ; (* a header that ends inside double quotes: its block, if any, opens on a later line *) top-head = "increment" | "render" | COLOR-BLOCK ; COLOR-BLOCK = /(?:view|actor|system|action|handoff|data|start|end|ref|arrow)_color(?:_[a-z][a-z0-9-]*)?/ ; (* <kind>_color, <kind>_color_<type>, arrow_color, arrow_color_<arrow kind>; a suffix that is not a type of the kind is a warning *) node-head = KIND WS HANDLE [ _ "[" DISPLAY-ID "]" ] ;node-head-q = KIND WS HANDLE _ "[" DISPLAY-ID BRACKET-QUOTE-TAIL "]" ; KIND = "view" | "actor" | "system" | "action" | "handoff" | "data" | "start" | "end" | "ref" ; arrow-head = HANDLE WS TOKEN WS HANDLE [ _ ":" [ _ label ] ] ;arrow-head-q = HANDLE WS TOKEN WS HANDLE _ ":" _ label-q ; TOKEN = "-->" | "->" | "-x->" | "..>" | ".>" | ".x.>" | "-" DIR "->" | "-" DIR "-x->" | "." DIR ".>" | "." DIR ".x.>" ; (* 6 + 4 x 8 = 38 tokens *) DIR = "right" | "left" | "up" | "down" | "r" | "l" | "u" | "d" ; label = trigger [ _ guard ] | guard ; (* a trigger, a guard, or both (13.4) *) label-q = "[" BRACKET-TEXT BRACKET-QUOTE-TAIL "]" [ _ ( GUARD-STRING-Q | GUARD-TEXT-Q ) ] | [ trigger _ ] GUARD-TEXT GUARD-QUOTE-TAIL ; (* a trigger or a guard with a double quote that is not closed *) trigger = "[" BRACKET-TEXT "]" ; guard = STRING | GUARD-TEXT ; (* quote a guard that holds ; { } or ' *) (* ---------------------------------------------------------------- blocks (4.4) *) (* A statement's block opens with { on its line, or alone at the start of a later line, with only lines to skip between. Entries are key: value, one per line or separated by ;. A key on its own means true. The block closes on a line that ends with } and holds more } than {, outside double quotes; a block that opens and closes on one line holds as many { as }. *) block-part = _ block | line-end [ later-block ] ; later-block = { skip } lead block ; block = "{" _ [ entries _ ] "}" line-end (* on one line *) | "{" [ _ open-entries ] line-end (* over several lines *) { skip | block-line } closing-line ; block-line = lead open-entries line-end ; closing-line = lead [ entries _ ] "}" line-end ; (* Entries are split at each ; outside double quotes and square brackets. A [ or ] without its partner keeps the ; after it in the value (raw-open-bracket). *) entries = [ semis _ ] entry { semis _ entry } [ semis ] | semis (* empty entries are dropped *) | [ semis _ ] { entry semis _ } KEY _ ":" _ [ raw-value ] raw-open-bracket ; (* On a line that leaves the block open, two more things are text: a double quote that is not closed (the rest of the line is then the value), and a brace without its partner, when the line does not end with }. *) open-entries = [ semis _ ] open-entry { semis _ open-entry } [ semis ] | semis | [ semis _ ] { open-entry semis _ } KEY _ ":" _ [ raw-open-value ] ( raw-open-bracket [ raw-quote-tail ] | raw-quote-tail ) | raw-free-entries /(?<!\})/ ; open-entry = KEY [ _ ":" [ _ ( value | raw-open-value ) ] ] ; raw-open-value = { raw-piece } "{" { raw-piece | "{" } | raw-value ; (* a { without its partner never closes a block *) semis = _ ";" { _ ";" } ; entry = KEY [ _ ":" [ _ value ] ] ; (* ---------------------------------------------------------------- values (5) *) value = placeholder | list | bool | duration | number | color | trace-link | handle | text | raw-value ; placeholder = "{{auto}}" ; (* for unique_id only (7) *) list = "[" _ [ item { _ "," _ item } _ ] "]" ; (* one item may go without the brackets: text *)item = STRING | ITEM-TEXT ; bool = /(?i:true|false)/ ; (* any case; a key on its own is true *) number = /[0-9]+/ ; duration = /[0-9]+(?:\.[0-9]+)?[ \t]?(?:ms|s|min|h|d)/ ; color = /#(?:[0-9a-fA-F]{8}|[0-9a-fA-F]{6}|[0-9a-fA-F]{3})/ | /[A-Za-z]+/ ; (* a name: one PlantUML knows, else a warning *) trace-link = /[a-z][a-z0-9-]*:(?:(?!<<TCUT>>)[^ \t\n;,"'{}\[\]])+/ ; (* kind:reference (9.2) *) handle = HANDLE ; (* one declared in the journey *) text = STRING | BARE-TEXT ; (* What the module reads as a value, whatever the key: the rest of the entry. Braces pair up on the line; square brackets pair up, or pair the other way round (] ... [), and a ; inside them is text; a ' after a blank starts a comment. A value outside the forms above is a warning (21), never a syntax error. *) raw-value = raw-piece { raw-piece } ; raw-piece = raw-flat | raw-braces | raw-square | raw-reversed ; raw-flat = /[^ \t\n"'\/;{}\[\]]+/ | SLASH | APOSTROPHE | INNER-BLANKS | STRING ; raw-braces = "{" { raw-flat | raw-braces | raw-square } "}" ; raw-square = "[" { raw-flat | raw-braces | raw-square | ";" } "]" ; raw-reversed = "]" { raw-flat | raw-flat-braces | ";" | raw-reversed } "[" ; raw-flat-braces = "{" { raw-flat | raw-flat-braces } "}" ; raw-open-bracket = raw-open-square | raw-open-reversed ; raw-open-square = "[" { raw-flat | raw-braces | raw-square | ";" } [ raw-open-square ] ; raw-open-reversed = "]" { raw-flat | raw-flat-braces | ";" | raw-reversed } [ raw-open-reversed ] ; raw-quote-tail = /"(?:(?!<<TCUT>>)(?:[^"\\\n]|\\[^\n]))*/ ; (* a double quote that is not closed, and the rest of the line *) (* On a line that leaves the block open and does not end with }, braces are plain text. *) raw-free-entries = [ semis _ ] raw-free-entry { semis _ raw-free-entry } [ semis ] | [ semis _ ] { raw-free-entry semis _ } KEY _ ":" _ [ raw-free-value ] ( raw-free-open-bracket [ raw-quote-tail ] | raw-quote-tail ) ; raw-free-entry = KEY [ _ ":" [ _ raw-free-value ] ] ; raw-free-value = raw-free-piece { raw-free-piece } ; raw-free-piece = raw-free-flat | raw-free-square | raw-free-reversed ; raw-free-flat = raw-flat | "{" | "}" ; raw-free-square = "[" { raw-free-flat | raw-free-square | ";" } "]" ; raw-free-reversed = "]" { raw-free-flat | ";" | raw-free-reversed } "[" ; raw-free-open-bracket = raw-free-open-square | raw-free-open-reversed ; raw-free-open-square = "[" { raw-free-flat | raw-free-square | ";" } [ raw-free-open-square ] ; raw-free-open-reversed = "]" { raw-free-flat | ";" | raw-free-reversed } [ raw-free-open-reversed ] ; (* A journey entry takes the rest of its line: ; braces and brackets are plain characters there. *) raw-line-value = { raw-line-piece } ( raw-line-piece | raw-quote-tail ) ; raw-line-piece = /[^ \t\n"'\/]+/ | SLASH | APOSTROPHE | INNER-BLANKS | STRING ; (* ---------------------------------------------------------------- lexical classes (22) *) HANDLE = /(?!(?:view|actor|system|journey|increment|action|handoff|data|start|end|ref)(?![A-Za-z0-9_]))[A-Za-z][A-Za-z0-9_]*/ ; (* letters, digits and _, starting with a letter; not a keyword (4.2) *) KEY = /[a-z][a-z0-9_]*/ ; JOURNEY-ID = /[A-Za-z0-9][A-Za-z0-9._-]*/ ; STRING = /"(?:(?!<<TCUT>>)(?:[^"\\\n]|\\[^\n]))*"/ ; (* \" is a quote; any other backslash pair is read as in a PlantUML label: \n, \\, \t *) (* Three pieces that every unquoted text below shares, so that a comment is never read as text: *)APOSTROPHE = /(?<![ \t])'+/ ; (* a ' that does not follow a blank *)INNER-BLANKS = /[ \t]+(?![ \t'\n])/ ; (* blanks that more text follows, not a comment *)SLASH = /(?!<<TCUT>>)\// ; (* a / that does not start TCUT *) (* The text of a display id and of a trigger: anything except ] and a line end. A { outside double quotes would open the block, and a ' after a blank starts a comment. A part in double quotes holds no ]. A double quote that is not closed may end the text (BRACKET-QUOTE-TAIL); the line then ends inside quotes. *)BRACKET-TEXT = { /[^\]\n{"'\/ \t]+/ | SLASH | APOSTROPHE | INNER-BLANKS | /"(?:(?!<<TCUT>>)(?:[^"\\\n\]]|\\[^\n\]]))*"/ } ; BRACKET-QUOTE-TAIL = /"(?:(?!<<TCUT>>)(?:[^"\\\]\n]|\\[^\]\n]))*\\?/ ; DISPLAY-ID = BRACKET-TEXT ; (* A guard without quotes around it: no ; { } or ', and it does not start with [ or ". A part in double quotes inside it holds no ; } or ' either. *)GUARD-TEXT = ( /[^ \t\n"'\/;{}\[]/ | SLASH ) { /[^ \t\n"'\/;{}]+/ | SLASH | INNER-BLANKS | /"(?:[^"\\\n;}']|\\[^\n;}'])*"/ } ; GUARD-QUOTE-TAIL = /"(?:(?!\/')(?:[^"\\\n;}']|\\[^\n;}']))*/ ; (* a double quote that is not closed, and the rest of the guard: no ; } or ' *) (* A guard after a trigger whose double quote is not closed: the guard starts inside quotes. *)GUARD-TEXT-Q = /[^\[" \t\n;}'](?:(?!\/')[^"\n;}'])*/ ;GUARD-STRING-Q = /"[^"\\\n{};']*"/ ; (* Text without quotes (5): no ; { } ' or ", and square brackets in pairs. *)BARE-TEXT = ( /[^ \t\n"'\/;{}\[\]]+/ | SLASH | /\[[^\]\n"'{};]*\]/ ) { /[^ \t\n"'\/;{}\[\]]+/ | SLASH | /\[[^\]\n"'{};]*\]/ | INNER-BLANKS } ; (* A list item without quotes: no , [ ] ; { } ' or ". *)ITEM-TEXT = ( /[^ \t\n"'\/;,{}\[\]]+/ | SLASH ) { /[^ \t\n"'\/;,{}\[\]]+/ | SLASH | INNER-BLANKS } ; (* ---------------------------------------------------------------- characters *) _ = { /[ \t]/ | SPECIAL } ; (* blanks, if any *)WS = { SPECIAL } /[ \t]/ _ ; (* one blank or more *)SPECIAL = /(?!<<TCUT>>)\/'''[-A-Za-z0-9_]*'''\// ; (* PlantUML removes it wherever it stands *)NL = /(?<![^\\]\\)\n/ ; (* a line end, but not after one backslash: PlantUML joins such a line to the next before UJN reads it *)EOF = /(?![\s\S])/ ;Where the grammar, the spec and the module differ#
The grammar follows the module wherever the module is not plainly wrong. What remains:
Where the grammar is more exact than section 22
- Preprocessor lines: section 22 allows them only before the journey line. The module and the grammar accept them anywhere, as section 2 says, but only the lines PlantUML's preprocessor recognizes. Any other line that starts with !, such as !pragma, !!x, ! if or !define with no name, reaches UJN and is not a UJN statement.
- Comment lines and blank lines may stand anywhere, including before the journey line and between the journey line and its entries. Section 22 does not show them there.
- A journey entry takes the whole rest of its line: ; and braces are plain text there, each line holds one entry, and the colon is required. A line like journey : x is read as a bad journey line, not as an entry.
- Section 22 requires a block on increment, render and the color blocks. The module and the grammar also accept them without one, as an empty block, with no warning.
- A color block accepts any suffix shaped like a type, both after <kind>_color and after arrow_color. A suffix that is not a known type gives the warning 'unknown type in ...'.
- An arrow needs a blank on each side of its token, so a-->b is a syntax error. Section 22 writes HANDLE TOKEN HANDLE without saying so. There are 38 tokens.
- Section 22 does not define GUARD. In the module and the grammar, a guard is either one closed string, or unquoted text without ; { } or ' that does not start with [ or a double quote. Unquoted text may end with a double quote that is not closed; the line then ends inside quotes, so it can hold no ' comment and no block. The module's message 'Quote a guard that holds { } or an apostrophe' does not mention ;.
- TRIGGER and DISPLAY-ID are 'any text except ]', with two limits: a { outside double quotes opens the block, and a ' after a blank starts a comment. A double quote that is not closed is allowed, but then nothing except blanks may follow the ] on that line; the block may open on the next line. A display id may be empty ([]).
- Blank, comment and preprocessor lines may stand before a block's {. Empty blocks and empty entries are allowed (;;, or a ; that leads or trails), and entries may sit on the same line as { or }. A block closes on a line that ends with } and holds more } than {. A block that opens and closes on one line holds as many { as }.
- Section 2 counts render and the color block names (view_color and so on) as keywords, but the module does not reserve them: view render and view view_color are valid. A handle's letters are ASCII A to Z.
- Block comments, without regard to quotes: on a line that starts with /', the comment runs to the first '/ (/'/ counts). On a line that ends with '/, the comment runs from the last /'. A line that starts with /' and ends with '/ is all comment, and a /'''name'''/ comment is removed wherever it stands. A /' ... '/ anywhere else in a line is plain text, or a syntax error. A ' comment right after a leading /' '/ comment is a preprocessor error.
- The file around the diagram is not covered by section 22. As in PlantUML, a file may hold text outside its diagrams, other PlantUML diagrams, and several UJN diagrams. A diagram that a new @start line interrupts is dropped. The start line is @start or \start in lower case, then ujn in any case (@startUJN), then anything (@startujn(id=x), @startujnx). Any line that starts with @end or \end, in lower case, ends the diagram. A YAML header between two --- lines may follow the start line.
- Line ends may be CR LF, or a CR alone, as PlantUML reads them. A byte order mark at the start of a file is ignored.
- A block comment, a !procedure, !function or !definelong that is never closed, or an !exit line, makes PlantUML drop the rest of the diagram silently. The grammar does the same.
- Section 21 says an unknown arrow token gives a message telling you to write the source first. The module gives that message only for a reversed token (b <-- a). For a ==> b it says 'Not a UJN statement'.
Where the grammar is stricter than section 5
- Section 5 says unquoted text needs quotes only when it holds ;, }, ', a comma inside a list, or blanks at its start or end. The module and the grammar also read {, [, ] and " unquoted, with effects section 5 does not describe. A [ or ] without its partner keeps the ; after it in the same value, so title: Step [1; owner: x is one entry.
- An unquoted double quote that is not closed takes the rest of the line into the value, ; and } included. So view a { title: 5" screen } leaves the block open, and a later } closes it. On a line of its own inside a block, title: 5" screen reads as section 5 means.
- A { without its partner is plain text on a line that leaves a block open. A } inside a value, which section 5 says needs quotes, gives only a warning, and the grammar reads it on a line that leaves the block open and does not end with }.
- A duration may have a decimal number (1.5 h), as the module accepts. Section 5 says 'a number and a unit', and section 5 numbers are digits only.
- A list must close on the line where it starts. A value outside the section 5 forms is a warning, never a syntax error; ujn_grammar.py --strict accepts only the section 5 forms.
What the module reads and the grammar refuses
- A guard that starts with a double quote but is not one closed string, such as "x" or "y, "x" ; y, "x" } or "abc. The module checks only the first character and gives no warning; this is a module bug.
- A guard that starts with [ and has no ] (: [Save), or a guard that starts with [ after a trigger (: [Save] [draft]). The module reads these as guards, which hides a missing ] or an extra trigger.
- After a trigger whose double quote is not closed, a guard that holds a double quote, unless the guard is one closed string, as in [say "hi] ok "x.
- A line that ends with one backslash. PlantUML joins it to the next line before UJN reads it, and a comment line that ends this way swallows the next line. The grammar refuses such a line instead of following the join.
- Braces that do not pair, on a line that ends with }. This covers a line that closes a block (title: a } b }), a one-line block with text after it (view a { title: x }{{auto}}), and a line that opens a block (view a { title: a } b }). The module counts the braces and reads these, in surprising ways.
- A value where a brace pair holds a square bracket that does not pair, as in title: {[}.
- Lines that the preprocessor writes. The grammar skips preprocessor lines without running them and reads every other line as written. So it does not see statements written by a macro, a procedure call, an !foreach loop or a !{...} line, and it reads the branch of an !if that is not taken.
- A /'''name'''/ comment inside a word, as in vi/'''x'''/ew a. PlantUML removes it anywhere, while the grammar removes it only between tokens.
What the grammar accepts and the module refuses
- Two nodes with the same handle, display id, unique id or friendly id, and an arrow to a handle that no statement declares. Checking these needs more than a grammar.
- Preprocessor lines that fail when PlantUML runs them. Examples are an !if without !endif, or an !endif, !else or !endwhile alone; a failed !assert; an !include or !theme that cannot be found; a Python error; a function without !return. The grammar only checks that such a line is a preprocessor line.
- A digit string too long for the module, as in increment { auto; view_start: 99999999999 } or a display id VIEW-99999999999. The module crashes; this is a module bug.
- A block comment or preprocessor block that is never closed when only the journey line comes before it. The module crashes; this is a module bug. With any other line before it, the module drops the rest of the diagram, as the grammar does.
Out of scope
- Control characters other than tab, line feed and carriage return, the Unicode line separators U+0085, U+2028 and U+2029, and U+E103 are out of scope, and the grammar refuses any file that holds one. The module reads a vertical tab or form feed as a blank, drops control characters at the ends of a line, and breaks some lines at U+0085, U+2028 and U+2029.
- PlantUML's @pause, @unpause and @append lines, which drop lines from a diagram or add lines to it.
- A line where @start follows only punctuation, such as ' @startujn or # @startujn. PlantUML starts a diagram there and removes that punctuation from the lines after it, so a comment line ' @startuml inside a UJN diagram starts a new diagram.
- Inside block comments, inside preprocessor blocks, and in text outside a diagram, the grammar follows a line that ends with one backslash only in the simple cases noted at each rule.