updated Scintilla to 2.29
[TortoiseGit.git] / ext / scintilla / lexers / LexSorcus.cxx
blob9a94ce6631fc86236b216082aba153e88b9fe651
1 // Scintilla source code edit control
2 /** @file LexSorcus.cxx
3 ** Lexer for SORCUS installation files
4 ** Written by Eugen Bitter and Christoph Baumann at SORCUS Computer, Heidelberg Germany
5 ** Based on the ASM Lexer by The Black Horus
6 **/
8 // The License.txt file describes the conditions under which this software may be distributed.
10 #include <stdlib.h>
11 #include <string.h>
12 #include <stdio.h>
13 #include <stdarg.h>
14 #include <assert.h>
15 #include <ctype.h>
17 #include "ILexer.h"
18 #include "Scintilla.h"
19 #include "SciLexer.h"
21 #include "WordList.h"
22 #include "LexAccessor.h"
23 #include "Accessor.h"
24 #include "StyleContext.h"
25 #include "CharacterSet.h"
26 #include "LexerModule.h"
28 #ifdef SCI_NAMESPACE
29 using namespace Scintilla;
30 #endif
33 //each character a..z and A..Z + '_' can be part of a keyword
34 //additionally numbers that follow 'M' can be contained in a keyword
35 static inline bool IsSWordStart(const int ch, const int prev_ch)
37 if (isalpha(ch) || (ch == '_') || ((isdigit(ch)) && (prev_ch == 'M')))
38 return true;
40 return false;
44 //only digits that are not preceded by 'M' count as a number
45 static inline bool IsSorcusNumber(const int ch, const int prev_ch)
47 if ((isdigit(ch)) && (prev_ch != 'M'))
48 return true;
50 return false;
54 //only = is a valid operator
55 static inline bool IsSorcusOperator(const int ch)
57 if (ch == '=')
58 return true;
60 return false;
64 static void ColouriseSorcusDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
65 Accessor &styler)
68 WordList &Command = *keywordlists[0];
69 WordList &Parameter = *keywordlists[1];
70 WordList &Constant = *keywordlists[2];
72 // Do not leak onto next line
73 if (initStyle == SCE_SORCUS_STRINGEOL)
74 initStyle = SCE_SORCUS_DEFAULT;
76 StyleContext sc(startPos, length, initStyle, styler);
78 for (; sc.More(); sc.Forward())
81 // Prevent SCE_SORCUS_STRINGEOL from leaking back to previous line
82 if (sc.atLineStart && (sc.state == SCE_SORCUS_STRING))
84 sc.SetState(SCE_SORCUS_STRING);
87 // Determine if the current state should terminate.
88 if (sc.state == SCE_SORCUS_OPERATOR)
90 if (!IsSorcusOperator(sc.ch))
92 sc.SetState(SCE_SORCUS_DEFAULT);
95 else if(sc.state == SCE_SORCUS_NUMBER)
97 if(!IsSorcusNumber(sc.ch, sc.chPrev))
99 sc.SetState(SCE_SORCUS_DEFAULT);
102 else if (sc.state == SCE_SORCUS_IDENTIFIER)
104 if (!IsSWordStart(sc.ch, sc.chPrev))
106 char s[100];
108 sc.GetCurrent(s, sizeof(s));
110 if (Command.InList(s))
112 sc.ChangeState(SCE_SORCUS_COMMAND);
114 else if (Parameter.InList(s))
116 sc.ChangeState(SCE_SORCUS_PARAMETER);
118 else if (Constant.InList(s))
120 sc.ChangeState(SCE_SORCUS_CONSTANT);
123 sc.SetState(SCE_SORCUS_DEFAULT);
126 else if (sc.state == SCE_SORCUS_COMMENTLINE )
128 if (sc.atLineEnd)
130 sc.SetState(SCE_SORCUS_DEFAULT);
133 else if (sc.state == SCE_SORCUS_STRING)
135 if (sc.ch == '\"')
137 sc.ForwardSetState(SCE_SORCUS_DEFAULT);
139 else if (sc.atLineEnd)
141 sc.ChangeState(SCE_SORCUS_STRINGEOL);
142 sc.ForwardSetState(SCE_SORCUS_DEFAULT);
146 // Determine if a new state should be entered.
147 if (sc.state == SCE_SORCUS_DEFAULT)
149 if ((sc.ch == ';') || (sc.ch == '\''))
151 sc.SetState(SCE_SORCUS_COMMENTLINE);
153 else if (IsSWordStart(sc.ch, sc.chPrev))
155 sc.SetState(SCE_SORCUS_IDENTIFIER);
157 else if (sc.ch == '\"')
159 sc.SetState(SCE_SORCUS_STRING);
161 else if (IsSorcusOperator(sc.ch))
163 sc.SetState(SCE_SORCUS_OPERATOR);
165 else if (IsSorcusNumber(sc.ch, sc.chPrev))
167 sc.SetState(SCE_SORCUS_NUMBER);
172 sc.Complete();
176 static const char* const SorcusWordListDesc[] = {"Command","Parameter", "Constant", 0};
178 LexerModule lmSorc(SCLEX_SORCUS, ColouriseSorcusDoc, "sorcins", 0, SorcusWordListDesc);