eric7/QScintilla/Lexers/LexerJavaScript.py

branch
eric7
changeset 8312
800c432b34c8
parent 7923
91e843545d9a
child 8318
962bce857696
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2003 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a JavaScript lexer with some additional methods.
8 """
9
10 from PyQt5.Qsci import QsciLexerJavaScript, QsciScintilla
11
12 from .Lexer import Lexer
13 import Preferences
14
15
16 class LexerJavaScript(Lexer, QsciLexerJavaScript):
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 QsciLexerJavaScript.__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 [QsciLexerJavaScript.Comment,
72 QsciLexerJavaScript.CommentDoc,
73 QsciLexerJavaScript.CommentLine,
74 QsciLexerJavaScript.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 [QsciLexerJavaScript.DoubleQuotedString,
84 QsciLexerJavaScript.SingleQuotedString,
85 QsciLexerJavaScript.UnclosedString,
86 QsciLexerJavaScript.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 QsciLexerJavaScript.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

eric ide

mercurial