loreanvictor / kaashi

A turing complete JSON-like declarative language for data/config description
MIT License
17 stars 1 forks source link

Do we need string escape? #2

Open sesajad opened 4 years ago

sesajad commented 4 years ago

I guess yes. note that we currently don't have

loreanvictor commented 4 years ago

Yes, also template literals. Will add to examples.

loreanvictor commented 4 years ago

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?

sesajad commented 4 years ago
  1. 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.

  2. Templates from JS are just fine. I can also add that Python f-string and Scala string interpolation have similar functionalities (and syntax).

  3. Additional question: why do we have two (or even three) quote-marks? while JSON having one?

loreanvictor commented 4 years ago

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"}]
}

?