1# -*- coding: utf-8 -*- 2 3# Copyright (c) 2002 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> 4# 5 6""" 7Module implementing an IDL lexer with some additional methods. 8""" 9 10from PyQt5.Qsci import QsciLexerIDL, QsciScintilla 11 12from .Lexer import Lexer 13import Preferences 14 15 16class LexerIDL(Lexer, QsciLexerIDL): 17 """ 18 Subclass to implement some additional lexer dependant methods. 19 """ 20 def __init__(self, parent=None): 21 """ 22 Constructor 23 24 @param parent parent widget of this lexer 25 """ 26 QsciLexerIDL.__init__(self, parent) 27 Lexer.__init__(self) 28 29 self.commentString = "//" 30 self.streamCommentString = { 31 'start': '/* ', 32 'end': ' */' 33 } 34 self.boxCommentString = { 35 'start': '/* ', 36 'middle': ' * ', 37 'end': ' */' 38 } 39 40 self.keywordSetDescriptions = [ 41 self.tr("Primary keywords and identifiers"), 42 self.tr("Secondary keywords and identifiers"), 43 self.tr("Documentation comment keywords"), 44 self.tr("Global classes and typedefs"), 45 self.tr("Preprocessor definitions"), 46 self.tr("Task marker and error marker keywords"), 47 ] 48 49 def initProperties(self): 50 """ 51 Public slot to initialize the properties. 52 """ 53 self.setFoldComments(Preferences.getEditor("CppFoldComment")) 54 self.setFoldPreprocessor(Preferences.getEditor("CppFoldPreprocessor")) 55 self.setFoldAtElse(Preferences.getEditor("CppFoldAtElse")) 56 indentStyle = 0 57 if Preferences.getEditor("CppIndentOpeningBrace"): 58 indentStyle |= QsciScintilla.AiOpening 59 if Preferences.getEditor("CppIndentClosingBrace"): 60 indentStyle |= QsciScintilla.AiClosing 61 self.setAutoIndentStyle(indentStyle) 62 self.setFoldCompact(Preferences.getEditor("AllFoldCompact")) 63 64 def isCommentStyle(self, style): 65 """ 66 Public method to check, if a style is a comment style. 67 68 @param style style to check (integer) 69 @return flag indicating a comment style (boolean) 70 """ 71 return style in [QsciLexerIDL.Comment, 72 QsciLexerIDL.CommentDoc, 73 QsciLexerIDL.CommentLine, 74 QsciLexerIDL.CommentLineDoc] 75 76 def isStringStyle(self, style): 77 """ 78 Public method to check, if a style is a string style. 79 80 @param style style to check (integer) 81 @return flag indicating a string style (boolean) 82 """ 83 return style in [QsciLexerIDL.DoubleQuotedString, 84 QsciLexerIDL.SingleQuotedString, 85 QsciLexerIDL.UnclosedString, 86 QsciLexerIDL.VerbatimString] 87 88 def defaultKeywords(self, kwSet): 89 """ 90 Public method to get the default keywords. 91 92 @param kwSet number of the keyword set (integer) 93 @return string giving the keywords (string) or None 94 """ 95 return QsciLexerIDL.keywords(self, kwSet) 96 97 def maximumKeywordSet(self): 98 """ 99 Public method to get the maximum keyword set. 100 101 @return maximum keyword set (integer) 102 """ 103 return 4 104