Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix perlElseIfError when used in other syntax type #80

Merged
merged 1 commit into from

2 participants

@benizi

When used in the Mason syntax type, the way the perlElseIfError group
was handled caused any line beginning with 'if' to be highlighted as an
error. This is due to the way Vim includes other syntax files.
perlElseIfError was marked as 'contained', but wasn't limited to a
specific group. When perl.vim gets included, perlElseIfError is then
allowed to exist at what was formerly the top level.

Instead, make the errant '\s*if' of 'elseif' and 'else if' a part of the
perlConditional group, so that perlElseIfError can be confined to
containedin=perlConditional.

In Perl files, everything that should be marked as a perlElseIfError is
handled properly. In Mason files, this prevents the erroneous
perlElseIfError highlighting for 'if', but only marks 'elseif' as an
error (the :syn-keyword perlElseIfError works; the :syn-match doesn't).

Benjamin R. Haskell Fix perlElseIfError when used in other syntax type
When used in the Mason syntax type, the way the perlElseIfError group
was handled caused any line beginning with 'if' to be highlighted as an
error.  This is due to the way Vim includes other syntax files.
perlElseIfError was marked as 'contained', but wasn't limited to a
specific group.  When perl.vim gets included, perlElseIfError is then
allowed to exist at what was formerly the top level.

Instead, make the errant '\s*if' of 'elseif' and 'else if' a part of the
perlConditional group, so that perlElseIfError can be confined to
containedin=perlConditional.

In Perl files, everything that should be marked as a perlElseIfError is
handled properly.  In Mason files, this prevents the erroneous
perlElseIfError highlighting for 'if', but only marks 'elseif' as an
error (the :syn-keyword perlElseIfError works; the :syn-match doesn't).
0ea3bdb
@hoelzro
Owner

@benizi Could you provide a sample Mason file that demonstrates this behavior, as well as perhaps a screenshot? I'm unable to reproduce this issue at the moment, but I've only written a very small Mason file.

@benizi

I don't use Mason (or even Perl that much lately). Someone reported the issue against my mostly-abandoned fork. I have no idea whether it's valid Mason syntax, but here's what I was using to test the fix:

% my $noun = 'World';
Hello <% $noun %>!
How are ya?
<% if (1) { $noun } elsif (1) { $noun } else { $yay } %>
<% if (1) { $noun } elseif (1) { $noun } else { $yay } %>
<% if (1) { $noun } else if (1) { $noun } else { $yay } %>
<% if (1) { $noun } else
if (1) { $noun } else { $yay } %>
@hoelzro
Owner

@benizi Much appreciated; I see what you're saying now! I'll look into this tomorrow.

@hoelzro hoelzro merged commit 95a2af4 into vim-perl:master
@hoelzro
Owner

Merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 28, 2012
  1. Fix perlElseIfError when used in other syntax type

    Benjamin R. Haskell authored
    When used in the Mason syntax type, the way the perlElseIfError group
    was handled caused any line beginning with 'if' to be highlighted as an
    error.  This is due to the way Vim includes other syntax files.
    perlElseIfError was marked as 'contained', but wasn't limited to a
    specific group.  When perl.vim gets included, perlElseIfError is then
    allowed to exist at what was formerly the top level.
    
    Instead, make the errant '\s*if' of 'elseif' and 'else if' a part of the
    perlConditional group, so that perlElseIfError can be confined to
    containedin=perlConditional.
    
    In Perl files, everything that should be marked as a perlElseIfError is
    handled properly.  In Mason files, this prevents the erroneous
    perlElseIfError highlighting for 'if', but only marks 'elseif' as an
    error (the :syn-keyword perlElseIfError works; the :syn-match doesn't).
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 3 deletions.
  1. +3 −3 syntax/perl.vim
View
6 syntax/perl.vim
@@ -64,7 +64,7 @@ syn region perlGenericBlock matchgroup=perlGenericBlock start="{" end="}" conta
" All keywords
"
syn match perlConditional "\<\%(if\|elsif\|unless\|given\|when\|default\)\>"
-syn match perlConditional "\<else\>" nextgroup=perlElseIfError skipwhite skipnl skipempty
+syn match perlConditional "\<else\%(\%(\_s\*if\>\)\|\>\)" contains=perlElseIfError skipwhite skipnl skipempty
syn match perlRepeat "\<\%(while\|for\%(each\)\=\|do\|until\|continue\)\>"
syn match perlOperator "\<\%(defined\|undef\|eq\|ne\|[gl][et]\|cmp\|not\|and\|or\|xor\|not\|bless\|ref\|do\)\>"
syn match perlControl "\<\%(BEGIN\|CHECK\|INIT\|END\|UNITCHECK\)\>"
@@ -188,8 +188,8 @@ syn match perlSpecialMatch "(\*\%(\%(PRUNE\|SKIP\|THEN\)\%(:[^)]*\)\=\|\%(MARK\
" Highlight lines with only whitespace (only in blank delimited here documents) as errors
syn match perlNotEmptyLine "^\s\+$" contained
" Highlight "} else if (...) {", it should be "} else { if (...) { " or "} elsif (...) {"
-syn match perlElseIfError "\s\+if" contained
-syn keyword perlElseIfError elseif
+syn match perlElseIfError "else\_s*if" containedin=perlConditional
+syn keyword perlElseIfError elseif containedin=perlConditional
" Variable interpolation
"
Something went wrong with that request. Please try again.