YS Comment Syntax
What is the syntax for comments in YS?
Well that's simple.
YS code is YAML, so the comment syntax is the same as YAML.
Well, there's a little bit more to it than that.
YAML Comments🔗
Yes. YAML comments are valid in YS code.
There's no way they couldn't be. (Not without breaking the laws of YAML Physics!)
Comments in YAML start with #
and continue to the end of the line.
Clojure comments use ;
to the end of the line.
For a while, YS also supported ;
as a comment character.
Only in code mode, of course.
YAML and Multi-line Scalars🔗
One: thing I don't see enough of in people's YAML is splitting long strings into multiple lines.
In YAML, with plain, folded and quoted scalars, you can split a line anywhere you want.
One: thing I don't see enough
of in people's YAML is
splitting long strings
into multiple lines.
You can even start the scalar on a new line.
One:
thing I don't see enough of in people's YAML is
splitting long strings into multiple lines.
But one thing you can't do is put comments in the middle of a multi-line scalar.
say:
One thing I rarely see enough of in YAML files # LINE 1
is splitting long strings into multiple lines.
That's an error.
You actually don't need to put comments in multi-line scalars much in YAML...
But in YS the need comes up more often.
$ ys -e 'say:
read-line() # Read line from stdin
.words() # Split into words
.reverse() # Reverse the words
.joins() # Join the words with a space'
Compile error: while parsing a block mapping
in reader, line 2, column 1:
say:
^
expected <block end>, but found '<scalar>'
in reader, line 4, column 5:
.words() # Split into words
^
Those comments would be nice, but they're not valid YAML.
Luckily YS has a solution for this. It has a special comment syntax (only in code mode).
$ ys -e 'say:
read-line() \"Read line from stdin"
.words() \"Split into words"
.reverse() \"Reverse the words"
.joins() \"Join the words with a space"'
YS is YAML
YAML is YS
Couldn't have said it better myself!