]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexAsm.cxx
1eecf9b31a99b8570297e32ea9d12dad72009773
1 // Scintilla source code edit control
3 ** Lexer for Assembler, just for the Masm Syntax
4 ** Written by The Black Horus
6 // Copyright 1998-2002 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"
26 static inline bool IsAWordChar(const int ch
) {
27 return (ch
< 0x80) && (isalnum(ch
) || ch
== '.' || ch
== '_' || ch
=='\\');
30 static inline bool IsAWordStart(const int ch
) {
31 return (ch
< 0x80) && (isalnum(ch
) || ch
== '_' || ch
== '.');
34 inline bool isAsmOperator(char ch
) {
37 // '.' left out as it is used to make up numbers
38 if (ch
== '*' || ch
== '/' || ch
== '-' || ch
== '+' ||
39 ch
== '(' || ch
== ')' || ch
== '=' ||
40 ch
== '[' || ch
== ']' || ch
== '<' ||
41 ch
== '>' || ch
== ',' ||
42 ch
== '.' || ch
== '%' || ch
== ':')
47 static void ColouriseAsmDoc(unsigned int startPos
, int length
, int initStyle
, WordList
*keywordlists
[],
50 WordList
&cpuInstruction
= *keywordlists
[0];
51 WordList
&mathInstruction
= *keywordlists
[1];
52 WordList
®isters
= *keywordlists
[2];
53 WordList
&directive
= *keywordlists
[3];
54 WordList
&directiveOperand
= *keywordlists
[4];
56 StyleContext
sc(startPos
, length
, initStyle
, styler
);
58 for (; sc
.More(); sc
.Forward())
60 // Handle line continuation generically.
62 if (sc
.Match("\\\n")) {
66 if (sc
.Match("\\\r\n")) {
73 // Determine if the current state should terminate.
74 if (sc
.state
== SCE_ASM_OPERATOR
) {
75 sc
.SetState(SCE_ASM_DEFAULT
);
76 }else if (sc
.state
== SCE_ASM_NUMBER
) {
77 if (!IsAWordChar(sc
.ch
)) {
78 sc
.SetState(SCE_ASM_DEFAULT
);
80 } else if (sc
.state
== SCE_ASM_IDENTIFIER
) {
81 if (!IsAWordChar(sc
.ch
) ) {
83 sc
.GetCurrentLowered(s
, sizeof(s
));
85 if (cpuInstruction
.InList(s
)) {
86 sc
.ChangeState(SCE_ASM_CPUINSTRUCTION
);
87 } else if (mathInstruction
.InList(s
)) {
88 sc
.ChangeState(SCE_ASM_MATHINSTRUCTION
);
89 } else if (registers
.InList(s
)) {
90 sc
.ChangeState(SCE_ASM_REGISTER
);
91 } else if (directive
.InList(s
)) {
92 sc
.ChangeState(SCE_ASM_DIRECTIVE
);
93 } else if (directiveOperand
.InList(s
)) {
94 sc
.ChangeState(SCE_ASM_DIRECTIVEOPERAND
);
96 sc
.SetState(SCE_ASM_DEFAULT
);
99 else if (sc
.state
== SCE_ASM_COMMENT
) {
101 sc
.SetState(SCE_ASM_DEFAULT
);
103 } else if (sc
.state
== SCE_ASM_STRING
) {
105 if (sc
.chNext
== '\"' || sc
.chNext
== '\'' || sc
.chNext
== '\\') {
108 } else if (sc
.ch
== '\"') {
109 sc
.ForwardSetState(SCE_ASM_DEFAULT
);
110 } else if (sc
.atLineEnd
) {
111 sc
.ForwardSetState(SCE_ASM_DEFAULT
);
115 // Determine if a new state should be entered.
116 else if (sc
.state
== SCE_ASM_DEFAULT
) {
118 sc
.SetState(SCE_ASM_COMMENT
);
119 } else if (isdigit(sc
.ch
) || (sc
.ch
== '.' && isdigit(sc
.chNext
))) {
120 sc
.SetState(SCE_ASM_NUMBER
);
121 } else if (IsAWordStart(sc
.ch
)) {
122 sc
.SetState(SCE_ASM_IDENTIFIER
);
123 } else if (sc
.Match('\"')) {
124 sc
.SetState(SCE_ASM_STRING
);
132 static const char * const asmWordListDesc
[] = {
137 "Directive operands",
141 LexerModule
lmAsm(SCLEX_ASM
, ColouriseAsmDoc
, "asm", 0, asmWordListDesc
);