Add the information to String literal of how it was created
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:
- 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.
- 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.
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.
I agree with you. Maybe it is good enough to provide a function (well, I guess users could do it themselves to start with? :man_shrugging: ) to transform the node for that string literal into a list of Node String when needed.