jeff-hykin / better-shell-syntax

💾 📦 ♻️ An improvement to the shell syntax for VS Code
MIT License
51 stars 4 forks source link

Heredoc Definition Strings #76

Closed maxprehl closed 6 months ago

maxprehl commented 7 months ago

Hi Jeff, I'd love to help with the heredoc issues, started this new issue so we don't have to bother everyone on the previous issue.

The code with a problem is:

https://github.com/jeff-hykin/better-shell-syntax/blob/7220287a2e40d5909f346ebdc913a67c39f1927c/main/main.rb#L936

It looks like:

image

It should look like:

image

maxprehl commented 7 months ago

I just started looking through your library, ruby-grammar-builder https://github.com/jeff-hykin/ruby_grammar_builder

Trying to get familiar with it, but i'm a bit confused still.

For the "=cut" issue I'm wondering where exactly you think the issue lies.

Based on what you said in the old issue, it's somewhere in the start_pattern for the heredoc PatternRange?

https://github.com/jeff-hykin/better-shell-syntax/blob/7220287a2e40d5909f346ebdc913a67c39f1927c/main/main.rb#L943-L962

i'm guessing it's this section? L950

then(
    match: name_pattern,
    reference: "delimiter",
    tag_as: "punctuation.definition.string.heredoc",
)

I think you said in the library that there's some kind of limitation of having sub-matches within a PatternRange?

Is this one of those situations that this then clause should be a sub-match for a string literal?

Really curious if i can help you out here! I'm also happy to also help on the other heredoc issues with the pipelines on the same line or the line-breaks. I'm also really curious about #64 if there is even a way for you to delegate a section of code to a different syntax highlighter?

jeff-hykin commented 6 months ago

Is this one of those situations that this then clause should be a sub-match for a string literal?

Yes! Nice Job, that is exactly the case. I believe shell would support even a multi-line delimiter but theres no way for the grammar to match that.

That said, the existing behavior could be improved. Right now its looking for name_pattern which is way more restrictive than any possible string. One line single-quote strings can be perfectly matched with a single regex. So that could be one improvement. Double quote strings though, even if they're a single line, can't be matched perfectly because of interpolation. Interpolation can only be hackily supported.