static inline bool IsIdentifierStart (const int ch)
{
return (ch < 0x80) && (isalpha(ch) || (ch == '_') || (ch == '\'));
}
static inline bool IsIdentifierChar (const int ch)
{
return (ch < 0x80) && (isalnum(ch) || (ch == '_') || (ch == '@') ||
(ch == ':') || (ch == '.') || (ch == '\'));
}
static inline bool IsLabelStart (const int ch)
{
return (ch < 0x80) && (isalpha(ch) || (ch == '_') || (ch == '\'));
}
static inline int IsOperator (const int ch1, const int ch2)
{
if (ch1 < 0x80)
{
if ((ch1 == '+') || (ch1 == '-') || (ch1 == '*') || (ch1 == '/') || (ch1 == '#') ||
(ch1 == '(') || (ch1 == ')') || (ch1 == '~') || (ch1 == '&') || (ch1 == '|'))
return 1;
else if ((ch2 < 0x80) && (ch1 == ch2) && (ch1 == '<' || ch1 == '>'))
return 2;
}
return 0;
}
static inline bool IsBin (const int ch)
{
return (ch < 0x80) && ((ch == '0') || (ch == '1'));
}
static void ColouriseA68kDoc (unsigned int startPos, int length, int initStyle, WordList *keywordlists[], Accessor &styler)
{
WordList &cpuInstruction = *keywordlists[0];
WordList ®isters = *keywordlists[1];
WordList &directive = *keywordlists[2];
WordList &extInstruction = *keywordlists[3];
StyleContext sc(startPos, length, initStyle, styler);
for (; sc.More(); sc.Forward())
{
char Buffer[100];
int OpType;
// Reset style at beginning of line
if (sc.atLineStart)
sc.SetState(SCE_A68K_DEFAULT);
// Check if current style continue
if (sc.state != SCE_A68K_DEFAULT)
{
if (((sc.state == SCE_A68K_COMMENT) && !sc.atLineStart) ||
((sc.state == SCE_A68K_NUMBER_DEC) && isdigit(sc.ch)) ||
((sc.state == SCE_A68K_NUMBER_BIN) && IsBin(sc.ch)) ||
((sc.state == SCE_A68K_NUMBER_HEX) && isxdigit(sc.ch)) ||
((sc.state == SCE_A68K_MACRO_ARG) && isdigit(sc.ch)) ||
((sc.state == SCE_A68K_STRING1) && (sc.ch != '\'')) ||
((sc.state == SCE_A68K_STRING2) && (sc.ch != '\"')) ||
((sc.state == SCE_A68K_LABEL) && ((sc.ch != ':') ||
((sc.ch == ':') && (sc.chNext == ':')) ||
((sc.chPrev == ':') && (sc.ch == ':') && IsIdentifierChar(sc.chNext)))) ||
((sc.state == SCE_A68K_IDENTIFIER) && IsIdentifierChar(sc.ch)))
continue;
else if (((sc.state == SCE_A68K_STRING1) && (sc.ch == '\'')) ||
((sc.state == SCE_A68K_STRING2) && (sc.ch == '\"')) ||
((sc.state == SCE_A68K_LABEL) && (sc.ch == ':')))
sc.ForwardSetState(SCE_A68K_DEFAULT);
else if ((sc.state == SCE_A68K_IDENTIFIER) && !IsIdentifierChar(sc.ch))
{
sc.GetCurrentLowered(Buffer, sizeof(Buffer));
if (cpuInstruction.InList(Buffer))
sc.ChangeState(SCE_A68K_CPUINSTRUCTION);
else if (extInstruction.InList(Buffer))
sc.ChangeState(SCE_A68K_EXTINSTRUCTION);
else if (registers.InList(Buffer))
sc.ChangeState(SCE_A68K_REGISTER);
else if (directive.InList(Buffer))
sc.ChangeState(SCE_A68K_DIRECTIVE);
}
sc.SetState(SCE_A68K_DEFAULT); // Drop current state ?
}
// Check if a new style must be entered
OpType = IsOperator(sc.ch, sc.chNext);
if (sc.atLineStart && IsLabelStart(sc.ch))
sc.SetState(SCE_A68K_LABEL);
else if (sc.ch == ';')
sc.SetState(SCE_A68K_COMMENT);
else if (isdigit(sc.ch))
sc.SetState(SCE_A68K_NUMBER_DEC);
else if (sc.ch == '%')
sc.SetState(SCE_A68K_NUMBER_BIN);
else if (sc.ch == '$')
sc.SetState(SCE_A68K_NUMBER_HEX);
else if (sc.ch == '\'')
sc.SetState(SCE_A68K_STRING1);
else if (sc.ch == '\"')
sc.SetState(SCE_A68K_STRING2);
else if (sc.ch == '\')
sc.SetState(SCE_A68K_MACRO_ARG);
else if (IsIdentifierStart(sc.ch))
sc.SetState(SCE_A68K_IDENTIFIER);
else if (OpType != 0)
{
sc.SetState(SCE_A68K_OPERATOR);
if (OpType == 2)
sc.ForwardSetState(SCE_A68K_OPERATOR);
}
}
sc.Complete();
}
static const char * const a68kWordListDesc[] =
{
"CPU instructions",
"Registers",
"Directives",
"Extended instructions",
0
};
LexerModule lmA68k(SCLEX_A68K, ColouriseA68kDoc, "A68k", 0, a68kWordListDesc);
typedef void (*funcptr)(void); struct machin { funcptr More; funcptr Forward; } sc;
Ximoon (./86) :
Valide mais moche
Je pensais surtout à "WordList &cpuInstruction = *keywordlists[0];" pour dire ça
Ximoon (./86) :plus clair comme ça
Je pensais surtout à "WordList &cpuInstruction = *keywordlists[0];" pour dire ça