|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2002 - 2009 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a CPP lexer with some additional methods. |
|
8 """ |
|
9 |
|
10 from PyQt4.Qsci import QsciLexerCPP, QsciScintilla |
|
11 |
|
12 from Lexer import Lexer |
|
13 import Preferences |
|
14 |
|
15 class LexerCPP(QsciLexerCPP, Lexer): |
|
16 """ |
|
17 Subclass to implement some additional lexer dependant methods. |
|
18 """ |
|
19 def __init__(self, parent=None, caseInsensitiveKeywords = False): |
|
20 """ |
|
21 Constructor |
|
22 |
|
23 @param parent parent widget of this lexer |
|
24 """ |
|
25 QsciLexerCPP.__init__(self, parent, caseInsensitiveKeywords) |
|
26 Lexer.__init__(self) |
|
27 |
|
28 self.commentString = "//" |
|
29 self.streamCommentString = { |
|
30 'start' : '/* ', |
|
31 'end' : ' */' |
|
32 } |
|
33 self.boxCommentString = { |
|
34 'start' : '/* ', |
|
35 'middle' : ' * ', |
|
36 'end' : ' */' |
|
37 } |
|
38 |
|
39 def initProperties(self): |
|
40 """ |
|
41 Public slot to initialize the properties. |
|
42 """ |
|
43 self.setFoldComments(Preferences.getEditor("CppFoldComment")) |
|
44 self.setFoldPreprocessor(Preferences.getEditor("CppFoldPreprocessor")) |
|
45 self.setFoldAtElse(Preferences.getEditor("CppFoldAtElse")) |
|
46 indentStyle = 0 |
|
47 if Preferences.getEditor("CppIndentOpeningBrace"): |
|
48 indentStyle |= QsciScintilla.AiOpening |
|
49 if Preferences.getEditor("CppIndentClosingBrace"): |
|
50 indentStyle |= QsciScintilla.AiClosing |
|
51 self.setAutoIndentStyle(indentStyle) |
|
52 self.setFoldCompact(Preferences.getEditor("AllFoldCompact")) |
|
53 try: |
|
54 self.setDollarsAllowed(Preferences.getEditor("CppDollarsAllowed")) |
|
55 except AttributeError: |
|
56 pass |
|
57 |
|
58 def autoCompletionWordSeparators(self): |
|
59 """ |
|
60 Public method to return the list of separators for autocompletion. |
|
61 |
|
62 @return list of separators (list of strings) |
|
63 """ |
|
64 return ['::', '->', '.'] |
|
65 |
|
66 def isCommentStyle(self, style): |
|
67 """ |
|
68 Public method to check, if a style is a comment style. |
|
69 |
|
70 @return flag indicating a comment style (boolean) |
|
71 """ |
|
72 return style in [QsciLexerCPP.Comment, |
|
73 QsciLexerCPP.CommentDoc, |
|
74 QsciLexerCPP.CommentLine, |
|
75 QsciLexerCPP.CommentLineDoc] |
|
76 |
|
77 def isStringStyle(self, style): |
|
78 """ |
|
79 Public method to check, if a style is a string style. |
|
80 |
|
81 @return flag indicating a string style (boolean) |
|
82 """ |
|
83 return style in [QsciLexerCPP.DoubleQuotedString, |
|
84 QsciLexerCPP.SingleQuotedString, |
|
85 QsciLexerCPP.UnclosedString, |
|
86 QsciLexerCPP.VerbatimString] |