mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 09:40:21 +00:00
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:
committed by
Colin Seymour
parent
15885701cd
commit
21babbceb1
@@ -358,10 +358,10 @@ module Linguist
|
|||||||
end
|
end
|
||||||
|
|
||||||
disambiguate ".pm" do |data|
|
disambiguate ".pm" do |data|
|
||||||
if /^\s*(?:use\s+v6\s*;|(?:\bmy\s+)?class|module)\b/.match(data)
|
if /\buse\s+(?:strict\b|v?5\.)/.match(data)
|
||||||
Language["Perl 6"]
|
|
||||||
elsif /\buse\s+(?:strict\b|v?5\.)/.match(data)
|
|
||||||
Language["Perl"]
|
Language["Perl"]
|
||||||
|
elsif /^\s*(?:use\s+v6\s*;|(?:\bmy\s+)?class|module)\b/.match(data)
|
||||||
|
Language["Perl 6"]
|
||||||
elsif /^\s*\/\* XPM \*\//.match(data)
|
elsif /^\s*\/\* XPM \*\//.match(data)
|
||||||
Language["XPM"]
|
Language["XPM"]
|
||||||
end
|
end
|
||||||
|
|||||||
8
test/fixtures/Perl/Module.pm
vendored
Normal file
8
test/fixtures/Perl/Module.pm
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
use 5.006;
|
||||||
|
use strict;
|
||||||
|
|
||||||
|
=head1
|
||||||
|
|
||||||
|
module
|
||||||
|
|
||||||
|
=cut
|
||||||
Reference in New Issue
Block a user