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

Basic string templates / interpolation in normal strings #722

Open
jiribenes opened this issue Dec 2, 2024 · 3 comments · May be fixed by #743
Open

Basic string templates / interpolation in normal strings #722

jiribenes opened this issue Dec 2, 2024 · 3 comments · May be fixed by #743
Assignees
Labels
feature New feature or request requires-design

Comments

@jiribenes
Copy link
Contributor

jiribenes commented Dec 2, 2024

Currently, we don't parse string templates in normal strings.

As a first step, we could allow at least arguments which are already strings like:

val domain = "https://api.effekt-lang.org"
val user = "effekt"
val resourceId = 42

"GET ${domain}/users/${user}/resource/${resourceId.show}"

This would involve:

  1. changing the parser (allowing ${ ... } to appear in normal strings)
  2. allowing string literals to be Template[...] in source.Tree
  3. piping them through Namer
  4. in Typer, making sure all of the splices are Strings
  5. and then when transforming into Core, just concatenate them for now into a Core string literal

There are some interesting detours/shortcuts:

  • try using show on the splices instead (probably horrible to use because of the error messages)
  • desugar to string concatenation directly in the parser
  • have the templates as a primitive instead of string concatenation; just define def infixConcat(s1, s2) = "${s1}${s2}"
@jiribenes jiribenes added feature New feature or request requires-design labels Dec 2, 2024
@dvdvgt
Copy link
Collaborator

dvdvgt commented Dec 12, 2024

When the lexer and new parser was written, we also talked about adding string interpolation to normal strings and not just extern definitions. Was there a particular reason we withheld from implementing this feature request back then other than the detours listed here, @b-studios?

@dvdvgt dvdvgt self-assigned this Dec 12, 2024
@dvdvgt
Copy link
Collaborator

dvdvgt commented Dec 12, 2024

Do we want to allow using string templates for pattern matching on string literals? If so, then so some of the proposed shortcuts will probably not work.

@jiribenes
Copy link
Contributor Author

Do we want to allow using string templates for pattern matching on string literals?

I wouldn't do that for now, that seems like a separate (& much more difficult issue).
I'd still probably lex it even there, and then reject it in the pattern matching compiler to preserve reasonable error msgs.

@dvdvgt dvdvgt linked a pull request Dec 12, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request requires-design
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants