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

Heredoc Definition Strings #76

Closed
maxprehl opened this issue Feb 26, 2024 · 2 comments
Closed

Heredoc Definition Strings #76

maxprehl opened this issue Feb 26, 2024 · 2 comments

Comments

@maxprehl
Copy link

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:

# heredocs

It looks like:

image

It should look like:

image

@maxprehl
Copy link
Author

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?

start_pattern: Pattern.new(
Pattern.new(
match: lookBehindToAvoid(/</).then(/<<-/),
tag_as: "keyword.operator.heredoc",
).then(std_space).then(
match: /"|'/,
reference: "start_quote"
).then(std_space).then(
match: name_pattern,
reference: "delimiter",
tag_as: "punctuation.definition.string.heredoc",
).lookAheadFor(/\s|;|&|<|"|'/).matchResultOf(
"start_quote"
).then(
match: /.*/,
includes: [
:normal_statement_context,
],
)
),

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
Copy link
Owner

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.

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