|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2014 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a CoffeeScript lexer with some additional methods. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.Qsci import QsciLexerCoffeeScript |
|
13 |
|
14 from .Lexer import Lexer |
|
15 import Preferences |
|
16 |
|
17 |
|
18 class LexerCoffeeScript(Lexer, QsciLexerCoffeeScript): |
|
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 QsciLexerCoffeeScript.__init__(self, parent) |
|
29 Lexer.__init__(self) |
|
30 |
|
31 self.commentString = "#" |
|
32 self.streamCommentString = { |
|
33 'start': '###\n', |
|
34 'end': '\n###' |
|
35 } |
|
36 |
|
37 self.keywordSetDescriptions = [ |
|
38 self.tr("Keywords"), |
|
39 self.tr("Secondary keywords"), |
|
40 self.tr("Unused"), |
|
41 self.tr("Global classes"), |
|
42 ] |
|
43 |
|
44 def initProperties(self): |
|
45 """ |
|
46 Public slot to initialize the properties. |
|
47 """ |
|
48 self.setDollarsAllowed( |
|
49 Preferences.getEditor("CoffeeScriptDollarsAllowed")) |
|
50 self.setFoldComments( |
|
51 Preferences.getEditor("CoffeScriptFoldComment")) |
|
52 self.setStylePreprocessor( |
|
53 Preferences.getEditor("CoffeeScriptStylePreprocessor")) |
|
54 self.setFoldCompact( |
|
55 Preferences.getEditor("AllFoldCompact")) |
|
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 [QsciLexerCoffeeScript.Comment, |
|
65 QsciLexerCoffeeScript.CommentDoc, |
|
66 QsciLexerCoffeeScript.CommentLine, |
|
67 QsciLexerCoffeeScript.CommentLineDoc, |
|
68 QsciLexerCoffeeScript.CommentBlock, |
|
69 QsciLexerCoffeeScript.BlockRegexComment] |
|
70 |
|
71 def isStringStyle(self, style): |
|
72 """ |
|
73 Public method to check, if a style is a string style. |
|
74 |
|
75 @param style style to check (integer) |
|
76 @return flag indicating a string style (boolean) |
|
77 """ |
|
78 return style in [QsciLexerCoffeeScript.DoubleQuotedString, |
|
79 QsciLexerCoffeeScript.SingleQuotedString, |
|
80 QsciLexerCoffeeScript.UnclosedString, |
|
81 QsciLexerCoffeeScript.VerbatimString] |
|
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 QsciLexerCoffeeScript.keywords(self, kwSet) |
|
91 |
|
92 def maximumKeywordSet(self): |
|
93 """ |
|
94 Public method to get the maximum keyword set. |
|
95 |
|
96 @return maximum keyword set (integer) |
|
97 """ |
|
98 return 4 |