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

string literal enhancement ideas #905

Closed
andychu opened this issue Feb 26, 2021 · 4 comments
Closed

string literal enhancement ideas #905

andychu opened this issue Feb 26, 2021 · 4 comments

Comments

@andychu
Copy link
Contributor

andychu commented Feb 26, 2021

Related to expression language enhancements #865

(1) get rid of legacy backticks in double quotes, especially for "Pulp" dialect. These should be valid:

var x = "`"  
echo "`"  

(2) for generating Make or Ninja: percent interpolation instead of dollar interpolation

var mystr = %"string literal %var %{var} \% \" \\ "
echo %"hello %world"   # need special detection in command mode

for variant in opt asan gc_debug { 
  build %"out1 out2: $in.%variant" {
    var = 'value'
  }
}

Notes:

  • An alternative design is to use doubling like %% and %", but I think that's too inconsistent and confusing.
  • We should probably deprecate $"" in this case, because it's confusing? Or maybe it's consistent? It's just an alias for "" that emphases that $ is the interpolation character. But then that's confused with $'', which needs to be replaced with c''.

(Discarded idea: repurpose it for C-escaped strings? $"" and %"" could both be c-escaped with \n \r \t \0 \x00 \u{1234} ? Nah that conflicts with r'' vs c''. Too confusing)

@andychu
Copy link
Contributor Author

andychu commented May 14, 2021

  • This came up again with user feedback -- c'' and $'' is confusing.
  • other feedback: string escaping is important to avoid HTML injection, SQL injection, shell injection

@andychu
Copy link
Contributor Author

andychu commented May 14, 2021

Crazy idea for new syntax similar to #799

  • echo ${'auto escaped string $foo ${bar} zzz '}
    • is this too close to $'foo\n' ?

Maybe Rust-like ?

  • echo r#"foo"#

    • although the rules aren't exactly the same, so this could be confusing
  • like symbolic tags in expression mode:

    • echo %c'foo'
    • echo %r"foo"
    • echo %raw'foo'
    • echo %html"<a href=$foo>"

I think the latter syntax might be compatible and not require a new lexer mode. You would have a token like Lit_SymbolLike and then look ahead for ' or ". And then THAT can enter a different mode if shopt --set parse_string_literals or --set parse_percent

  • problem: %foo vs. %foo'bar' in expression mode. Does that cause a problem?

More ideas

  • echo ${html'foo'}
  • const x = ${html'foo'} -- this works with no change?

@andychu
Copy link
Contributor Author

andychu commented May 14, 2021

I think this is mostly obviated by the escaper or default_escaper mechanism.

#938

@andychu
Copy link
Contributor Author

andychu commented May 29, 2021

Yeah this is all too elaborate, I did something simple and effective with #940

@andychu andychu closed this as completed May 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant