Repository navigation
feat: Add a line continuation character - #3408
Conversation
|
This looks great! When I look at the discussion in #819, I see that the similarity to the comma at the end of the line is an issue, so perhaps the following example would be more appropriate? derive x = 1
# \ + 2
\ + 3 |
|
Nice work! Looking at this I had quite a controversial idea: the fact that a new line has semantic meaning is quite strange for a language. How much worse would PRQL look like if we required the from albums
| select {album_id, title}
| group title (
sort album_id
| take 1
) |
I thought about this a while ago. I think one of the beautiful features of PRQL is that it's completely based around pipelines, and so can design the syntax around that. And that means that we don't need special pipe characters... This does seem mostly opinion / aesthetic. One more objective measure is comparing the number of times we need a line-continuation character with the number of times we need a pipe — the latter is 1-2 orders of magnitude greater. |
|
That's true, continuation character is much less common than a pipeline. Cool, I concur. |
|
I implemented an approach to "skip over" lines with comments, which I think is the best approach. One caveat — it does mean that when lexing PRQL, we always need to find the next non-comment, non-empty line to know when to finish lexing that "logical" line. I think that's probably OK given our performance requirements are lower than most... |
|
One of my questions is that the meaning of line breaks changes (line breaks are ignored) in tuples |
Exactly correct! Lmk if we could make that clearer |
|
This is ready to go, let me know any concerns? One reason not to merge is that we think it makes lexing less performant, and prevents us from optimizing in the future. It's basically doing exactly what But otherwise I'll merge... |
Oh, I did not check that excellent document. Thanks for pointing that. |
|
Let me cross link that existing doc & this new documentation |
|
FYI I renamed this in the docs to "line wrapping", from "line continuation"... |
| - within an array | ||
| - when the following line is a new statement, which starts with a keyword of | ||
| `func`, `let` or `from`. | ||
| `func`, `let` or `from` |
There was a problem hiding this comment.
Is the reference to func still correct here or is this outdated since the introduction of let?
IIRC, a function definition including the optional func would need to be written as
let my_func = func x -> ...So a line would never start with func anymore.
There was a problem hiding this comment.
I was actually just about to remove this! I was going to completely remove func...
I don't think it is that uncommon. bash, Python, and Julia all have
I see you've already moved on from this but I just wanted to add that I think it would be substantially worse. |
Could we not add parentheses It's also quite a common pattern, for example in Python for things like the following: s = ("this string "
"reads better when "
"written over multiple lines")EDIT: I guess one counterpoint is that you would need to know whether you are inside a "column expression" or a parenthesis for a pipeline like after a Similarly, many languages seem to be able to cope with unfinished expressions where a derive x = 1 +
3IDK enough about compilers to know what makes that possible for them and what the performance impact is. I do see Max's point about the impact of |
|
Thank you very much for implementing this @max-sixty ! 🙏 |
Yeah re pipelines. And I also think that grammar being different inside vs. outside of parentheses is less consistent, and so worse, all-else-equal |
I agree. I hate using parentheses in Python method chains just to bring the dot to the beginning of the line...... (Of course I don't have to do it myself because the wonderful Black handles it automatically.) |
Would close #3380, close #819
This kinda works but we need to decide how to handle comments. It's described inline — but basically:
...doesn't work, because the middle line is commented out, so is interpreted as a new line.
The big advantage of the line continuation character at the start of the line vs. the end is that it's easy to comment out parts of an expression, which this doesn't support.
One idea — have a line continuation character join to the previous line with content. So these would all be equal:
A refinement of that idea would be to only allow comments, not blank lines, to be joined to.
What do folks think?