Open sesajad opened 4 years ago
Yes, also template literals. Will add to examples.
Ok string escapes will convolute the examples, so let's just assume the following:
{
x: 'don\'t ever tink',
y: "tink \"you\" no me",
z: `come \`follow\` me`
}
As for templates, there actually was an example, but since it diverges from the JavaScript template literals, I couldn't recognize it on the first sight. I changed it to match JavaScript syntax, i.e.
{
x: 42;
y: `the answer is (rather obviously): ${x}`
}
Any thoughts on the change?
for string escapes, I agree. moreover, as we are somehow extending JSONs, we should support it. here is it's BNF. I'll check to make sure we are extending it.
Templates from JS are just fine. I can also add that Python f-string and Scala string interpolation have similar functionalities (and syntax).
Additional question: why do we have two (or even three) quote-marks? while JSON having one?
for string escapes, I agree. moreover, as we are somehow extending JSONs, we should support it. here is it's BNF. I'll check to make sure we are extending it.
We are not:
{
"x": [1, 2, 3, 4]
}
{
"x": {1, 2, 3, 4}
}
But, could we, without ambiguity?
Additional question: why do we have two (or even three) quote-marks? while JSON having one?
ease of use (which JSON doesn't have). simply put, this:
{
projectName: `sadjad's "blog"`
}
is easier (and more readable) than:
{
projectName: "sadjad's \"blog\""
}
or
{
projectName: 'sadjad\'s "blog"'
}
Templates from JS are just fine. I can also add that Python f-string and Scala string interpolation have similar functionalities (and syntax).
Further contemplation on this: should we also add custom template strings of Javascript? i.e. should:
{
name: "world",
msg: x`hellow ${world}!`
}
be equivalent to:
{
name: "world",
msg: x[{'hellow', '!'}, {"world"}]
}
?
I guess yes. note that we currently don't have