diff options
author | Matthäus G. Chajdas <dev@anteru.net> | 2020-09-22 20:40:58 +0200 |
---|---|---|
committer | Matthäus G. Chajdas <dev@anteru.net> | 2020-09-22 20:40:58 +0200 |
commit | f0d31da6b26e7057dc488d8ee04e06b1a448a49c (patch) | |
tree | bb01aa5da7a5f4aa4e3e2a4836b040c535ea977d /pygments/lexers/perl.py | |
parent | 07f596dbb9357c1ec2077bdc4319f594d287ae15 (diff) | |
download | pygments-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.py | 16 |
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): |