Formal syntax

Every tourniquet program is also a valid string of UTF-8.

With that said, the following is the formal syntax for a tourniquet program (called source_file in the EBNF specification below), using W3C-style EBNF notation:

source_file ::= wsc (definition wsc)*

definition ::= identifier wsc ":=" sequence ";"

sequence ::= wsc (sequence_element wsc)*

sequence_element ::= identifier | "(" sequence ")"

identifier ::= identifier_char+ - ":=" - "/*" - "*/"

identifier_char ::= [^;()] - SEPARATOR_OR_OTHER


/* ===== Whitespace & comments ===== */

wsc ::= (whitespace | comment)*

whitespace ::= UNICODE_SEPARATOR+

comment ::= "/*" (ANY - "*/")* "*/"


/* ===== Unicode stuff ===== */

ANY ::= [#x0000-#x10fffd]

SEPARATOR_OR_OTHER ::= UNICODE_SEPARATOR | UNICODE_OTHER

UNICODE_SEPARATOR ::= #x0020 | #x00a0 | #x1680 | #x2000 | #x2001 | #x2002
                    | #x2003 | #x2004 | #x2005 | #x2006 | #x2007 | #x2008
                    | #x2009 | #x200a | #x2028 | #x2029 | #x202f | #x205f
                    | #x3000

UNICODE_OTHER ::=  #x0000 |   #x0001 |   #x0002 |  #x0003 |  #x0004 |  #x0005 | #x0006
                |  #x0007 |   #x0008 |   #x0009 |  #x000a |  #x000b |  #x000c | #x000d
                |  #x000e |   #x000f |   #x0010 |  #x0011 |  #x0012 |  #x0013 | #x0014
                |  #x0015 |   #x0016 |   #x0017 |  #x0018 |  #x0019 |  #x001a | #x001b
                |  #x001c |   #x001d |   #x001e |  #x001f |  #x007f |  #x0080 | #x0081
                |  #x0082 |   #x0083 |   #x0084 |  #x0085 |  #x0086 |  #x0087 | #x0088
                |  #x0089 |   #x008a |   #x008b |  #x008c |  #x008d |  #x008e | #x008f
                |  #x0090 |   #x0091 |   #x0092 |  #x0093 |  #x0094 |  #x0095 | #x0096
                |  #x0097 |   #x0098 |   #x0099 |  #x009a |  #x009b |  #x009c | #x009d
                |  #x009e |   #x009f |   #x00ad |  #x0600 |  #x0601 |  #x0602 | #x0603
                |  #x0604 |   #x0605 |   #x061c |  #x06dd |  #x070f |  #x0890 | #x0891
                |  #x08e2 |   #x180e |   #x200b |  #x200c |  #x200d |  #x200e | #x200f
                |  #x202a |   #x202b |   #x202c |  #x202d |  #x202e |  #x2060 | #x2061
                |  #x2062 |   #x2063 |   #x2064 |  #x2066 |  #x2067 |  #x2068 | #x2069
                |  #x206a |   #x206b |   #x206c |  #x206d |  #x206e |  #x206f | #xe000
                |  #xf8ff |   #xfeff |   #xfff9 |  #xfffa |  #xfffb | #x110bd
                | #x110cd |  #x13430 |  #x13431 | #x13432 | #x13433 | #x13434
                | #x13435 |  #x13436 |  #x13437 | #x13438 | #x1bca0 | #x1bca1
                | #x1bca2 |  #x1bca3 |  #x1d173 | #x1d174 | #x1d175 | #x1d176
                | #x1d177 |  #x1d178 |  #x1d179 | #x1d17a | #xe0001 | #xe0020
                | #xe0021 |  #xe0022 |  #xe0023 | #xe0024 | #xe0025 | #xe0026
                | #xe0027 |  #xe0028 |  #xe0029 | #xe002a | #xe002b | #xe002c
                | #xe002d |  #xe002e |  #xe002f | #xe0030 | #xe0031 | #xe0032
                | #xe0033 |  #xe0034 |  #xe0035 | #xe0036 | #xe0037 | #xe0038
                | #xe0039 |  #xe003a |  #xe003b | #xe003c | #xe003d | #xe003e
                | #xe003f |  #xe0040 |  #xe0041 | #xe0042 | #xe0043 | #xe0044
                | #xe0045 |  #xe0046 |  #xe0047 | #xe0048 | #xe0049 | #xe004a
                | #xe004b |  #xe004c |  #xe004d | #xe004e | #xe004f | #xe0050
                | #xe0051 |  #xe0052 |  #xe0053 | #xe0054 | #xe0055 | #xe0056
                | #xe0057 |  #xe0058 |  #xe0059 | #xe005a | #xe005b | #xe005c
                | #xe005d |  #xe005e |  #xe005f | #xe0060 | #xe0061 | #xe0062
                | #xe0063 |  #xe0064 |  #xe0065 | #xe0066 | #xe0067 | #xe0068
                | #xe0069 |  #xe006a |  #xe006b | #xe006c | #xe006d | #xe006e
                | #xe006f |  #xe0070 |  #xe0071 | #xe0072 | #xe0073 | #xe0074
                | #xe0075 |  #xe0076 |  #xe0077 | #xe0078 | #xe0079 | #xe007a
                | #xe007b |  #xe007c |  #xe007d | #xe007e | #xe007f | #xf0000
                | #xffffd | #x100000 | #x10fffd