|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2005 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a Lua lexer with some additional methods. |
|
8 """ |
|
9 |
|
10 from PyQt6.Qsci import QsciLexerLua |
|
11 |
|
12 from .Lexer import Lexer |
|
13 import Preferences |
|
14 |
|
15 |
|
16 class LexerLua(Lexer, QsciLexerLua): |
|
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 QsciLexerLua.__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("Keywords"), |
|
37 self.tr("Basic functions"), |
|
38 self.tr("String, (table) & math functions"), |
|
39 self.tr("Coroutines, I/O & system facilities"), |
|
40 self.tr("User defined 1"), |
|
41 self.tr("User defined 2"), |
|
42 self.tr("User defined 3"), |
|
43 self.tr("User defined 4"), |
|
44 ] |
|
45 |
|
46 def initProperties(self): |
|
47 """ |
|
48 Public slot to initialize the properties. |
|
49 """ |
|
50 self.setFoldCompact(Preferences.getEditor("AllFoldCompact")) |
|
51 |
|
52 def autoCompletionWordSeparators(self): |
|
53 """ |
|
54 Public method to return the list of separators for autocompletion. |
|
55 |
|
56 @return list of separators (list of strings) |
|
57 """ |
|
58 return [':', '.'] |
|
59 |
|
60 def isCommentStyle(self, style): |
|
61 """ |
|
62 Public method to check, if a style is a comment style. |
|
63 |
|
64 @param style style to check (integer) |
|
65 @return flag indicating a comment style (boolean) |
|
66 """ |
|
67 return style in [QsciLexerLua.Comment, |
|
68 QsciLexerLua.LineComment] |
|
69 |
|
70 def isStringStyle(self, style): |
|
71 """ |
|
72 Public method to check, if a style is a string style. |
|
73 |
|
74 @param style style to check (integer) |
|
75 @return flag indicating a string style (boolean) |
|
76 """ |
|
77 return style in [QsciLexerLua.String, |
|
78 QsciLexerLua.LiteralString, |
|
79 QsciLexerLua.UnclosedString] |
|
80 |
|
81 def defaultKeywords(self, kwSet): |
|
82 """ |
|
83 Public method to get the default keywords. |
|
84 |
|
85 @param kwSet number of the keyword set (integer) |
|
86 @return string giving the keywords (string) or None |
|
87 """ |
|
88 return QsciLexerLua.keywords(self, kwSet) |
|
89 |
|
90 def maximumKeywordSet(self): |
|
91 """ |
|
92 Public method to get the maximum keyword set. |
|
93 |
|
94 @return maximum keyword set (integer) |
|
95 """ |
|
96 return 8 |