1# -*- coding: utf-8 -*- 2 3# Copyright (c) 2004 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> 4# 5 6""" 7Module implementing a Perl lexer with some additional methods. 8""" 9 10import contextlib 11 12from PyQt5.Qsci import QsciLexerPerl 13 14from .Lexer import Lexer 15import Preferences 16 17 18class LexerPerl(Lexer, QsciLexerPerl): 19 """ 20 Subclass to implement some additional lexer dependant methods. 21 """ 22 def __init__(self, parent=None): 23 """ 24 Constructor 25 26 @param parent parent widget of this lexer 27 """ 28 QsciLexerPerl.__init__(self, parent) 29 Lexer.__init__(self) 30 31 self.commentString = "#" 32 33 self.keywordSetDescriptions = [ 34 self.tr("Keywords"), 35 ] 36 37 def initProperties(self): 38 """ 39 Public slot to initialize the properties. 40 """ 41 self.setFoldComments(Preferences.getEditor("PerlFoldComment")) 42 self.setFoldCompact(Preferences.getEditor("AllFoldCompact")) 43 with contextlib.suppress(AttributeError): 44 self.setFoldPackages(Preferences.getEditor("PerlFoldPackages")) 45 self.setFoldPODBlocks(Preferences.getEditor("PerlFoldPODBlocks")) 46 with contextlib.suppress(AttributeError): 47 self.setFoldAtElse(Preferences.getEditor("PerlFoldAtElse")) 48 49 def autoCompletionWordSeparators(self): 50 """ 51 Public method to return the list of separators for autocompletion. 52 53 @return list of separators (list of strings) 54 """ 55 return ['::', '->'] 56 57 def isCommentStyle(self, style): 58 """ 59 Public method to check, if a style is a comment style. 60 61 @param style style to check (integer) 62 @return flag indicating a comment style (boolean) 63 """ 64 return style in [QsciLexerPerl.Comment] 65 66 def isStringStyle(self, style): 67 """ 68 Public method to check, if a style is a string style. 69 70 @param style style to check (integer) 71 @return flag indicating a string style (boolean) 72 """ 73 return style in [QsciLexerPerl.DoubleQuotedHereDocument, 74 QsciLexerPerl.DoubleQuotedString, 75 QsciLexerPerl.QuotedStringQ, 76 QsciLexerPerl.QuotedStringQQ, 77 QsciLexerPerl.QuotedStringQR, 78 QsciLexerPerl.QuotedStringQW, 79 QsciLexerPerl.QuotedStringQX, 80 QsciLexerPerl.SingleQuotedHereDocument, 81 QsciLexerPerl.SingleQuotedString] 82 83 def defaultKeywords(self, kwSet): 84 """ 85 Public method to get the default keywords. 86 87 @param kwSet number of the keyword set (integer) 88 @return string giving the keywords (string) or None 89 """ 90 return QsciLexerPerl.keywords(self, kwSet) 91