Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 20653d7

Browse files
eemeliaphillips
andauthored
Allow whitespace at complex-message start (#854)
* Allow whitespace at complex-message start * Apply suggestions from code review Co-authored-by: Addison Phillips <[email protected]> * Remove whitespace from simple-start-char --------- Co-authored-by: Addison Phillips <[email protected]>
1 parent bb8e8c2 commit 20653d7

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

spec/message.abnf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
message = simple-message / complex-message
22

3-
simple-message = [simple-start pattern]
3+
simple-message = [s] [simple-start pattern]
44
simple-start = simple-start-char / escaped-char / placeholder
55
pattern = *(text-char / escaped-char / placeholder)
66
placeholder = expression / markup
77

8-
complex-message = *(declaration [s]) complex-body [s]
8+
complex-message = [s] *(declaration [s]) complex-body [s]
99
declaration = input-declaration / local-declaration / reserved-statement
1010
complex-body = quoted-pattern / matcher
1111

@@ -86,7 +86,7 @@ name-char = name-start / DIGIT / "-" / "."
8686
/ %xB7 / %x300-36F / %x203F-2040
8787

8888
; Restrictions on characters in various contexts
89-
simple-start-char = content-char / s / "@" / "|"
89+
simple-start-char = content-char / "@" / "|"
9090
text-char = content-char / s / "." / "@" / "|"
9191
quoted-char = content-char / s / "." / "@" / "{" / "}"
9292
reserved-char = content-char / "."

spec/syntax.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,14 @@ message = simple-message / complex-message
153153
```
154154
155155
A **_<dfn>simple message</dfn>_** contains a single _pattern_,
156-
with restrictions on its first character.
156+
with restrictions on its first non-whitespace character.
157157
An empty string is a valid _simple message_.
158158

159+
Whitespace at the start or end of a _simple message_ is significant,
160+
and a part of the _text_ of the _message_.
161+
159162
```abnf
160-
simple-message = [simple-start pattern]
163+
simple-message = [s] [simple-start pattern]
161164
simple-start = simple-start-char / escaped-char / placeholder
162165
```
163166

@@ -169,8 +172,11 @@ and consists of:
169172
1. an optional list of _declarations_, followed by
170173
2. a _complex body_
171174

175+
Whitespace at the start or end of a _complex message_ is not significant,
176+
and does not affect the processing of the _message_.
177+
172178
```abnf
173-
complex-message = *(declaration [s]) complex-body [s]
179+
complex-message = [s] *(declaration [s]) complex-body [s]
174180
```
175181

176182
### Declarations
@@ -300,16 +306,16 @@ U+007B LEFT CURLY BRACKET `{`, and U+007D RIGHT CURLY BRACKET `}`
300306
MUST be escaped as `\\`, `\{`, and `\}` respectively.
301307
302308
In the ABNF, _text_ is represented by non-empty sequences of
303-
`simple-start-char`, `text-char`, and `escaped-char`.
304-
The first of these is used at the start of a _simple message_,
309+
`simple-start-char`, `text-char`, `escaped-char`, and `s`.
310+
The production `simple-start-char` represents the first non-whitespace in a _simple message_
305311
and matches `text-char` except for not allowing U+002E FULL STOP `.`.
306312
The ABNF uses `content-char` as a shared base for _text_ and _quoted literal_ characters.
307313
308314
Whitespace in _text_, including tabs, spaces, and newlines is significant and MUST
309315
be preserved during formatting.
310316
311317
```abnf
312-
simple-start-char = content-char / s / "@" / "|"
318+
simple-start-char = content-char / "@" / "|"
313319
text-char = content-char / s / "." / "@" / "|"
314320
quoted-char = content-char / s / "." / "@" / "{" / "}"
315321
reserved-char = content-char / "."

test/tests/syntax.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
"src": "hello {|world|}",
3737
"exp": "hello world"
3838
},
39+
{
40+
"description": "message -> simple-message -> s simple-start pattern -> s simple-start-char pattern -> ...",
41+
"src": "\n hello\t",
42+
"exp": "\n hello\t"
43+
},
3944
{
4045
"src": "hello {$place}",
4146
"params": [
@@ -134,6 +139,11 @@
134139
"src": ".input{$x}{{}}",
135140
"exp": ""
136141
},
142+
{
143+
"description": "message -> complex-message -> s *(declaration [s]) complex-body s -> s declaration complex-body s -> s input-declaration complex-body s -> s input variable-expression complex-body s",
144+
"src": "\t.input{$x}{{}}\n",
145+
"exp": ""
146+
},
137147
{
138148
"description": "message -> complex-message -> *(declaration [s]) complex-body -> declaration declaration complex-body -> input-declaration input-declaration complex-body -> input variable-expression input variable-expression complex-body",
139149
"src": ".input{$x}.input{$y}{{}}",
@@ -145,8 +155,8 @@
145155
"exp": ""
146156
},
147157
{
148-
"description": "message -> complex-message -> *(declaration [s]) complex-body s -> complex-body s",
149-
"src": "{{}} ",
158+
"description": "message -> complex-message -> s *(declaration [s]) complex-body s -> s complex-body s",
159+
"src": " {{}} ",
150160
"exp": ""
151161
},
152162
{
@@ -398,8 +408,7 @@
398408
"source": "|42|",
399409
"value": "42"
400410
}
401-
],
402-
"exp": "42"
411+
]
403412
},
404413
{
405414
"description": "... literal -> quoted-literal -> \"|\" \"|\" ...",

0 commit comments

Comments
 (0)