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

Support indented here-docs (fix incorrect string highlighting) #26

Open
aeschli opened this issue Nov 1, 2017 · 14 comments
Open

Support indented here-docs (fix incorrect string highlighting) #26

aeschli opened this issue Nov 1, 2017 · 14 comments

Comments

@aeschli
Copy link
Contributor

aeschli commented Nov 1, 2017

From @skaurus on October 20, 2017 14:34

I'm talking about this: http://perldoc.perl.org/perlop.html#Indented-Here-docs

Steps to Reproduce:

  1. write perl code like that:
if ($cond) {
    my $string = <<~EOF;
        indented
        text
        will be
        indented
        just by 4 spaces
        and totally not 8
    EOF
    my $res = $self->method;
}
...
  1. code after closing EOF will be colored as if it's still inside the string.

Currently it works only if opening here-doc marker does not have a tilde; AND closing marker is not indented (at all).

Reproduces without extensions: Yes

Copied from original issue: microsoft/vscode#36640

@aeschli
Copy link
Contributor Author

aeschli commented Nov 1, 2017

From @roblourens on October 20, 2017 17:31

@mjbvz This is perl, not PHP :D

@skaurus
Copy link

skaurus commented Dec 27, 2017

Maybe I can help?
Issues like this will pop up from time to time (Perl is not getting much love these days...) and I am motivated to fix them.

@skaurus
Copy link

skaurus commented Feb 26, 2019

Really, could you please point me to the relevant source file, or docs, or anything and I'll try squash that motherfbug. I'm a bit pissed by it at the moment. I have to create a multiline comment and write inside specific incantation to make syntax highlighting happy, and that looks ugly.

@rdwampler
Copy link

@skaurus:
I believe this the relevant section in the grammar.

<dict>
<key>begin</key>
<string>(((&lt;&lt;) *'([^']*)'))(.*)\n?</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.definition.string.perl</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>string.unquoted.heredoc.quote.perl</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>punctuation.definition.heredoc.perl</string>
</dict>
<key>4</key>
<dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>$self</string>
</dict>
</array>
</dict>
</dict>
<key>contentName</key>
<string>string.unquoted.heredoc.quote.perl</string>
<key>end</key>
<string>(^\4$)</string>
</dict>
<dict>
<key>begin</key>
<string>(((&lt;&lt;) *\\((?![=\d\$\( ])[^;,'"`\s\)]*)))(.*)\n?</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.definition.string.perl</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>string.unquoted.heredoc.quote.perl</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>punctuation.definition.heredoc.perl</string>
</dict>
<key>4</key>
<dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>$self</string>
</dict>
</array>
</dict>
</dict>
<key>contentName</key>
<string>string.unquoted.heredoc.quote.perl</string>
<key>end</key>
<string>(^\4$)</string>
</dict>

I believe you'll need to add a regex to match the indented terminator. An example can be found in the ruby bundle:
https://github.com/textmate/ruby.tmbundle/blob/300b9961332c6dc8e282bd8c3192c2ea528f95a6/Syntaxes/Ruby.plist#L1765-L1805

@skaurus
Copy link

skaurus commented Feb 28, 2019

Thanks!

@skaurus
Copy link

skaurus commented Mar 16, 2019

So I finally got to it.

It seems that regexes that match the start of the here-docs can have one capture group less, since groups 1 and 2 are identical. So line 2044 from the code fragment above would be:
<string>((&lt;&lt;) *'([^']*)')(.*)\n?</string>

Now, to actually support indented here-docs it would be nice to use regex conditionals: if opening here-doc identifier have ~, then and only then closing identifier can have \s* before it. Wikipedia says that TextMate uses oniguruma regex library, and it have support for regex conditionals since version 6.5.0. But it seems that current release of TextMate uses some older version because conditional regexes do not work.

Right now we can allow spaces regardless of ~ presence, but that can broke highlighting in some cases.
Or, I can create copies of all existing here-doc definitions, with ~ and spaces allowed.

Which way is better do you think?

@skaurus
Copy link

skaurus commented Mar 16, 2019

Commit with an extra capture groups removed (only in here-docs definitions) and spaces allowed regardless of tilda presence would look like this: skaurus@bba43a9

With regex conditionals, ~? in start regexes would be replaced with (~)?, and (^\3$) in end regexes with (^(?(3)\s*|)\4$).

@skaurus
Copy link

skaurus commented Mar 26, 2019

Hey?

@nezirin
Copy link

nezirin commented Oct 13, 2019

m(._.)m

@camtauxe
Copy link

Looks like there's another pull request for the same thing #41, (though it's just as neglected)

@PatrickCronin
Copy link
Contributor

There's also #42, which is a bit more thorough than 41.

@namotco
Copy link

namotco commented Jul 26, 2024

Any movement on this PR?

@PatrickCronin
Copy link
Contributor

I believe #42 (merged) has addressed this issue.

@namotco
Copy link

namotco commented Jul 26, 2024 via email

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

7 participants