Skip to content

Commit 4784fb9

Browse files
authored
Beautify the ABNF (#613)
* Beautify the ABNF As we lock down the ABNF, start to fix spacing and alignment. In this PR all of the changes are editorial. Note that I have moved a few of the productions in an attempt to organize items more logically. I have also added comments for individual blocks. * A few more block alignments * Fix markup note * ... and a final tidy... * Minor reordering per comment
1 parent d06033b commit 4784fb9

File tree

1 file changed

+49
-40
lines changed

1 file changed

+49
-40
lines changed

spec/message.abnf

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,78 @@
1-
message = simple-message / complex-message
1+
message = simple-message / complex-message
22

3-
simple-message = [simple-start pattern]
4-
simple-start = simple-start-char / text-escape / placeholder
5-
pattern = *(text-char / text-escape / placeholder)
6-
placeholder = expression / markup
3+
simple-message = [simple-start pattern]
4+
simple-start = simple-start-char / text-escape / placeholder
5+
pattern = *(text-char / text-escape / placeholder)
6+
placeholder = expression / markup
7+
8+
complex-message = *(declaration [s]) complex-body
9+
declaration = input-declaration / local-declaration / reserved-statement
10+
complex-body = quoted-pattern / matcher
711

8-
complex-message = *(declaration [s]) complex-body
9-
declaration = input-declaration / local-declaration / reserved-statement
1012
input-declaration = input [s] variable-expression
1113
local-declaration = local s variable [s] "=" [s] expression
1214

13-
complex-body = quoted-pattern / matcher
14-
quoted-pattern = "{{" pattern "}}"
15+
quoted-pattern = "{{" pattern "}}"
1516

16-
matcher = match-statement 1*([s] variant)
17-
match-statement = match 1*([s] selector)
18-
selector = expression
19-
variant = key *(s key) [s] quoted-pattern
20-
key = literal / "*"
17+
matcher = match-statement 1*([s] variant)
18+
match-statement = match 1*([s] selector)
19+
selector = expression
20+
variant = key *(s key) [s] quoted-pattern
21+
key = literal / "*"
2122

22-
expression = literal-expression
23-
/ variable-expression
24-
/ annotation-expression
25-
literal-expression = "{" [s] literal [s annotation] *(s attribute) [s] "}"
26-
variable-expression = "{" [s] variable [s annotation] *(s attribute) [s] "}"
23+
; Expressions
24+
expression = literal-expression
25+
/ variable-expression
26+
/ annotation-expression
27+
literal-expression = "{" [s] literal [s annotation] *(s attribute) [s] "}"
28+
variable-expression = "{" [s] variable [s annotation] *(s attribute) [s] "}"
2729
annotation-expression = "{" [s] annotation *(s attribute) [s] "}"
28-
annotation = function
29-
/ private-use-annotation
30-
/ reserved-annotation
3130

31+
annotation = function
32+
/ private-use-annotation
33+
/ reserved-annotation
34+
35+
; Markup; Note that standalone markup is part of the first line
3236
markup = "{" [s] markup-open *(s attribute) [s] ["/"] "}"
3337
/ "{" [s] markup-close *(s attribute) [s] "}"
3438
markup-open = "#" identifier *(s option)
3539
markup-close = "/" identifier
3640

37-
literal = quoted / unquoted
38-
quoted = "|" *(quoted-char / quoted-escape) "|"
39-
unquoted = name / number-literal
40-
variable = "$" name
41-
function = ":" identifier *(s option)
42-
option = identifier [s] "=" [s] (literal / variable)
43-
attribute = "@" identifier [[s] "=" [s] (literal / variable)]
41+
; Expression and literal parts
42+
function = ":" identifier *(s option)
43+
option = identifier [s] "=" [s] (literal / variable)
44+
; Attributes are reserved for future standardization
45+
attribute = "@" identifier [[s] "=" [s] (literal / variable)]
46+
47+
variable = "$" name
48+
literal = quoted / unquoted
49+
quoted = "|" *(quoted-char / quoted-escape) "|"
50+
unquoted = name / number-literal
51+
; number-literal matches JSON number (https://www.rfc-editor.org/rfc/rfc8259#section-6)
52+
number-literal = ["-"] (0 / ([1-9] *DIGIT)) ["." 1*DIGIT] [%i"e" ["-" / "+"] 1*DIGIT]
4453

54+
; Keywords; Note that these are case-sensitive
4555
input = %s".input"
4656
local = %s".local"
4757
match = %s".match"
4858

4959
; Reserve additional .keywords for use by future versions of this specification.
5060
reserved-statement = reserved-keyword [s reserved-body] 1*([s] expression)
51-
; Note that the following expression is a simplification,
61+
; Note that the following production is a simplification,
5262
; as this rule MUST NOT be considered to match existing keywords
5363
; (`.input`, `.local`, and `.match`).
54-
reserved-keyword = "." name
64+
reserved-keyword = "." name
5565

5666
; Reserve additional sigils for use by future versions of this specification.
57-
reserved-annotation = reserved-annotation-start reserved-body
67+
reserved-annotation = reserved-annotation-start reserved-body
5868
reserved-annotation-start = "!" / "%" / "*" / "+" / "<" / ">" / "?" / "~"
5969

60-
reserved-body = *([s] 1*(reserved-char / reserved-escape / quoted))
61-
6270
; Reserve sigils for private-use by implementations.
63-
private-use-annotation = private-start reserved-body
64-
private-start = "^" / "&"
65-
66-
; number-literal matches JSON number
67-
; https://www.rfc-editor.org/rfc/rfc8259#section-6
68-
number-literal = ["-"] (0 / ([1-9] *DIGIT)) ["." 1*DIGIT] [%i"e" ["-" / "+"] 1*DIGIT]
71+
private-use-annotation = private-start reserved-body
72+
private-start = "^" / "&"
73+
reserved-body = *([s] 1*(reserved-char / reserved-escape / quoted))
6974

75+
; Names and identifiers
7076
; identifier matches https://www.w3.org/TR/REC-xml-names/#NT-QName
7177
; name matches https://www.w3.org/TR/REC-xml-names/#NT-NCName
7278
identifier = [namespace ":"] name
@@ -80,6 +86,7 @@ name-start = ALPHA / "_"
8086
name-char = name-start / DIGIT / "-" / "."
8187
/ %xB7 / %x300-36F / %x203F-2040
8288

89+
; Restrictions on characters in various contexts
8390
simple-start-char = content-char / s / "@" / "|"
8491
text-char = content-char / s / "." / "@" / "|"
8592
quoted-char = content-char / s / "." / "@" / "{" / "}"
@@ -94,9 +101,11 @@ content-char = %x00-08 ; omit HTAB (%x09) and LF (%x0A)
94101
/ %x7E-D7FF ; omit surrogates
95102
/ %xE000-10FFFF
96103

104+
; Character escapes
97105
text-escape = backslash ( backslash / "{" / "}" )
98106
quoted-escape = backslash ( backslash / "|" )
99107
reserved-escape = backslash ( backslash / "{" / "|" / "}" )
100108
backslash = %x5C ; U+005C REVERSE SOLIDUS "\"
101109

110+
; Whitespace
102111
s = 1*( SP / HTAB / CR / LF / %x3000 )

0 commit comments

Comments
 (0)