*** empty log message ***
[anjuta-git-plugin.git] / scintilla / LexAPDL.cxx
blob1cf263e5018a9eef4ba08258943ca595834583df
1 // Scintilla source code edit control
2 /** @file LexAPDL.cxx
3 ** Lexer for APDL. Based on the lexer for Assembler by The Black Horus.
4 ** By Hadar Raz.
5 **/
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.
9 #include <stdlib.h>
10 #include <string.h>
11 #include <ctype.h>
12 #include <stdio.h>
13 #include <stdarg.h>
15 #include "Platform.h"
17 #include "PropSet.h"
18 #include "Accessor.h"
19 #include "StyleContext.h"
20 #include "KeyWords.h"
21 #include "Scintilla.h"
22 #include "SciLexer.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 == '%')
36 return true;
37 return false;
40 static void ColouriseAPDLDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
41 Accessor &styler) {
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) {
64 if (sc.atLineEnd) {
65 sc.SetState(SCE_APDL_DEFAULT);
67 } else if (sc.state == SCE_APDL_COMMENTBLOCK) {
68 if (sc.atLineEnd) {
69 if (sc.ch == '\r') {
70 sc.Forward();
72 sc.ForwardSetState(SCE_APDL_DEFAULT);
74 } else if (sc.state == SCE_APDL_STRING) {
75 if (sc.atLineEnd) {
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)) {
82 char s[100];
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);
115 stringStart = sc.ch;
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);
123 sc.Complete();
126 static const char * const apdlWordListDesc[] = {
127 "processors",
128 "commands",
129 "slashommands",
130 "starcommands",
131 "arguments",
132 "functions",
136 LexerModule lmAPDL(SCLEX_APDL, ColouriseAPDLDoc, "apdl", 0, apdlWordListDesc);