Stream: ideas

Topic: Syntax/convention for including other languages in strings


view this post on Zulip Eli Dowling (Apr 01 2024 at 04:46):

I think having a standard annotation for strings containing other languages would be a helpful addition to roc, this could either be a language feature or a community convention, like always naming functions that injest that data the name of the language eg:

jsonData=
     json
        """
         {"data":10}
        """
htmlData=
     html
        """
         {"data":10}
        """

Having some level of standardization here lets us do some very cool things:

  1. We can have tree-sitter automatically hightlight the language in the string correctly
  2. We could actually have RocLs or an editor extension start that language's language server and provide completion, diagnostics hover etc

image.png

view this post on Zulip Luke Boswell (Apr 01 2024 at 04:50):

My preference would be similar to markdown code blocks..

htmlData=
    """html
        {"data":10}
    """

view this post on Zulip Eli Dowling (Apr 01 2024 at 04:53):

I did think that but it creates some weirdness in cases like this :
"""html"""
like do we include it? or not?
I could imagine a specific syntax like:

%html"""
<div>
"""

%html"<div>"

One thing i really like about the function version is that you will often want to parse or ingest or validate the data in some way anyway

view this post on Zulip Luke Boswell (Apr 01 2024 at 05:46):

like do we include it? or not?

I thought the multi-line content starts on the next line so it wouldn't be an issue.

view this post on Zulip Isaac Van Doren (Apr 01 2024 at 12:21):

This sounds nice!

view this post on Zulip Isaac Van Doren (Apr 01 2024 at 12:21):

You can have a single line string that uses triple quotes

view this post on Zulip Isaac Van Doren (Apr 01 2024 at 12:22):

I like having the language after the “”” too. I think it would be fine to just not enable it for single line triple quote strings

view this post on Zulip Eli Dowling (Apr 01 2024 at 12:26):

This is currently valid roc:

html=
  """<div>
  </div>
  """

I do agree it's be nice having it like markdown I'm just very leery of putting anything inside the quotes that isn't part of the string, I think it's unintuitive and could definitely cause gotchas

view this post on Zulip Richard Feldman (Apr 01 2024 at 12:46):

I like the original idea as a convention! Some nice things about it:

view this post on Zulip Richard Feldman (Apr 01 2024 at 12:47):

I like the idea of the heuristic for "should we enable syntax highlighting?" being "is it an unqualified function call with exactly 1 argument, and that one argument is a triple-quoted string"

view this post on Zulip Eli Dowling (Apr 02 2024 at 05:31):

Cool, all reasons I agree with. I'll add the feature to tree sitter sometime soon and put it on an eventual to-do list for the language server.

view this post on Zulip Eli Dowling (Apr 02 2024 at 23:20):

This is in the latest version of the tree sitter Grammer, for the vscode folks... Well I'll take a look at adding this to the extension :)

view this post on Zulip Eli Dowling (Apr 13 2024 at 06:44):

Well I've been running this for a while and it has a problem.
A bunch of usual functions are also file formats tree-sitter recognizes. Such as "panic". so the highlighting goes all weird


Last updated: Jun 16 2026 at 16:19 UTC