Strings simplified

The first language iteration is almost over. It's time to revise some previously made decisions on syntax and semantic. Nowadays Argentum has too many syntax for strings - single and multiline, with and without interpolation, strings are defined with "" and ``. In single-line ""-strings there used C/C++ escaping, in other strings - parenthesis escaping ({}, ${}, [], ()).

So first simplification: there are only one escaping - the parenthesis one. And only one way of defining string ""-strings. In ""-strings there used {} escaping:

s = "Hello";   // single-line string
a = "Hello {userName}!";   // single-line string with escapes

The same ""-string can become a multiline string, if it has a newline character in it. In this case all characters in the first line define the formatting options, all lines after the format line define the text, that can or cannot have escapes depending on the format string. This multiline string literal is defined by indentation and must be closed with '"' on the next outdented line (to not to break the existing text editors and highlighters).

d = "
    multiline string
    without escapes,
    so {}-are just ordinary symbols
e = "{}
    multiline string with escapes: {2+2}
    this will be printed as 4
f = "$[]
    multiline string with fancy escapes $[] (btw technically it's single line)

The full syntax of format string allows us to define:

  • escaping,
  • tabs handling,
  • extra indentation,
  • end-of-line encoding,
  • adding of extra new lines and indentations at the end.

It left not changed and can be found here: string interpolation

Since there is no more C/C++ style escapes, there introduced a macro utf32_, that creates a string using utf code-points. It can be used directly or to define self-documenting constants:

const LF = utf32_(0x0a);

log("Hello {travelerName}{LF}");

There are also added $""- strings that:

  • Cannot be multiline
  • Use ${} as escape brackets.

They might be useful when creating single-line strings having some {} characters.

But for JSONs the multiline form is better:

     "name": (toJsonString(
     "age": (user.age)

BTW, This string simplification allows to use the backtick character (`) for simplified lambda declarations.

Leave a Reply

Your email address will not be published. Required fields are marked *