summaryrefslogtreecommitdiff
path: root/pygments/lexers/perl.py
diff options
context:
space:
mode:
authorMatthäus G. Chajdas <dev@anteru.net>2020-09-22 20:40:58 +0200
committerMatthäus G. Chajdas <dev@anteru.net>2020-09-22 20:40:58 +0200
commitf0d31da6b26e7057dc488d8ee04e06b1a448a49c (patch)
treebb01aa5da7a5f4aa4e3e2a4836b040c535ea977d /pygments/lexers/perl.py
parent07f596dbb9357c1ec2077bdc4319f594d287ae15 (diff)
downloadpygments-git-task/add-analyze-text.tar.gz
Improve various analyse_text methods.task/add-analyze-text
* Make Perl less confident in presence of :=. * Improve brainfuck check to not parse the whole input. * Improve Unicon by matching \self, /self * Fix Ezhil not matching against the input text
Diffstat (limited to 'pygments/lexers/perl.py')
-rw-r--r--pygments/lexers/perl.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/pygments/lexers/perl.py b/pygments/lexers/perl.py
index 741de3fd..95fb94e7 100644
--- a/pygments/lexers/perl.py
+++ b/pygments/lexers/perl.py
@@ -208,8 +208,18 @@ class PerlLexer(RegexLexer):
def analyse_text(text):
if shebang_matches(text, r'perl'):
return True
+
+ result = 0
+
if re.search(r'(?:my|our)\s+[$@%(]', text):
- return 0.9
+ result += 0.9
+
+ if ':=' in text:
+ # := is not valid Perl, but it appears in unicon, so we should
+ # become less confident if we think we found Perl with :=
+ result /= 2
+
+ return result
class Perl6Lexer(ExtendedRegexLexer):
@@ -711,6 +721,10 @@ class Perl6Lexer(ExtendedRegexLexer):
continue
break
+ if ':=' in text:
+ # Same logic as above for PerlLexer
+ rating /= 2
+
return rating
def __init__(self, **options):