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

Format string reentrency #2244

Open
ncannasse opened this issue Oct 10, 2013 · 13 comments
Open

Format string reentrency #2244

ncannasse opened this issue Oct 10, 2013 · 13 comments

Comments

@ncannasse
Copy link
Member

With b94ee60, it is now possible to have format strings in format strings: 'Hello ${name '$age years'} old'

However there seems to be an issue if the inner string has spaces around it:

'${ '${x}'}' does not work (the inner string is not considered a format string)

@ncannasse
Copy link
Member Author

Another related issue: we should allow any code in ${} , not only values.
For instance the following does not work ATM:
'${ var str = ""; str; }' while the following works : '${{ var str = ""; str; }}'

@ncannasse
Copy link
Member Author

Another last issue is that quoted chars in sub format strings are unquoted.

@ghost ghost assigned ncannasse Jan 6, 2014
@Simn Simn modified the milestones: 3.2, 3.3 Mar 24, 2015
@Simn Simn modified the milestones: 3.3, December 2015 Dec 8, 2015
@ncannasse
Copy link
Member Author

That's actually quite complex and requires a lot of testing. Any volunteer to take over this task ? @Simn @nadako ?

@Simn
Copy link
Member

Simn commented Dec 31, 2015

I think we should first find a better way to communicate the quoted status (" or ') for strings, which would make this a Haxe 4 issue.

@ncannasse
Copy link
Member Author

you mean inside the string itself ? this should not be required, given that we have all the information needed to correctly lex it

@Simn
Copy link
Member

Simn commented Dec 31, 2015

'${ '${x}'}' does not work (the inner string is not considered a format string)

This suggests to me that the information is lost somewhere. I'm not very familiar with the current implementation, but in general inner format strings should be handled without any additional effort via normal expression recursion.

@ncannasse
Copy link
Member Author

Yes, I agree, this is normally done directly in lexer.mll (string2, code_string) which should unquote things as they should, but doesn't

@Simn
Copy link
Member

Simn commented Dec 31, 2015

Don't we need a stack in order to lex nested structures like this? At the moment we only have buf which is reset on new strings/comments/regexes, so that really doesn't support any notion of "string in string".

@Simn
Copy link
Member

Simn commented Dec 31, 2015

Eh, I guess we don't because we dump everything into the same buffer and deal with it while typing.

@Simn
Copy link
Member

Simn commented Dec 31, 2015

I fixed the spacing issue. As for this:

Another related issue: we should allow any code in ${} , not only values.
For instance the following does not work ATM:
'${ var str = ""; str; }' while the following works : '${{ var str = ""; str; }}'

I consider that a fair limitation. If you want a block you have to start a block. Sure it looks a bit funny because interpolation also uses {} as delimiters, but I don't see why we should imply blocks here.

Another last issue is that quoted chars in sub format strings are unquoted.

Any example of that?

@ncannasse
Copy link
Member Author

'${'\''}' should be ok, but it's not. I think that requires an entirely different way of processing format strings.

@Simn Simn modified the milestones: December 2015, 3.4 Feb 20, 2016
@Simn Simn modified the milestones: 3.4, 4.0 Jan 9, 2017
@Aurel300
Copy link
Member

Aurel300 commented Dec 4, 2019

Related issues:

And here is a new one:

class Main {
  public static function main():Void {
    var foo = "hello";
    trace('${'${foo}'}'); // outputs hello
    trace('\n${'${foo}'}'); // outputs ${foo}
  }
}

@nadako
Copy link
Member

nadako commented May 25, 2020

I'm going to revive my old branch with the "mini-ast" and probably do what is suggested in #9370 (comment).

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

6 participants