PML Syntax EBNF

The following table specifies PML's syntax, expressed in Extended Backus–Naur form (EBNF).

Nodes

NameRuleExamples
node =   empty_node
| non_empty_node
empty_node = "[" name "]" [nl]
non_empty_node = "[" name separator attributes ? child_node * "]"

Note: The separator is optional if the name is immediately followed by [ or (.
[i huge]
[image(source=strawberries.jpg)]
[image (
    source = strawberries.jpg
) ]
[div A [i[b nice]] dog]
separator = whitespace_char
child_node =   node
| node_text
| comment
[i huge]
All is well!
[- comment -]
node_text = node_text_char + Bob
3.14
We want simplicity.
root\\config\["port"\]
node_text_char =   any Unicode character,
  except "[", "]", and "\"
| escaped_char
| "\("
a
é
\[
\(

Attributes

NameRuleExamples
attributes = "(" commented_attribute * ")" (height=200)
(
    title = "A planet"
    [- size in mm -]
    width = 400
    height = 248
)
()
commented_attribute = ( whitespace | comment ) * attribute ( whitespace | comment ) * [- degrees celsius -]
temperature = 30
attribute = name whitespace ? "=" whitespace ? attribute_value color=orange
title = "More Benefits"
attribute_value =   quoted_value
| unquoted_value
"yes"
yes
quoted_value = '"' quoted_value_char * '"' "yellow"
"light yellow"
"/root/foo/bar"
"C:\\config.txt"
"list[3]"
"list\[3\]"
"He said\n\"That's ok\""
"Tim
Tom
Tam"
""
quoted_value_char =   any Unicode character,
  except "
| '\"'
| escaped_char
a
é
\"
\n
unquoted_value = unquoted_value_char + yellow
/root/foo/bar
C:\config.txt
unquoted_value_char = Any Unicode character,
except whitespace_char, [, ], (, ), ", '
Remak: Escape characters are not allowed.
a
/
\

Common Elements

NameRuleExamples
name = name_start_char name_char *

Regex: [a-zA-Z_][a-zA-Z0-9_\.-]*
height
border-color
_default
name_start_char =   "a" .. "z"
| "A" .. "Z"
| "_"
a
Z
_
name_char =   "a" .. "z"
| "A" .. "Z"
| "0" .. "9"
| "_"
| "-"
| "."
a
Z
9
_
-
.
comment = "[-" ( node_text | comment ) * "-]" [- TODO: improve text -]
[- comment [- nested comment -] -]
whitespace = whitespace_char +
whitespace_char =   " "
| \t
| \n
| \r\n
escaped_char =   "\\"
| "\["
| "\]"
| "\t"
| "\r"
| "\n"
| Unicode_escape_sequence
\\        (\)
\[        ([)
\]        (])
\t        (tab)
\r        (carriage return)
\n        (line feed)
\u002A    (*)
Unicode_escape_sequence = "\u" hex_char hex_char hex_char hex_char \u002A    (*)
hex_char =   "0" .. "9"
| "a" .. "f"
| "A" .. "F"
1
a
F