Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add quoted strings which allow substitutions #456

Open
thraidh opened this issue Feb 26, 2017 · 1 comment
Open

Add quoted strings which allow substitutions #456

thraidh opened this issue Feb 26, 2017 · 1 comment

Comments

@thraidh
Copy link

thraidh commented Feb 26, 2017

Today quoted strings do not allow substitutions to keep full compatibility with JSON. Triple double-quoted strings also don't allow substitutions, even if there is no JSON-compatibility which could be broken.

If you want substitutions in multi-line strings, you would have to do something like

config.longtext="""first line
more lines...
line with """${value1}""" and """${value2}""".
more text with    tab
""""

This is a little bit cumbersome. Therefore I propose these solutions:

  1. a configuration option which changes the behavior of """
  2. a new quote $"""..."""
  3. a new quote $"...", which would also allow multi-line strings

In addition to substitution the default backslash-escapes should be interpreted.

Another feature to think about are improved indentation rules, where the indentation of the first line after the first line break is considered to be the zero indentation. The very first line would be ignored, if it was empty. For all lines after the first line break, the common prefix between the current and first line would be removed. This would work for spaces and tabs, but may not have the desired effect for mixed tabs and spaces. If you have those, the first line after the first line break should start at column one.

This would allow:

config {
    longtext=$"""
        first line
        more lines...
        line with ${value1} and ${value2}.
        more text with\ttab
        """"
}

to be the same as above, albeit more readable.

If that is too much magic, there is still the original """.

@thraidh
Copy link
Author

thraidh commented Mar 5, 2017

Just saw, that this is more or less a duplicate of #391. Havoc's suggestion was to use the backtick, as it is used in ES6. This syntax allows multiline and substitutions. I would not allow general expressions, as HOCON is no programming language.

An addition would be using three backticks similar to three double quotes, which will also use the indentation rules.

chezou added a commit to chezou/cloudera-sparklyr that referenced this issue Mar 7, 2017
To set core_site_safety_valve, we should replace settings such as AWS secrets by hand.
cf: lightbend/config#456
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant