qscilexerjavascript.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // This module implements the QsciLexerJavaScript 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. #include "Qsci/qscilexerjavascript.h"
  20. #include <qcolor.h>
  21. #include <qfont.h>
  22. // The list of JavaScript keywords that can be used by other friendly lexers.
  23. const char *QsciLexerJavaScript::keywordClass =
  24. "abstract boolean break byte case catch char class const continue "
  25. "debugger default delete do double else enum export extends final "
  26. "finally float for function goto if implements import in instanceof "
  27. "int interface long native new package private protected public "
  28. "return short static super switch synchronized this throw throws "
  29. "transient try typeof var void volatile while with";
  30. // The ctor.
  31. QsciLexerJavaScript::QsciLexerJavaScript(QObject *parent)
  32. : QsciLexerCPP(parent)
  33. {
  34. }
  35. // The dtor.
  36. QsciLexerJavaScript::~QsciLexerJavaScript()
  37. {
  38. }
  39. // Returns the language name.
  40. const char *QsciLexerJavaScript::language() const
  41. {
  42. return "JavaScript";
  43. }
  44. // Returns the foreground colour of the text for a style.
  45. QColor QsciLexerJavaScript::defaultColor(int style) const
  46. {
  47. if (style == Regex)
  48. return QColor(0x3f,0x7f,0x3f);
  49. return QsciLexerCPP::defaultColor(style);
  50. }
  51. // Returns the end-of-line fill for a style.
  52. bool QsciLexerJavaScript::defaultEolFill(int style) const
  53. {
  54. if (style == Regex)
  55. return true;
  56. return QsciLexerCPP::defaultEolFill(style);
  57. }
  58. // Returns the font of the text for a style.
  59. QFont QsciLexerJavaScript::defaultFont(int style) const
  60. {
  61. if (style == Regex)
  62. #if defined(Q_OS_WIN)
  63. return QFont("Courier New",10);
  64. #elif defined(Q_OS_MAC)
  65. return QFont("Courier", 12);
  66. #else
  67. return QFont("Bitstream Vera Sans Mono",9);
  68. #endif
  69. return QsciLexerCPP::defaultFont(style);
  70. }
  71. // Returns the set of keywords.
  72. const char *QsciLexerJavaScript::keywords(int set) const
  73. {
  74. if (set != 1)
  75. return 0;
  76. return keywordClass;
  77. }
  78. // Returns the user name of a style.
  79. QString QsciLexerJavaScript::description(int style) const
  80. {
  81. if (style == Regex)
  82. return tr("Regular expression");
  83. return QsciLexerCPP::description(style);
  84. }
  85. // Returns the background colour of the text for a style.
  86. QColor QsciLexerJavaScript::defaultPaper(int style) const
  87. {
  88. if (style == Regex)
  89. return QColor(0xe0,0xf0,0xff);
  90. return QsciLexer::defaultPaper(style);
  91. }