eric6/ThirdParty/Pygments/pygments/lexers/perl.py

changeset 7983
54c5cfbb1e29
parent 7701
25f42e208e08
equal deleted inserted replaced
7982:48d210e41c65 7983:54c5cfbb1e29
3 pygments.lexers.perl 3 pygments.lexers.perl
4 ~~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~~
5 5
6 Lexers for Perl, Raku and related languages. 6 Lexers for Perl, Raku and related languages.
7 7
8 :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details. 9 :license: BSD, see LICENSE for details.
10 """ 10 """
11 11
12 import re 12 import re
13 13
206 } 206 }
207 207
208 def analyse_text(text): 208 def analyse_text(text):
209 if shebang_matches(text, r'perl'): 209 if shebang_matches(text, r'perl'):
210 return True 210 return True
211
212 result = 0
213
211 if re.search(r'(?:my|our)\s+[$@%(]', text): 214 if re.search(r'(?:my|our)\s+[$@%(]', text):
212 return 0.9 215 result += 0.9
216
217 if ':=' in text:
218 # := is not valid Perl, but it appears in unicon, so we should
219 # become less confident if we think we found Perl with :=
220 result /= 2
221
222 return result
213 223
214 224
215 class Perl6Lexer(ExtendedRegexLexer): 225 class Perl6Lexer(ExtendedRegexLexer):
216 """ 226 """
217 For `Raku <https://www.raku.org>`_ (a.k.a. Perl 6) source code. 227 For `Raku <https://www.raku.org>`_ (a.k.a. Perl 6) source code.
709 return True 719 return True
710 rating = 0.05 720 rating = 0.05
711 continue 721 continue
712 break 722 break
713 723
724 if ':=' in text:
725 # Same logic as above for PerlLexer
726 rating /= 2
727
714 return rating 728 return rating
715 729
716 def __init__(self, **options): 730 def __init__(self, **options):
717 super().__init__(**options) 731 super().__init__(**options)
718 self.encoding = options.get('encoding', 'utf-8') 732 self.encoding = options.get('encoding', 'utf-8')

eric ide

mercurial