qscilexerjson.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // This defines the interface to the QsciLexerJSON class.
  2. //
  3. // Copyright (c) 2017 Riverbank Computing Limited <info@riverbankcomputing.com>
  4. //
  5. // This file is part of QScintilla.
  6. //
  7. // This file may be used under the terms of the GNU General Public License
  8. // version 3.0 as published by the Free Software Foundation and appearing in
  9. // the file LICENSE included in the packaging of this file. Please review the
  10. // following information to ensure the GNU General Public License version 3.0
  11. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  12. //
  13. // If you do not wish to use this file under the terms of the GPL version 3.0
  14. // then you may purchase a commercial license. For more information contact
  15. // info@riverbankcomputing.com.
  16. //
  17. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  18. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  19. #ifndef QSCILEXERJSON_H
  20. #define QSCILEXERJSON_H
  21. #include <QObject>
  22. #include <Qsci/qsciglobal.h>
  23. #include <Qsci/qscilexer.h>
  24. //! \brief The QsciLexerJSON class encapsulates the Scintilla JSON lexer.
  25. class QSCINTILLA_EXPORT QsciLexerJSON : public QsciLexer
  26. {
  27. Q_OBJECT
  28. public:
  29. //! This enum defines the meanings of the different styles used by the
  30. //! JSON lexer.
  31. enum {
  32. //! The default.
  33. Default = 0,
  34. //! A number.
  35. Number = 1,
  36. //! A string.
  37. String = 2,
  38. //! An unclosed string.
  39. UnclosedString = 3,
  40. //! A property.
  41. Property = 4,
  42. //! An escape sequence.
  43. EscapeSequence = 5,
  44. //! A line comment.
  45. CommentLine = 6,
  46. //! A block comment.
  47. CommentBlock = 7,
  48. //! An operator.
  49. Operator = 8,
  50. //! An Internationalised Resource Identifier (IRI).
  51. IRI = 9,
  52. //! A JSON-LD compact IRI.
  53. IRICompact = 10,
  54. //! A JSON keyword.
  55. Keyword = 11,
  56. //! A JSON-LD keyword.
  57. KeywordLD = 12,
  58. //! A parsing error.
  59. Error = 13,
  60. };
  61. //! Construct a QsciLexerJSON with parent \a parent. \a parent is
  62. //! typically the QsciScintilla instance.
  63. QsciLexerJSON(QObject *parent = 0);
  64. //! Destroys the QsciLexerJSON instance.
  65. virtual ~QsciLexerJSON();
  66. //! Returns the name of the language.
  67. const char *language() const;
  68. //! Returns the name of the lexer. Some lexers support a number of
  69. //! languages.
  70. const char *lexer() const;
  71. //! Returns the foreground colour of the text for style number \a style.
  72. //!
  73. //! \sa defaultPaper()
  74. QColor defaultColor(int style) const;
  75. //! Returns the end-of-line fill for style number \a style.
  76. bool defaultEolFill(int style) const;
  77. //! Returns the font for style number \a style.
  78. QFont defaultFont(int style) const;
  79. //! Returns the background colour of the text for style number \a style.
  80. //!
  81. //! \sa defaultColor()
  82. QColor defaultPaper(int style) const;
  83. //! Returns the set of keywords for the keyword set \a set recognised
  84. //! by the lexer as a space separated string.
  85. const char *keywords(int set) const;
  86. //! Returns the descriptive name for style number \a style. If the
  87. //! style is invalid for this language then an empty QString is returned.
  88. //! This is intended to be used in user preference dialogs.
  89. QString description(int style) const;
  90. //! Causes all properties to be refreshed by emitting the
  91. //! propertyChanged() signal as required.
  92. void refreshProperties();
  93. //! If \a highlight is true then line and block comments will be
  94. //! highlighted. The default is true.
  95. //!
  96. //! \sa hightlightComments()
  97. void setHighlightComments(bool highlight);
  98. //! Returns true if line and block comments are highlighted
  99. //!
  100. //! \sa setHightlightComments()
  101. bool highlightComments() const {return allow_comments;}
  102. //! If \a highlight is true then escape sequences in strings are
  103. //! highlighted. The default is true.
  104. //!
  105. //! \sa highlightEscapeSequences()
  106. void setHighlightEscapeSequences(bool highlight);
  107. //! Returns true if escape sequences in strings are highlighted.
  108. //!
  109. //! \sa setHighlightEscapeSequences()
  110. bool highlightEscapeSequences() const {return escape_sequence;}
  111. //! If \a fold is true then trailing blank lines are included in a fold
  112. //! block. The default is true.
  113. //!
  114. //! \sa foldCompact()
  115. void setFoldCompact(bool fold);
  116. //! Returns true if trailing blank lines are included in a fold block.
  117. //!
  118. //! \sa setFoldCompact()
  119. bool foldCompact() const {return fold_compact;}
  120. protected:
  121. //! The lexer's properties are read from the settings \a qs. \a prefix
  122. //! (which has a trailing '/') should be used as a prefix to the key of
  123. //! each setting. true is returned if there is no error.
  124. //!
  125. bool readProperties(QSettings &qs,const QString &prefix);
  126. //! The lexer's properties are written to the settings \a qs.
  127. //! \a prefix (which has a trailing '/') should be used as a prefix to
  128. //! the key of each setting. true is returned if there is no error.
  129. //!
  130. bool writeProperties(QSettings &qs,const QString &prefix) const;
  131. private:
  132. void setAllowCommentsProp();
  133. void setEscapeSequenceProp();
  134. void setCompactProp();
  135. bool allow_comments;
  136. bool escape_sequence;
  137. bool fold_compact;
  138. QsciLexerJSON(const QsciLexerJSON &);
  139. QsciLexerJSON &operator=(const QsciLexerJSON &);
  140. };
  141. #endif