1# -*- coding: utf-8 -*- 2 3# Copyright (c) 2017 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> 4# 5 6""" 7Module implementing a JSON lexer with some additional methods. 8""" 9 10from PyQt5.Qsci import QsciLexerJSON 11 12from .Lexer import Lexer 13import Preferences 14 15 16class LexerJSON(Lexer, QsciLexerJSON): 17 """ 18 Subclass to implement some additional lexer dependent methods. 19 """ 20 def __init__(self, parent=None): 21 """ 22 Constructor 23 24 @param parent parent widget of this lexer 25 """ 26 QsciLexerJSON.__init__(self, parent) 27 Lexer.__init__(self) 28 29 self.commentString = "//" 30 self.streamCommentString = { 31 'start': '/* ', 32 'end': ' */' 33 } 34 35 self.keywordSetDescriptions = [ 36 self.tr("JSON Keywords"), 37 self.tr("JSON-LD Keywords"), 38 ] 39 40 def initProperties(self): 41 """ 42 Public slot to initialize the properties. 43 """ 44 self.setHighlightComments( 45 Preferences.getEditor("JSONHightlightComments")) 46 self.setHighlightEscapeSequences( 47 Preferences.getEditor("JSONHighlightEscapeSequences")) 48 self.setFoldCompact( 49 Preferences.getEditor("AllFoldCompact")) 50 51 def isCommentStyle(self, style): 52 """ 53 Public method to check, if a style is a comment style. 54 55 @param style style to check (integer) 56 @return flag indicating a comment style (boolean) 57 """ 58 return style in [QsciLexerJSON.CommentLine, 59 QsciLexerJSON.CommentBlock] 60 61 def isStringStyle(self, style): 62 """ 63 Public method to check, if a style is a string style. 64 65 @param style style to check (integer) 66 @return flag indicating a string style (boolean) 67 """ 68 return style in [QsciLexerJSON.String, 69 QsciLexerJSON.UnclosedString] 70 71 def defaultKeywords(self, kwSet): 72 """ 73 Public method to get the default keywords. 74 75 @param kwSet number of the keyword set (integer) 76 @return string giving the keywords (string) or None 77 """ 78 return QsciLexerJSON.keywords(self, kwSet) 79 80 def maximumKeywordSet(self): 81 """ 82 Public method to get the maximum keyword set. 83 84 @return maximum keyword set (integer) 85 """ 86 return 2 87