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

Fix to parse "\#{{ ... }}" inside macro #5288

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

makenowjust
Copy link
Contributor

@makenowjust makenowjust commented Nov 13, 2017

Fixed #5287

Now "\#{{ ... }}" is parsed as macro expreession {{ ... }} wrapped with macro literal "\# and ". And this PR also fixed "\\#{{ ... }}" to parse it as only macro literal "\\#{{ ... }}".

Fixed crystal-lang#5287

Now `"\#{{ ... }}"` is parsed as macro expreession `{{ ... }}` wrapped with
macro literal `"\#` and `"`.
And this commit also fixed `"\\#{{ ... }}"` to parse it as only macro
literal `"\\#{{ ... }}"`.
@jhass
Copy link
Member

jhass commented Nov 13, 2017

It's a tricky case but I'm not sure I find the fixed behaviour intuitive. I would expect the escape in this place if "#{{...}}" was it's own kind of expression and not equivalent to either StringInterpolation(TupleLiteral(...)) or #MacroInterpolation(...). Maybe we should just make it a parse error and tell people to use @bew's workaround?

@makenowjust
Copy link
Contributor Author

@jhass I think to implement it is hard, at least harder than this, and the benefit is so little.

And, this behavior makes sense to me really. Currently "#{{ ... }}" inside macro is parsed as macro literal "#{{ ... }}" as-is because #{ inside string literal leads string interpolation even if inside macro. "#{{{ ... }}}" is parsed as literal "#{, macro expression {{ ... }} and macro literal }" due to the same reason. Thus, "\#{{ ... }}" should be parsed as macro literal "\#, macro expression {{ ... }} and literal " because \#{ inside string literal doesn't lead string interpolation.

@straight-shoota
Copy link
Member

Why not make #{{foo}} a macro interpolation plus # by default? If it is supposed to be a string interpolation, you'd just need to add whitespace. So there would be no need for escaping.

@makenowjust
Copy link
Contributor Author

/cc @asterite

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

Successfully merging this pull request may close these issues.

Macro: Parsing string fail when #{{...}} is inside the string
3 participants