1# -*- coding: utf-8 -*-
2
3# Copyright (c) 2008 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4#
5
6"""
7Module implementing a YAML lexer with some additional methods.
8"""
9
10from PyQt5.Qsci import QsciLexerYAML
11
12from .Lexer import Lexer
13import Preferences
14
15
16class LexerYAML(Lexer, QsciLexerYAML):
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        QsciLexerYAML.__init__(self, parent)
27        Lexer.__init__(self)
28
29        self.commentString = "#"
30
31        self.keywordSetDescriptions = [
32            self.tr("Keywords"),
33        ]
34
35    def initProperties(self):
36        """
37        Public slot to initialize the properties.
38        """
39        self.setFoldComments(Preferences.getEditor("YAMLFoldComment"))
40
41    def isCommentStyle(self, style):
42        """
43        Public method to check, if a style is a comment style.
44
45        @param style style to check (integer)
46        @return flag indicating a comment style (boolean)
47        """
48        return style in [QsciLexerYAML.Comment]
49
50    def isStringStyle(self, style):
51        """
52        Public method to check, if a style is a string style.
53
54        @param style style to check (integer)
55        @return flag indicating a string style (boolean)
56        """
57        return False
58
59    def defaultKeywords(self, kwSet):
60        """
61        Public method to get the default keywords.
62
63        @param kwSet number of the keyword set (integer)
64        @return string giving the keywords (string) or None
65        """
66        return QsciLexerYAML.keywords(self, kwSet)
67