Fix Perl 5 and 6 disambiguation bug (#3860)

* Add test to demonstrate Perl syntax detection bug

A Perl 5 .pm file containing the word `module` or `class`, even with
an explicit `use 5.*` statement, is recognized as Perl 6 code.

* Improve Perl 5 and Perl 6 disambiguation

The heuristics for Perl 5 and 6 `.pm` files disambiguation was done
searching for keywords which can appear in both languages (`class` and
`module`) in addition to the `use` statement check.

Due to Perl 6 being tested first, code containing those words would
always be interpreted as Perl 6.

Test order was thus reversed, testing for Perl 5 first. Since Perl 6
code would never contain a `use 5.*` statement, this does no harm to
Perl 6 detection while fixing the problem to Perl 5.

Fixes: #3637
This commit is contained in:
Cesar Tessarin
2017-10-23 07:16:56 -02:00
committed by Colin Seymour
parent 15885701cd
commit 21babbceb1
2 changed files with 11 additions and 3 deletions

View File

@@ -358,10 +358,10 @@ module Linguist
end
disambiguate ".pm" do |data|
if /^\s*(?:use\s+v6\s*;|(?:\bmy\s+)?class|module)\b/.match(data)
Language["Perl 6"]
elsif /\buse\s+(?:strict\b|v?5\.)/.match(data)
if /\buse\s+(?:strict\b|v?5\.)/.match(data)
Language["Perl"]
elsif /^\s*(?:use\s+v6\s*;|(?:\bmy\s+)?class|module)\b/.match(data)
Language["Perl 6"]
elsif /^\s*\/\* XPM \*\//.match(data)
Language["XPM"]
end

8
test/fixtures/Perl/Module.pm vendored Normal file
View File

@@ -0,0 +1,8 @@
use 5.006;
use strict;
=head1
module
=cut