]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexAPDL.cxx
b739e9a7cb562845ad58855044131c8eff494566
12 #include "StyleContext.h"
14 #include "Scintilla.h"
18 static inline bool IsAWordChar(const int ch
) {
19 return (ch
< 0x80) && (isalnum(ch
) || ch
== '_');
22 static inline bool IsAWordStart(const int ch
) {
23 return (ch
< 0x80) && (isalnum(ch
) || ch
== '/' || ch
== '*');
26 inline bool IsABlank(unsigned int ch
) {
27 return (ch
== ' ') || (ch
== 0x09) || (ch
== 0x0b) ;
32 static void ColouriseAPDLDoc(unsigned int startPos
, int length
, int initStyle
,
33 WordList
*keywordlists
[], Accessor
&styler
)
37 //~ fp = fopen("myoutput.txt", "w");
39 WordList
&commands
= *keywordlists
[0];
40 WordList
&processors
= *keywordlists
[1];
41 WordList
&functions
= *keywordlists
[2];
44 // backtrack to the beginning of the document, this may be slow for big documents.
45 initStyle
= SCE_APDL_DEFAULT
;
46 StyleContext
sc(0, startPos
+length
, initStyle
, styler
);
48 // backtrack to the nearest keyword
49 //~ while ((startPos > 1) && (styler.StyleAt(startPos) != SCE_APDL_WORD)) {
52 //~ startPos = styler.LineStart(styler.GetLine(startPos));
53 //~ initStyle = styler.StyleAt(startPos - 1);
54 //~ StyleContext sc(startPos, endPos-startPos, initStyle, styler);
56 bool firstInLine
= true;
59 for (; sc
.More(); sc
.Forward()) {
61 atEOL
= (sc
.ch
== '\r' && sc
.chNext
== '\n') || (sc
.ch
== '\n');
63 //~ if (sc.ch == '\r') {
64 //~ fprintf(fp,"CR\t%d\t%d", atEOL, firstInLine);
65 //~ } else if (sc.ch == '\n') {
66 //~ fprintf(fp,"LF\t%d\t%d", atEOL, firstInLine);
68 //~ fprintf(fp,"%c\t%d\t%d", sc.ch, atEOL, firstInLine);
71 // Determine if the current state should terminate.
72 if (sc
.state
== SCE_APDL_COMMENT
) {
73 //~ fprintf(fp,"\tCOMMENT");
75 sc
.SetState(SCE_APDL_DEFAULT
);
77 } else if (sc
.state
== SCE_APDL_COMMENTBLOCK
) {
78 //~ fprintf(fp,"\tCOMMENTBLOCK");
83 sc
.ForwardSetState(SCE_APDL_DEFAULT
);
85 } else if (sc
.state
== SCE_APDL_NUMBER
) {
86 //~ fprintf(fp,"\tNUMBER");
88 } else if ((sc
.ch
== 'e' || sc
.ch
== 'E') && (isdigit(sc
.chNext
) || sc
.chNext
== '+' || sc
.chNext
== '-')) {
89 } else if (sc
.ch
== '.') {
90 } else if ((sc
.ch
== '+' || sc
.ch
== '-') && (sc
.chPrev
== 'e' || sc
.chPrev
== 'E')) {
92 sc
.SetState(SCE_APDL_DEFAULT
);
94 } else if (sc
.state
== SCE_APDL_STRING
) {
95 //~ fprintf(fp,"\tSTRING");
97 //~ sc.ForwardSetState(SCE_APDL_DEFAULT);
99 atEOL
= (sc
.ch
== '\r' && sc
.chNext
== '\n') || (sc
.ch
== '\n');
103 sc
.SetState(SCE_APDL_DEFAULT
);
105 } else if (sc
.state
== SCE_APDL_WORD
) {
106 //~ fprintf(fp,"\tWORD");
107 if (!IsAWordChar(sc
.ch
) || sc
.ch
== '%') {
109 sc
.GetCurrentLowered(s
, sizeof(s
));
110 if (commands
.InList(s
) && firstInLine
) {
111 if (IsABlank(sc
.ch
) || sc
.ch
== ',' || atEOL
) {
112 sc
.ChangeState(SCE_APDL_COMMAND
);
117 } else if (processors
.InList(s
)) {
118 if (IsABlank(sc
.ch
) || atEOL
) {
119 sc
.ChangeState(SCE_APDL_PROCESSOR
);
120 while (sc
.ch
!= '\n') {
125 } else if (functions
.InList(s
)) {
126 sc
.ChangeState(SCE_APDL_FUNCTION
);
135 sc
.SetState(SCE_APDL_DEFAULT
);
139 // Determine if a new state should be entered.
140 if (sc
.state
== SCE_APDL_DEFAULT
) {
141 if (sc
.ch
== '!' && sc
.chNext
!= '!') {
142 sc
.SetState(SCE_APDL_COMMENT
);
143 } else if (sc
.ch
== '!' && sc
.chNext
== '!') {
144 sc
.SetState(SCE_APDL_COMMENTBLOCK
);
145 } else if (IsADigit(sc
.ch
) && !IsAWordChar(sc
.chPrev
)) {
146 sc
.SetState(SCE_APDL_NUMBER
);
147 } else if (sc
.ch
== '.' && (isoperator(static_cast<char>(sc
.chPrev
)) ||
148 IsABlank(sc
.chPrev
) || sc
.chPrev
== '\n' || sc
.chPrev
== '\r')) {
149 sc
.SetState(SCE_APDL_NUMBER
);
150 } else if (sc
.ch
== '\"') {
151 sc
.SetState(SCE_APDL_STRING
);
152 } else if (IsAWordStart(sc
.ch
) && (!IsADigit(sc
.chPrev
))) {
153 sc
.SetState(SCE_APDL_WORD
);
157 //~ fprintf(fp,"\n");
167 static const char * const apdlWordListDesc
[] = {
174 LexerModule
lmAPDL(SCLEX_APDL
, ColouriseAPDLDoc
, "apdl", 0, apdlWordListDesc
);