aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <unknown>2003-03-17 09:07:24 +0000
committernyamatongwe <unknown>2003-03-17 09:07:24 +0000
commit19f22fc977ccb6c5b2a802ddb1fa1d63bdf0c37e (patch)
tree2dd6caae32c28b230a5e02850ef3c7d544dbf896
parent7c0fd4b35c851e39842b9187a62ce785cdcab605 (diff)
downloadscintilla-mirror-19f22fc977ccb6c5b2a802ddb1fa1d63bdf0c37e.tar.gz
Added POV-Ray lexer by Steven te Brinke.
-rw-r--r--gtk/makefile4
-rw-r--r--gtk/scintilla.mak3
-rw-r--r--include/SciLexer.h12
-rw-r--r--include/Scintilla.iface15
-rw-r--r--src/KeyWords.cxx1
-rw-r--r--src/LexPOV.cxx222
-rw-r--r--win32/makefile4
-rw-r--r--win32/scintilla.mak3
-rw-r--r--win32/scintilla_vc6.mak3
9 files changed, 262 insertions, 5 deletions
diff --git a/gtk/makefile b/gtk/makefile
index 95105514b..19e64ca9e 100644
--- a/gtk/makefile
+++ b/gtk/makefile
@@ -44,8 +44,8 @@ endif
LEXOBJS=\
LexAda.o LexAsm.o LexAVE.o LexBaan.o LexBullant.o LexConf.o LexCPP.o \
LexCrontab.o LexCSS.o LexEiffel.o LexFortran.o LexHTML.o LexLisp.o LexLua.o \
-LexMatlab.o LexOthers.o LexPascal.o LexPerl.o LexPython.o LexRuby.o LexSQL.o \
-LexVB.o
+LexMatlab.o LexOthers.o LexPascal.o LexPerl.o LexPOV.o LexPython.o LexRuby.o \
+LexSQL.o LexVB.o
#--Autogenerated -- end of automatically generated section
# The LEXOBJS have to be treated specially as the functions in them are not called from external code
diff --git a/gtk/scintilla.mak b/gtk/scintilla.mak
index 5d80cfdb8..b851173d8 100644
--- a/gtk/scintilla.mak
+++ b/gtk/scintilla.mak
@@ -137,6 +137,7 @@ LEXOBJS=\
$(DIR_O)\LexOthers.obj \
$(DIR_O)\LexPascal.obj \
$(DIR_O)\LexPerl.obj \
+ $(DIR_O)\LexPOV.obj \
$(DIR_O)\LexPython.obj \
$(DIR_O)\LexRuby.obj \
$(DIR_O)\LexSQL.obj \
@@ -286,6 +287,8 @@ $(DIR_O)\LexPascal.obj: ..\src\LexPascal.cxx $(LEX_HEADERS)
$(DIR_O)\LexPerl.obj: ..\src\LexPerl.cxx $(LEX_HEADERS)
+$(DIR_O)\LexPOV.obj: ..\src\LexPOV.cxx $(LEX_HEADERS)
+
$(DIR_O)\LexPython.obj: ..\src\LexPython.cxx $(LEX_HEADERS)
$(DIR_O)\LexRuby.obj: ..\src\LexRuby.cxx $(LEX_HEADERS)
diff --git a/include/SciLexer.h b/include/SciLexer.h
index 5e4ad6c34..e1da492b2 100644
--- a/include/SciLexer.h
+++ b/include/SciLexer.h
@@ -53,6 +53,7 @@
#define SCLEX_FORTRAN 36
#define SCLEX_F77 37
#define SCLEX_CSS 38
+#define SCLEX_POV 39
#define SCLEX_AUTOMATIC 1000
#define SCE_P_DEFAULT 0
#define SCE_P_COMMENTLINE 1
@@ -448,6 +449,17 @@
#define SCE_CSS_DIRECTIVE 12
#define SCE_CSS_DOUBLESTRING 13
#define SCE_CSS_SINGLESTRING 14
+#define SCE_POV_DEFAULT 0
+#define SCE_POV_COMMENT 1
+#define SCE_POV_COMMENTLINE 2
+#define SCE_POV_COMMENTDOC 3
+#define SCE_POV_NUMBER 4
+#define SCE_POV_WORD 5
+#define SCE_POV_STRING 6
+#define SCE_POV_OPERATOR 7
+#define SCE_POV_IDENTIFIER 8
+#define SCE_POV_BRACE 9
+#define SCE_POV_WORD2 10
//--Autogenerated -- end of section automatically generated from Scintilla.iface
#endif
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index bcd10f9b1..dcd5711a9 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -1544,6 +1544,7 @@ val SCLEX_CPPNOCASE=35
val SCLEX_FORTRAN=36
val SCLEX_F77=37
val SCLEX_CSS=38
+val SCLEX_POV=39
# When a lexer specifies its language as SCLEX_AUTOMATIC it receives a
# value assigned in sequence from SCLEX_AUTOMATIC+1.
@@ -2012,7 +2013,19 @@ val SCE_CSS_IMPORTANT=11
val SCE_CSS_DIRECTIVE=12
val SCE_CSS_DOUBLESTRING=13
val SCE_CSS_SINGLESTRING=14
-
+# Lexical states for SCLEX_POV
+lex POV=SCLEX_POV SCE_POV_
+val SCE_POV_DEFAULT=0
+val SCE_POV_COMMENT=1
+val SCE_POV_COMMENTLINE=2
+val SCE_POV_COMMENTDOC=3
+val SCE_POV_NUMBER=4
+val SCE_POV_WORD=5
+val SCE_POV_STRING=6
+val SCE_POV_OPERATOR=7
+val SCE_POV_IDENTIFIER=8
+val SCE_POV_BRACE=9
+val SCE_POV_WORD2=10
# Events
evt void StyleNeeded=2000(int position)
diff --git a/src/KeyWords.cxx b/src/KeyWords.cxx
index 6183916c6..59b1bdea4 100644
--- a/src/KeyWords.cxx
+++ b/src/KeyWords.cxx
@@ -171,6 +171,7 @@ int Scintilla_LinkLexers() {
LINK_LEXER(lmLatex);
LINK_LEXER(lmPascal);
LINK_LEXER(lmPerl);
+ LINK_LEXER(lmPOV);
LINK_LEXER(lmPython);
LINK_LEXER(lmRuby);
LINK_LEXER(lmSQL);
diff --git a/src/LexPOV.cxx b/src/LexPOV.cxx
new file mode 100644
index 000000000..93f773bdf
--- /dev/null
+++ b/src/LexPOV.cxx
@@ -0,0 +1,222 @@
+// Scintilla source code edit control
+/** @file LexPOV.cxx
+ ** Lexer for POV-Ray, based on lexer for C++.
+ **/
+// Copyright 2003 by Steven te Brinke <steven.t.b@zonnet.nl>
+// The License.txt file describes the conditions under which this software may be distributed.
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "Platform.h"
+
+#include "PropSet.h"
+#include "Accessor.h"
+#include "StyleContext.h"
+#include "KeyWords.h"
+#include "Scintilla.h"
+#include "SciLexer.h"
+
+#define KEYWORD_BOXHEADER 1
+#define KEYWORD_FOLDCONTRACTED 2
+
+static inline bool IsAWordChar(const int ch) {
+ return (ch < 0x80) && (isalnum(ch) || ch == '.' || ch == '_');
+}
+
+static inline bool IsAWordStart(const int ch) {
+ return (ch < 0x80) && (isalnum(ch) || ch == '_');
+}
+
+static inline bool IsStateComment(const int state) {
+ return ((state == SCE_POV_COMMENT) ||
+ (state == SCE_POV_COMMENTLINE) ||
+ (state == SCE_POV_COMMENTDOC));
+}
+
+static inline bool IsStateString(const int state) {
+ return ((state == SCE_POV_STRING));
+}
+
+static void ColourisePOVDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
+ Accessor &styler) {
+
+ WordList &keywords = *keywordlists[0];
+ WordList &keywords2 = *keywordlists[1];
+
+ // Do not leak onto next line
+ /*if (initStyle == SCE_POV_STRINGEOL)
+ initStyle = SCE_POV_DEFAULT;*/
+
+ StyleContext sc(startPos, length, initStyle, styler);
+
+ bool caseSensitive = styler.GetPropertyInt("case.sensitive", 1) != 0;
+
+ for (; sc.More(); sc.Forward()) {
+
+ /*if (sc.atLineStart && (sc.state == SCE_POV_STRING)) {
+ // Prevent SCE_POV_STRINGEOL from leaking back to previous line
+ sc.SetState(SCE_POV_STRING);
+ }*/
+
+ // Handle line continuation generically.
+ if (sc.ch == '\\') {
+ if (sc.chNext == '\n' || sc.chNext == '\r') {
+ sc.Forward();
+ if (sc.ch == '\r' && sc.chNext == '\n') {
+ sc.Forward();
+ }
+ continue;
+ }
+ }
+
+ // Determine if the current state should terminate.
+ if (sc.state == SCE_POV_OPERATOR || sc.state == SCE_POV_BRACE) {
+ sc.SetState(SCE_POV_DEFAULT);
+ } else if (sc.state == SCE_POV_NUMBER) {
+ if (!IsADigit(sc.ch) || sc.ch != '.') {
+ sc.SetState(SCE_POV_DEFAULT);
+ }
+ } else if (sc.state == SCE_POV_IDENTIFIER) {
+ if (!IsAWordChar(sc.ch) || (sc.ch == '.')) {
+ char s[100];
+ if (caseSensitive) {
+ sc.GetCurrent(s, sizeof(s));
+ } else {
+ sc.GetCurrentLowered(s, sizeof(s));
+ }
+ if (keywords.InList(s)) {
+ sc.ChangeState(SCE_POV_WORD);
+ } else if (keywords2.InList(s)) {
+ sc.ChangeState(SCE_POV_WORD2);
+ }
+ sc.SetState(SCE_POV_DEFAULT);
+ }
+ } else if (sc.state == SCE_POV_COMMENT) {
+ if (sc.Match('*', '/')) {
+ sc.Forward();
+ sc.ForwardSetState(SCE_POV_DEFAULT);
+ }
+ } else if (sc.state == SCE_POV_COMMENTDOC) {
+ if (sc.Match('*', '/')) {
+ sc.Forward();
+ sc.ForwardSetState(SCE_POV_DEFAULT);
+ }
+ } else if (sc.state == SCE_POV_COMMENTLINE) {
+ if (sc.atLineEnd) {
+ sc.SetState(SCE_POV_DEFAULT);
+ }
+ } else if (sc.state == SCE_POV_STRING) {
+ if (sc.ch == '\\') {
+ if (sc.chNext == '\"' || sc.chNext == '\\') {
+ sc.Forward();
+ }
+ } else if (sc.ch == '\"') {
+ sc.ForwardSetState(SCE_POV_DEFAULT);
+ }
+ }
+
+ // Determine if a new state should be entered.
+ if (sc.state == SCE_POV_DEFAULT) {
+ if (IsADigit(sc.ch) || (sc.ch == '.' && IsADigit(sc.chNext))) {
+ sc.SetState(SCE_POV_NUMBER);
+ } else if (IsAWordStart(sc.ch) || (sc.ch == '#')) {
+ sc.SetState(SCE_POV_IDENTIFIER);
+ } else if (sc.Match('/', '*')) {
+ sc.SetState(SCE_POV_COMMENT);
+ sc.Forward(); // Eat the * so it isn't used for the end of the comment
+ } else if (sc.Match('/', '/')) {
+ sc.SetState(SCE_POV_COMMENTLINE);
+ } else if (sc.ch == '\"') {
+ sc.SetState(SCE_POV_STRING);
+ //} else if (isoperator(static_cast<char>(sc.ch))) {
+ } else if (sc.ch == '+' || sc.ch == '-' || sc.ch == '*' || sc.ch == '/' || sc.ch == '=' || sc.ch == '<' || sc.ch == '>' || sc.ch == '&' || sc.ch == '|' || sc.ch == '!' || sc.ch == '?' || sc.ch == ':') {
+ sc.SetState(SCE_POV_OPERATOR);
+ } else if (sc.ch == '{' || sc.ch == '}') {
+ sc.SetState(SCE_POV_BRACE);
+ }
+ }
+
+ }
+ sc.Complete();
+}
+
+static bool IsStreamCommentStyle(int style) {
+ return style == SCE_POV_COMMENT ||
+ style == SCE_POV_COMMENTDOC;
+}
+
+static void FoldNoBoxPOVDoc(unsigned int startPos, int length, int initStyle,
+ Accessor &styler) {
+ bool foldComment = styler.GetPropertyInt("fold.comment", 1) != 0;
+ bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
+ unsigned int endPos = startPos + length;
+ int visibleChars = 0;
+ int lineCurrent = styler.GetLine(startPos);
+ int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
+ int levelCurrent = levelPrev;
+ char chNext = styler[startPos];
+ int styleNext = styler.StyleAt(startPos);
+ int style = initStyle;
+ for (unsigned int i = startPos; i < endPos; i++) {
+ char ch = chNext;
+ chNext = styler.SafeGetCharAt(i + 1);
+ int stylePrev = style;
+ style = styleNext;
+ styleNext = styler.StyleAt(i + 1);
+ bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');
+ if (foldComment && IsStreamCommentStyle(style)) {
+ if (!IsStreamCommentStyle(stylePrev)) {
+ levelCurrent++;
+ } else if (!IsStreamCommentStyle(styleNext) && !atEOL) {
+ // Comments don't end at end of line and the next character may be unstyled.
+ levelCurrent--;
+ }
+ }
+ if (style == SCE_POV_BRACE) {
+ if (ch == '{') {
+ levelCurrent++;
+ } else if (ch == '}') {
+ levelCurrent--;
+ }
+ }
+ if (atEOL) {
+ int lev = levelPrev;
+ if (visibleChars == 0 && foldCompact)
+ lev |= SC_FOLDLEVELWHITEFLAG;
+ if ((levelCurrent > levelPrev) && (visibleChars > 0))
+ lev |= SC_FOLDLEVELHEADERFLAG;
+ if (lev != styler.LevelAt(lineCurrent)) {
+ styler.SetLevel(lineCurrent, lev);
+ }
+ lineCurrent++;
+ levelPrev = levelCurrent;
+ visibleChars = 0;
+ }
+ if (!isspacechar(ch))
+ visibleChars++;
+ }
+ // Fill in the real level of the next line, keeping the current flags as they will be filled in later
+ int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
+ styler.SetLevel(lineCurrent, levelPrev | flagsNext);
+}
+
+static void FoldPOVDoc(unsigned int startPos, int length, int initStyle, WordList *[], Accessor &styler) {
+ FoldNoBoxPOVDoc(startPos, length, initStyle, styler);
+}
+
+static const char * const POVWordLists[] = {
+ "Primary keywords and identifiers",
+ "Secondary keywords and identifiers",
+ 0,
+ };
+
+static void ColourisePOVDocSensitive(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
+ Accessor &styler) {
+ ColourisePOVDoc(startPos, length, initStyle, keywordlists, styler);
+}
+
+LexerModule lmPOV(SCLEX_POV, ColourisePOVDocSensitive, "pov", FoldPOVDoc, POVWordLists);
diff --git a/win32/makefile b/win32/makefile
index 2205832db..0e9f3564a 100644
--- a/win32/makefile
+++ b/win32/makefile
@@ -44,8 +44,8 @@ deps:
LEXOBJS=\
LexAda.o LexAsm.o LexAVE.o LexBaan.o LexBullant.o LexConf.o LexCPP.o \
LexCrontab.o LexCSS.o LexEiffel.o LexFortran.o LexHTML.o LexLisp.o LexLua.o \
-LexMatlab.o LexOthers.o LexPascal.o LexPerl.o LexPython.o LexRuby.o LexSQL.o \
-LexVB.o
+LexMatlab.o LexOthers.o LexPascal.o LexPerl.o LexPOV.o LexPython.o LexRuby.o \
+LexSQL.o LexVB.o
#--Autogenerated -- end of automatically generated section
SOBJS = ScintillaWin.o ScintillaBase.o Editor.o Document.o \
diff --git a/win32/scintilla.mak b/win32/scintilla.mak
index 754c92293..2865ef725 100644
--- a/win32/scintilla.mak
+++ b/win32/scintilla.mak
@@ -127,6 +127,7 @@ LEXOBJS=\
$(DIR_O)\LexOthers.obj \
$(DIR_O)\LexPascal.obj \
$(DIR_O)\LexPerl.obj \
+ $(DIR_O)\LexPOV.obj \
$(DIR_O)\LexPython.obj \
$(DIR_O)\LexRuby.obj \
$(DIR_O)\LexSQL.obj \
@@ -276,6 +277,8 @@ $(DIR_O)\LexPascal.obj: ..\src\LexPascal.cxx $(LEX_HEADERS)
$(DIR_O)\LexPerl.obj: ..\src\LexPerl.cxx $(LEX_HEADERS)
+$(DIR_O)\LexPOV.obj: ..\src\LexPOV.cxx $(LEX_HEADERS)
+
$(DIR_O)\LexPython.obj: ..\src\LexPython.cxx $(LEX_HEADERS)
$(DIR_O)\LexRuby.obj: ..\src\LexRuby.cxx $(LEX_HEADERS)
diff --git a/win32/scintilla_vc6.mak b/win32/scintilla_vc6.mak
index bcd1c4352..21d367c66 100644
--- a/win32/scintilla_vc6.mak
+++ b/win32/scintilla_vc6.mak
@@ -129,6 +129,7 @@ LEXOBJS=\
$(DIR_O)\LexOthers.obj \
$(DIR_O)\LexPascal.obj \
$(DIR_O)\LexPerl.obj \
+ $(DIR_O)\LexPOV.obj \
$(DIR_O)\LexPython.obj \
$(DIR_O)\LexRuby.obj \
$(DIR_O)\LexSQL.obj \
@@ -278,6 +279,8 @@ $(DIR_O)\LexPascal.obj: ..\src\LexPascal.cxx $(LEX_HEADERS)
$(DIR_O)\LexPerl.obj: ..\src\LexPerl.cxx $(LEX_HEADERS)
+$(DIR_O)\LexPOV.obj: ..\src\LexPOV.cxx $(LEX_HEADERS)
+
$(DIR_O)\LexPython.obj: ..\src\LexPython.cxx $(LEX_HEADERS)
$(DIR_O)\LexRuby.obj: ..\src\LexRuby.cxx $(LEX_HEADERS)