|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2008 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a Pascal lexer with some additional methods. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.Qsci import QsciLexerPascal |
|
13 |
|
14 from .Lexer import Lexer |
|
15 import Preferences |
|
16 |
|
17 |
|
18 class LexerPascal(Lexer, QsciLexerPascal): |
|
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 QsciLexerPascal.__init__(self, parent) |
|
29 Lexer.__init__(self) |
|
30 |
|
31 self.commentString = "//" |
|
32 self.streamCommentString = { |
|
33 'start': '{ ', |
|
34 'end': ' }' |
|
35 } |
|
36 |
|
37 self.keywordSetDescriptions = [ |
|
38 self.tr("Keywords"), |
|
39 ] |
|
40 |
|
41 def initProperties(self): |
|
42 """ |
|
43 Public slot to initialize the properties. |
|
44 """ |
|
45 self.setFoldComments(Preferences.getEditor("PascalFoldComment")) |
|
46 self.setFoldPreprocessor( |
|
47 Preferences.getEditor("PascalFoldPreprocessor")) |
|
48 self.setFoldCompact(Preferences.getEditor("AllFoldCompact")) |
|
49 try: |
|
50 self.setSmartHighlighting( |
|
51 Preferences.getEditor("PascalSmartHighlighting")) |
|
52 except AttributeError: |
|
53 pass |
|
54 |
|
55 def autoCompletionWordSeparators(self): |
|
56 """ |
|
57 Public method to return the list of separators for autocompletion. |
|
58 |
|
59 @return list of separators (list of strings) |
|
60 """ |
|
61 return ['.'] |
|
62 |
|
63 def isCommentStyle(self, style): |
|
64 """ |
|
65 Public method to check, if a style is a comment style. |
|
66 |
|
67 @param style style to check (integer) |
|
68 @return flag indicating a comment style (boolean) |
|
69 """ |
|
70 try: |
|
71 return style in [QsciLexerPascal.Comment, |
|
72 QsciLexerPascal.CommentDoc, |
|
73 QsciLexerPascal.CommentLine] |
|
74 except AttributeError: |
|
75 return style in [QsciLexerPascal.Comment, |
|
76 QsciLexerPascal.CommentParenthesis, |
|
77 QsciLexerPascal.CommentLine] |
|
78 |
|
79 def isStringStyle(self, style): |
|
80 """ |
|
81 Public method to check, if a style is a string style. |
|
82 |
|
83 @param style style to check (integer) |
|
84 @return flag indicating a string style (boolean) |
|
85 """ |
|
86 return style in [QsciLexerPascal.SingleQuotedString] |
|
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 QsciLexerPascal.keywords(self, kwSet) |