]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexAsm.cxx
17c938420a043e80c0f2bccef6333edaaae5ab88
1 // Scintilla source code edit control
3 ** Lexer for Assembler, just for the MASM syntax
4 ** Written by The Black Horus
5 ** Enhancements and NASM stuff by Kein-Hong Man, 2003-10
6 ** SCE_ASM_COMMENTBLOCK and SCE_ASM_CHARACTER are for future GNU as colouring
8 // Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
9 // The License.txt file describes the conditions under which this software may be distributed.
21 #include "StyleContext.h"
23 #include "Scintilla.h"
27 using namespace Scintilla
;
30 static inline bool IsAWordChar(const int ch
) {
31 return (ch
< 0x80) && (isalnum(ch
) || ch
== '.' ||
32 ch
== '_' || ch
== '?');
35 static inline bool IsAWordStart(const int ch
) {
36 return (ch
< 0x80) && (isalnum(ch
) || ch
== '_' || ch
== '.' ||
37 ch
== '%' || ch
== '@' || ch
== '$' || ch
== '?');
40 static inline bool IsAsmOperator(const int ch
) {
41 if ((ch
< 0x80) && (isalnum(ch
)))
43 // '.' left out as it is used to make up numbers
44 if (ch
== '*' || ch
== '/' || ch
== '-' || ch
== '+' ||
45 ch
== '(' || ch
== ')' || ch
== '=' || ch
== '^' ||
46 ch
== '[' || ch
== ']' || ch
== '<' || ch
== '&' ||
47 ch
== '>' || ch
== ',' || ch
== '|' || ch
== '~' ||
48 ch
== '%' || ch
== ':')
53 static void ColouriseAsmDoc(unsigned int startPos
, int length
, int initStyle
, WordList
*keywordlists
[],
56 WordList
&cpuInstruction
= *keywordlists
[0];
57 WordList
&mathInstruction
= *keywordlists
[1];
58 WordList
®isters
= *keywordlists
[2];
59 WordList
&directive
= *keywordlists
[3];
60 WordList
&directiveOperand
= *keywordlists
[4];
61 WordList
&extInstruction
= *keywordlists
[5];
63 // Do not leak onto next line
64 if (initStyle
== SCE_ASM_STRINGEOL
)
65 initStyle
= SCE_ASM_DEFAULT
;
67 StyleContext
sc(startPos
, length
, initStyle
, styler
);
69 for (; sc
.More(); sc
.Forward())
72 // Prevent SCE_ASM_STRINGEOL from leaking back to previous line
73 if (sc
.atLineStart
&& (sc
.state
== SCE_ASM_STRING
)) {
74 sc
.SetState(SCE_ASM_STRING
);
75 } else if (sc
.atLineStart
&& (sc
.state
== SCE_ASM_CHARACTER
)) {
76 sc
.SetState(SCE_ASM_CHARACTER
);
79 // Handle line continuation generically.
81 if (sc
.chNext
== '\n' || sc
.chNext
== '\r') {
83 if (sc
.ch
== '\r' && sc
.chNext
== '\n') {
90 // Determine if the current state should terminate.
91 if (sc
.state
== SCE_ASM_OPERATOR
) {
92 if (!IsAsmOperator(sc
.ch
)) {
93 sc
.SetState(SCE_ASM_DEFAULT
);
95 }else if (sc
.state
== SCE_ASM_NUMBER
) {
96 if (!IsAWordChar(sc
.ch
)) {
97 sc
.SetState(SCE_ASM_DEFAULT
);
99 } else if (sc
.state
== SCE_ASM_IDENTIFIER
) {
100 if (!IsAWordChar(sc
.ch
) ) {
102 sc
.GetCurrentLowered(s
, sizeof(s
));
104 if (cpuInstruction
.InList(s
)) {
105 sc
.ChangeState(SCE_ASM_CPUINSTRUCTION
);
106 } else if (mathInstruction
.InList(s
)) {
107 sc
.ChangeState(SCE_ASM_MATHINSTRUCTION
);
108 } else if (registers
.InList(s
)) {
109 sc
.ChangeState(SCE_ASM_REGISTER
);
110 } else if (directive
.InList(s
)) {
111 sc
.ChangeState(SCE_ASM_DIRECTIVE
);
112 } else if (directiveOperand
.InList(s
)) {
113 sc
.ChangeState(SCE_ASM_DIRECTIVEOPERAND
);
114 } else if (extInstruction
.InList(s
)) {
115 sc
.ChangeState(SCE_ASM_EXTINSTRUCTION
);
117 sc
.SetState(SCE_ASM_DEFAULT
);
120 else if (sc
.state
== SCE_ASM_COMMENT
) {
122 sc
.SetState(SCE_ASM_DEFAULT
);
124 } else if (sc
.state
== SCE_ASM_STRING
) {
126 if (sc
.chNext
== '\"' || sc
.chNext
== '\'' || sc
.chNext
== '\\') {
129 } else if (sc
.ch
== '\"') {
130 sc
.ForwardSetState(SCE_ASM_DEFAULT
);
131 } else if (sc
.atLineEnd
) {
132 sc
.ChangeState(SCE_ASM_STRINGEOL
);
133 sc
.ForwardSetState(SCE_ASM_DEFAULT
);
135 } else if (sc
.state
== SCE_ASM_CHARACTER
) {
137 if (sc
.chNext
== '\"' || sc
.chNext
== '\'' || sc
.chNext
== '\\') {
140 } else if (sc
.ch
== '\'') {
141 sc
.ForwardSetState(SCE_ASM_DEFAULT
);
142 } else if (sc
.atLineEnd
) {
143 sc
.ChangeState(SCE_ASM_STRINGEOL
);
144 sc
.ForwardSetState(SCE_ASM_DEFAULT
);
148 // Determine if a new state should be entered.
149 if (sc
.state
== SCE_ASM_DEFAULT
) {
151 sc
.SetState(SCE_ASM_COMMENT
);
152 } else if (isascii(sc
.ch
) && (isdigit(sc
.ch
) || (sc
.ch
== '.' && isascii(sc
.chNext
) && isdigit(sc
.chNext
)))) {
153 sc
.SetState(SCE_ASM_NUMBER
);
154 } else if (IsAWordStart(sc
.ch
)) {
155 sc
.SetState(SCE_ASM_IDENTIFIER
);
156 } else if (sc
.ch
== '\"') {
157 sc
.SetState(SCE_ASM_STRING
);
158 } else if (sc
.ch
== '\'') {
159 sc
.SetState(SCE_ASM_CHARACTER
);
160 } else if (IsAsmOperator(sc
.ch
)) {
161 sc
.SetState(SCE_ASM_OPERATOR
);
169 static const char * const asmWordListDesc
[] = {
174 "Directive operands",
175 "Extended instructions",
179 LexerModule
lmAsm(SCLEX_ASM
, ColouriseAsmDoc
, "asm", 0, asmWordListDesc
);