]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexAPDL.cxx
1 // Scintilla source code edit control
3 ** Lexer for APDL. Based on the lexer for Assembler by The Black Horus.
6 // Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
7 // The License.txt file describes the conditions under which this software may be distributed.
19 #include "StyleContext.h"
21 #include "Scintilla.h"
25 static inline bool IsAWordChar(const int ch
) {
26 return (ch
< 0x80 && (isalnum(ch
) || ch
== '_'));
29 static inline bool IsAnOperator(char ch
) {
30 // '.' left out as it is used to make up numbers
31 if (ch
== '*' || ch
== '/' || ch
== '-' || ch
== '+' ||
32 ch
== '(' || ch
== ')' || ch
== '=' || ch
== '^' ||
33 ch
== '[' || ch
== ']' || ch
== '<' || ch
== '&' ||
34 ch
== '>' || ch
== ',' || ch
== '|' || ch
== '~' ||
35 ch
== '$' || ch
== ':' || ch
== '%')
40 static void ColouriseAPDLDoc(unsigned int startPos
, int length
, int initStyle
, WordList
*keywordlists
[],
43 int stringStart
= ' ';
45 WordList
&processors
= *keywordlists
[0];
46 WordList
&commands
= *keywordlists
[1];
47 WordList
&slashcommands
= *keywordlists
[2];
48 WordList
&starcommands
= *keywordlists
[3];
49 WordList
&arguments
= *keywordlists
[4];
50 WordList
&functions
= *keywordlists
[5];
52 // Do not leak onto next line
53 initStyle
= SCE_APDL_DEFAULT
;
54 StyleContext
sc(startPos
, length
, initStyle
, styler
);
56 for (; sc
.More(); sc
.Forward()) {
57 // Determine if the current state should terminate.
58 if (sc
.state
== SCE_APDL_NUMBER
) {
59 if (!(IsADigit(sc
.ch
) || sc
.ch
== '.' || (sc
.ch
== 'e' || sc
.ch
== 'E') ||
60 ((sc
.ch
== '+' || sc
.ch
== '-') && (sc
.chPrev
== 'e' || sc
.chPrev
== 'E')))) {
61 sc
.SetState(SCE_APDL_DEFAULT
);
63 } else if (sc
.state
== SCE_APDL_COMMENT
) {
65 sc
.SetState(SCE_APDL_DEFAULT
);
67 } else if (sc
.state
== SCE_APDL_COMMENTBLOCK
) {
72 sc
.ForwardSetState(SCE_APDL_DEFAULT
);
74 } else if (sc
.state
== SCE_APDL_STRING
) {
76 sc
.SetState(SCE_APDL_DEFAULT
);
77 } else if ((sc
.ch
== '\'' && stringStart
== '\'') || (sc
.ch
== '\"' && stringStart
== '\"')) {
78 sc
.ForwardSetState(SCE_APDL_DEFAULT
);
80 } else if (sc
.state
== SCE_APDL_WORD
) {
81 if (!IsAWordChar(sc
.ch
)) {
83 sc
.GetCurrentLowered(s
, sizeof(s
));
84 if (processors
.InList(s
)) {
85 sc
.ChangeState(SCE_APDL_PROCESSOR
);
86 } else if (slashcommands
.InList(s
)) {
87 sc
.ChangeState(SCE_APDL_SLASHCOMMAND
);
88 } else if (starcommands
.InList(s
)) {
89 sc
.ChangeState(SCE_APDL_STARCOMMAND
);
90 } else if (commands
.InList(s
)) {
91 sc
.ChangeState(SCE_APDL_COMMAND
);
92 } else if (arguments
.InList(s
)) {
93 sc
.ChangeState(SCE_APDL_ARGUMENT
);
94 } else if (functions
.InList(s
)) {
95 sc
.ChangeState(SCE_APDL_FUNCTION
);
97 sc
.SetState(SCE_APDL_DEFAULT
);
99 } else if (sc
.state
== SCE_APDL_OPERATOR
) {
100 if (!IsAnOperator(static_cast<char>(sc
.ch
))) {
101 sc
.SetState(SCE_APDL_DEFAULT
);
105 // Determine if a new state should be entered.
106 if (sc
.state
== SCE_APDL_DEFAULT
) {
107 if (sc
.ch
== '!' && sc
.chNext
== '!') {
108 sc
.SetState(SCE_APDL_COMMENTBLOCK
);
109 } else if (sc
.ch
== '!') {
110 sc
.SetState(SCE_APDL_COMMENT
);
111 } else if (IsADigit(sc
.ch
) || (sc
.ch
== '.' && IsADigit(sc
.chNext
))) {
112 sc
.SetState(SCE_APDL_NUMBER
);
113 } else if (sc
.ch
== '\'' || sc
.ch
== '\"') {
114 sc
.SetState(SCE_APDL_STRING
);
116 } else if (IsAWordChar(sc
.ch
) || ((sc
.ch
== '*' || sc
.ch
== '/') && !isgraph(sc
.chPrev
))) {
117 sc
.SetState(SCE_APDL_WORD
);
118 } else if (IsAnOperator(static_cast<char>(sc
.ch
))) {
119 sc
.SetState(SCE_APDL_OPERATOR
);
126 static const char * const apdlWordListDesc
[] = {
136 LexerModule
lmAPDL(SCLEX_APDL
, ColouriseAPDLDoc
, "apdl", 0, apdlWordListDesc
);