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

Add the information to String literal of how it was created #57

Open
jfmengels opened this issue Jun 16, 2020 · 2 comments
Open

Add the information to String literal of how it was created #57

jfmengels opened this issue Jun 16, 2020 · 2 comments

Comments

@jfmengels
Copy link
Collaborator

It would be nice to know whether a String literal was created using "x" or using """x""".

I don't think we have the information at this point, and if we want to pin-point a part of the string based on the range from the expression node, then we need to account for the """.

Possible ways:

  1. Add the information as an additional argument
type Expression =
  = ...
  | Literal StringLiteralType String

-- Let's think of a better name for this one
type StringLiteralType
  = SingleQuote
  | TripleQuote

Then, if we want to select a sub-string, we need to offset the string by one for SingleQuote and by 3 for TripleQuote.

  1. Add a new variant to expression:
type Expression =
  = ...
  | Literal String
  | MultilineStringLiteral (List (Node String))

I am thinking it could be interesting to have a List of lines, each with their own range. That would make a lot of things quite easier. If you do need the concatenated string, then that is relatively easy to do.

I know I have struggled with finding sub-strings in multiline comments (maybe that could also be split into different types like this?), and I hope that this can make things a bit easier (especially if we have the range for each line).

I think this option is better, but the thing that makes it less nice is that if you are looking at strings, you need to handle both cases.

@stil4m
Copy link
Owner

stil4m commented Jun 17, 2020

I feel that option one has the nicest interface. My gut feeling says that in most usages you are interested in the String and pattern matching like Literal _ stringValue will be most used.

I see your point on the lines of a string literal. Let's sleep on it.

@jfmengels
Copy link
Collaborator Author

I agree with you. Maybe it is good enough to provide a function (well, I guess users could do it themselves to start with? 🤷‍♂️ ) to transform the node for that string literal into a list of Node String when needed.

jiegillet pushed a commit to jiegillet/elm-syntax that referenced this issue Jul 20, 2024
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

No branches or pull requests

2 participants