You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: text/3503-frontmatter.md
+91-25Lines changed: 91 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -187,40 +187,93 @@ Downsides:
187
187
- Familiar syntax in an unfamiliar use may make users feel unsettled, unsure how to proceed (what works and what doesn't).
188
188
- If viewed from the lens of a comment, it isn't a variant of comment syntax like doc-comments
189
189
190
-
### Alternative 1: Static-site generator frontmatter
190
+
### Alternative 1: Vary the opening/closing character
191
191
192
-
Note: this alternative was kept close to its source of inspiration, maintaining
193
-
no infostring, despite being subject to the same questions that would be
194
-
present for fenced code blocks, see [Future possibilities](#future-possibilities).
192
+
Instead of backticks, we could do another character, like
193
+
-`-`, making it look like YAML presentation streams, following the pattern of static site generators
194
+
-`+` like [zola's frontmatter](https://www.getzola.org/documentation/getting-started/overview/#markdown-content)
195
+
-`~`, using a lesser known markdown character
196
+
-`=`
197
+
- Open with `>>>` and close with `<<<`, like with HEREDOC (or invert it)
195
198
199
+
In practice:
196
200
```rust
197
201
#!/usr/bin/envcargo
198
-
---
202
+
---cargo
199
203
[package]
200
204
edition="2018"
201
205
---
202
206
203
207
fnmain() {
204
208
}
205
209
```
206
-
This is a subset/specialization of YAML presentation streams that mirrors people's experience with static site generators:
207
-
- The first line post-shebang-stripping is 3+ dashes, then capture all content until a matching pair of dashes on a dedicated line. This would be captured into a `#![frontmatter = ""]`. `frontmatter` attribute is reserved for crate roots. The 3+ with matching pair is a "just in case" a TOML multi-line string has that syntax in it)
208
-
- Future evolution: Allow a markdown-like infostring on the frontmatter opening dashes to declare the format with `cargo` being the default
209
-
- Future evolution: Allow `frontmatter` attribute on any module
210
+
```rust
211
+
#!/usr/bin/envcargo
212
+
+++cargo
213
+
[package]
214
+
edition="2018"
215
+
+++
216
+
217
+
fnmain() {
218
+
}
219
+
```
220
+
```rust
221
+
#!/usr/bin/envcargo
222
+
~~~cargo
223
+
[package]
224
+
edition="2018"
225
+
~~~
226
+
227
+
fnmain() {
228
+
}
229
+
```
230
+
```rust
231
+
#!/usr/bin/envcargo
232
+
===cargo
233
+
[package]
234
+
edition="2018"
235
+
===
236
+
237
+
fnmain() {
238
+
}
239
+
```
240
+
```rust
241
+
#!/usr/bin/envcargo
242
+
>>>cargo
243
+
[package]
244
+
edition="2018"
245
+
<<<
246
+
247
+
fnmain() {
248
+
}
249
+
```
250
+
```rust
251
+
#!/usr/bin/envcargo
252
+
<<<cargo
253
+
[package]
254
+
edition="2018"
255
+
>>>
256
+
257
+
fnmain() {
258
+
}
259
+
```
210
260
211
261
Benefits
212
-
- Visually/syntactically lightweight
213
-
- Has parallels to ideas outside of Rust, building on external knowledge that might exist
214
-
- Easy for cargo to parse and modify
215
-
- Can easily be leveraged by buck2, meson, etc in the future
216
-
- Users can edit/copy/paste the manifest without dealing with leading characters
262
+
- With `-`, it builds on people's familiarity with static site generators
263
+
- People can insert cargo-scripts into markdown (like chat, github issues)
264
+
without being familiar enough with markdown to know how to escape backticks
265
+
and to actually remember how to do it
217
266
218
267
Downsides
219
-
- Too general that people might abuse it
220
-
- We've extended the frontmatter syntax, undoing some of the "familiarity" benefit
221
-
- People are used to YAML going in frontmatter (though some systems allow other syntaxes)
268
+
- With `-`
269
+
- We've extended the frontmatter syntax with an infostring, undoing some of the "familiarity" benefit
270
+
- Potential congantive disonance as those familiar with frontmatter are used to YAML being there
271
+
- With `>>>` it isn't quite like HEREDOC to have less overhead
222
272
- Doesn't feel very rust-like
223
273
274
+
Note:
275
+
-`"` was not considered because that can feel too familiar and users might carry over their expectations for how strings work
276
+
224
277
### Alternative 2: Extended Shebang
225
278
226
279
````rust
@@ -241,6 +294,15 @@ The hope would be that we could get buy-in from other languages.
241
294
- Future evolution: Allow any `info` string with cargo checking for `content.starts_with(["cargo", "cargo,"])`
242
295
- Future evolution: Allow `frontmatter` attribute on any module
243
296
297
+
If we dropped future possibilities for additional content, we could remove the opening/closing syntax and tweak it to avoid attribute ambiguity,
298
+
greatly reducing the minimum syntax needed in some cases.
299
+
````rust
300
+
#!/usr/bin/envcargo
301
+
## package.edition ="2018"
302
+
303
+
fnmain() {}
304
+
````
305
+
244
306
Benefits
245
307
- Visually connected to the shebang
246
308
- Has parallels to ideas outside of Rust, building on external knowledge that might exist
@@ -277,13 +339,14 @@ Benefits
277
339
- Depending on doc-comment style used, users may be able to edit/copy/paste the manifest without dealing with leading characters
278
340
279
341
Downsides:
342
+
-**Blocker** Either we expose `syn`s lesser parse errors or we skip errors, deferring to rustc's, but then have the wrong behavior on commands that don't invoke rustc, like `cargo metadata`
343
+
- If we extend additional restrictions to make it more tool friendly, then we break from user expectations for how this syntax works
280
344
- When discussing with a Rust crash course teacher, it was felt their students would have a hard time learning to write these manifests from scratch
281
345
- Having the explain the overloading of concepts to new users
282
346
- Unpredictable location (both the doc comment and the cargo code block within it)
283
347
- Visual clutter (where clutter is overwhelming already in Rust)
284
348
- Might be a bit complicated to do edits (translating between location within
285
349
`toml_edit` spans to the location within `syn` spans especially with different comment styles)
286
-
- Either we expose `syn`s lesser parse errors or we skip errors, deferring to rustc's, but then have the wrong behavior on commands that don't invoke rustc, like `cargo metadata`
287
350
- Requires pulling in a full markdown parser to extract the manifest
288
351
- Incorrectly formatted markdown would lead to a missing manifest and confusing error messages at best or silent incorrect behavior at worse
289
352
@@ -311,12 +374,13 @@ Benefits
311
374
- Users can edit/copy/paste the manifest without dealing with leading characters
312
375
313
376
Downsides
377
+
-**Blocker** Either we expose `syn`s lesser parse errors or we skip errors, deferring to rustc's, but then have the wrong behavior on commands that don't invoke rustc, like `cargo metadata`
378
+
- If we extend additional restrictions to make it more tool friendly, then we break from user expectations for how this syntax works
314
379
- When discussing with a Rust crash course teacher, it was felt their students would have a hard time learning to write these manifests from scratch
315
380
- Unpredictable location (both the doc comment and the cargo code block within it)
316
381
- From talking to a teacher, users are more forgiving of not understanding the details for structure data in an unstructured format (doc comments / comments) but something that looks meaningful, they will want to understand it all requiring dealing with all of the concepts
317
382
- The attribute approach requires explaining multiple "advanced" topics: One teacher doesn't get to teaching any attributes until the second level in his crash course series and two teachers have found it difficult to teach people raw strings
318
383
- Attributes look "scary" (and they are in some respects for the hidden stuff they do)
319
-
- Either we expose `syn`s lesser parse errors or we skip errors, deferring to rustc's, but then have the wrong behavior on commands that don't invoke rustc, like `cargo metadata`
320
384
321
385
### Alternative 5: Regular Comment
322
386
@@ -356,17 +420,18 @@ Benefits
356
420
- Depending on the exact syntax decided on, users may be able to edit/copy/paste the manifest without dealing with leading characters
357
421
358
422
Downsides
423
+
-**Blocker** Assuming it can't be parsed with `syn` and either we need to write a
424
+
sufficiently compatible comment parser or pull in a much larger rust parser
425
+
to extract and update comments.
426
+
- If we extend additional restrictions to make it more tool friendly, then we break from user expectations for how this syntax works
427
+
- Like with doc comments, this should map to an attribute and then we'd just start the MVP with that attribute
359
428
- Unfamiliar syntax
360
429
- When discussing with a Rust crash course teacher, it was felt their students would have a hard time learning to write these manifests from scratch
361
430
- Having the explain the overloading of concepts to new users
362
431
- Unpredictable location (both the doc comment and the cargo code block within it)
363
432
- Visual clutter (where clutter is overwhelming already in Rust)
364
433
- New style of structured comment for the ecosystem to support with potential
365
434
compatibility issues, likely requiring a new edition
366
-
- Assuming it can't be parsed with `syn` and either we need to write a
367
-
sufficiently compatible comment parser or pull in a much larger rust parser
368
-
to extract and update comments.
369
-
- Like with doc comments, this should map to an attribute and then we'd just start the MVP with that attribute
370
435
371
436
### Alternative 6: Macro
372
437
@@ -386,13 +451,14 @@ Benefits
386
451
- Users can edit/copy/paste the manifest without dealing with leading characters
387
452
388
453
Downsides
454
+
-**Blocker** Either we expose `syn`s lesser parse errors or we skip errors, deferring to rustc's, but then have the wrong behavior on commands that don't invoke rustc, like `cargo metadata`
455
+
- If we extend additional restrictions to make it more tool friendly, then we break from user expectations for how this syntax works
389
456
- When discussing with a Rust crash course teacher, it was felt their students would have a hard time learning to write these manifests from scratch
390
457
- Unpredictable location (both the doc comment and the cargo code block within it)
391
458
- The `cargo` macro would need to come from somewhere (`std`?) which means it is taking on `cargo`-specific knowledge
392
459
- An unexplored direction we could go with this is a `meta!` macro (e.g. we'd need to have a format marker in it)
393
460
- A lot of tools/IDEs have problems in dealing with macros
394
461
- Free-form rust code makes it harder for cargo to make edits to the manifest
395
-
- Either we expose `syn`s lesser parse errors or we skip errors, deferring to rustc's, but then have the wrong behavior on commands that don't invoke rustc, like `cargo metadata`
396
462
397
463
### Alternative 7: Presentation Streams
398
464
@@ -417,7 +483,7 @@ Benefits
417
483
- Users can edit/copy/paste the manifest without dealing with leading characters
418
484
419
485
Downsides
420
-
- Difficult to parse without assistance from something like `syn` as we'd need to distinguish what the start of a stream is vs content of a string literal
486
+
-**Blocker**Difficult to parse without assistance from something like `syn` as we'd need to distinguish what the start of a stream is vs content of a string literal
421
487
- Being a new file format (a "text tar" format), there would be a lot of details to work out, including
422
488
- How to delineate and label documents
423
489
- How to allow escaping to avoid conflicts with content in a documents
0 commit comments