qscilexerspice.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. // This module implements the QsciLexerSpice 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/qscilexerspice.h"
  20. #include <qcolor.h>
  21. #include <qfont.h>
  22. // The ctor.
  23. QsciLexerSpice::QsciLexerSpice(QObject *parent)
  24. : QsciLexer(parent)
  25. {
  26. }
  27. // The dtor.
  28. QsciLexerSpice::~QsciLexerSpice()
  29. {
  30. }
  31. // Returns the language name.
  32. const char *QsciLexerSpice::language() const
  33. {
  34. return "Spice";
  35. }
  36. // Returns the lexer name.
  37. const char *QsciLexerSpice::lexer() const
  38. {
  39. return "spice";
  40. }
  41. // Return the style used for braces.
  42. int QsciLexerSpice::braceStyle() const
  43. {
  44. return Parameter;
  45. }
  46. // Returns the set of keywords.
  47. const char *QsciLexerSpice::keywords(int set) const
  48. {
  49. if (set == 1)
  50. return
  51. "ac alias alter alterparam append askvalues assertvalid "
  52. "autoscale break compose copy copytodoc dc delete destroy "
  53. "destroyvec diff display disto dowhile echo else end errorstop "
  54. "fftinit filter foreach fourier freqtotime function "
  55. "functionundef goto homecursors if isdisplayed label let "
  56. "linearize listing load loadaccumulator makelabel movelabel "
  57. "makesmithplot movecursorleft movecursorright msgbox nameplot "
  58. "newplot nextparam noise nopoints op plot plotf plotref poly "
  59. "print printcursors printevent printname printplot printstatus "
  60. "printtext printtol printunits printval printvector pwl pz quit "
  61. "removesmithplot rename repeat resume rotate runs rusage save "
  62. "sendplot sendscript sens set setcursor setdoc setlabel "
  63. "setlabeltype setmargins setnthtrigger setunits setvec setparam "
  64. "setplot setquery setscaletype settracecolor settracestyle "
  65. "setsource settrigger setvec setxlimits setylimits show showmod "
  66. "sort status step stop switch tf timetofreq timetowave tran "
  67. "unalias unlet unset unalterparam update version view wavefilter "
  68. "wavetotime where while write";
  69. if (set == 2)
  70. return
  71. "abs askvalue atan average ceil cos db differentiate "
  72. "differentiatex exp finalvalue floor getcursorx getcursory "
  73. "getcursory0 getcursory1 getparam im ln initialvalue integrate "
  74. "integratex interpolate isdef isdisplayed j log length mag max "
  75. "maxscale mean meanpts min minscale nextplot nextvector norm "
  76. "operatingpoint ph phase phaseextend pk_pk pos pulse re rms "
  77. "rmspts rnd sameplot sin sqrt stddev stddevpts tan tfall "
  78. "tolerance trise unitvec vector";
  79. if (set == 3)
  80. return "param nodeset include options dcconv subckt ends model";
  81. return 0;
  82. }
  83. // Returns the foreground colour of the text for a style.
  84. QColor QsciLexerSpice::defaultColor(int style) const
  85. {
  86. switch (style)
  87. {
  88. case Default:
  89. return QColor(0x80,0x80,0x80);
  90. case Command:
  91. case Function:
  92. return QColor(0x00,0x00,0x7f);
  93. case Parameter:
  94. return QColor(0x00,0x40,0xe0);
  95. case Number:
  96. return QColor(0x00,0x7f,0x7f);
  97. case Delimiter:
  98. return QColor(0x00,0x00,0x00);
  99. case Value:
  100. return QColor(0x7f,0x00,0x7f);
  101. case Comment:
  102. return QColor(0x00,0x7f,0x00);
  103. }
  104. return QsciLexer::defaultColor(style);
  105. }
  106. // Returns the font of the text for a style.
  107. QFont QsciLexerSpice::defaultFont(int style) const
  108. {
  109. QFont f;
  110. if (style == Comment)
  111. #if defined(Q_OS_WIN)
  112. f = QFont("Comic Sans MS",9);
  113. #elif defined(Q_OS_MAC)
  114. f = QFont("Comic Sans MS", 12);
  115. #else
  116. f = QFont("Bitstream Vera Serif",9);
  117. #endif
  118. else
  119. {
  120. f = QsciLexer::defaultFont(style);
  121. if (style == Function || style == Delimiter)
  122. f.setBold(true);
  123. }
  124. return f;
  125. }
  126. // Returns the user name of a style.
  127. QString QsciLexerSpice::description(int style) const
  128. {
  129. switch (style)
  130. {
  131. case Default:
  132. return tr("Default");
  133. case Identifier:
  134. return tr("Identifier");
  135. case Command:
  136. return tr("Command");
  137. case Function:
  138. return tr("Function");
  139. case Parameter:
  140. return tr("Parameter");
  141. case Number:
  142. return tr("Number");
  143. case Delimiter:
  144. return tr("Delimiter");
  145. case Value:
  146. return tr("Value");
  147. case Comment:
  148. return tr("Comment");
  149. }
  150. return QString();
  151. }