Skip to content

Feature request: allow escaping backticks in string literals #821

@diegommm

Description

@diegommm

Description

Allow simple escaping of backticks in string literals using backticks. Example expression:

let myConst = `
  This string contains a single backtick: ``
`;
someVar == myConst

Why

  • Improve ergonomics
  • Very simple to implement
  • Backward compatible: it doesn't break anything
  • Known pattern for escaping. Used e.g. in CSV (e.g. "field 1","field "" 2"), SQL ('It''s fine'), YAML ('It''s fine'), etc.
  • Code generation use case:
    • Currently, every other literal can be used in code generation except for strings. With this approach, one can generate code for an expression and use strings.ReplaceAll(src, "`", "``") to interpolate a string constant. This would make generated code very performant and efficient.
    • Especially useful if: (1) the environment is a fixed struct with very few variables; (2) an expression needs to be generated and will be executed many times in a tight loop; (3) there can be one or many constant string values and adding them to the environment can be impractical or incur in performance costs.

Adding a reference PR with the implementation and tests: #820

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions