
Folco (./122) :
Hmmm, Pen^2, bien que je n'aime pas trop ta technique accoladatoire, je dois bien reconnaitre que :
- ça crée l'interligne souhaité
- les accolades évitent toute équivoque
- si on veut rajouter un traitement après le if, les accolades sont déjà là, pas besoin de tout péter
Mais j'aime bien quand les colonnes de mes accolades ouvrantes et fermantes sont les mêmes. Faut que je réfléchisse à la question.
Ximoon (./123) :
L'est pas fluo
Mais bon ça n'est pas trop directement le sujet même si un peu quand même
Ximoon (./109) :
./105 > exactement(et pour les mêmes raisons que je donnais pour la présence d'une seule instruction "return").
// Return values for GetOperatorType
/**
* IsIdentifierStart
*
* Return true if the given char is a valid identifier first char
*/
static inline bool IsIdentifierStart (const int ch)
{
return (isalpha(ch) || (ch == '_') || (ch == '\'));
}
/**
* IsIdentifierChar
*
* Return true if the given char is a valid identifier char
*/
static inline bool IsIdentifierChar (const int ch)
{
return (isalnum(ch) || (ch == '_') || (ch == '@') || (ch == ':') || (ch == '.'));
}
/**
* GetOperatorType
*
* Return:
* NO_OPERATOR if char is not an operator
* OPERATOR_1CHAR if the operator is one char long
* OPERATOR_2CHAR if the operator is two chars long
*/
static inline int GetOperatorType (const int ch1, const int ch2)
{
int OpType = NO_OPERATOR;
if ((ch1 == '+') || (ch1 == '-') || (ch1 == '*') || (ch1 == '/') || (ch1 == '#') ||
(ch1 == '(') || (ch1 == ')') || (ch1 == '~') || (ch1 == '&') || (ch1 == '|') || (ch1 == ','))
OpType = OPERATOR_1CHAR;
else if ((ch1 == ch2) && (ch1 == '<' || ch1 == '>'))
OpType = OPERATOR_2CHAR;
return OpType;
}
/**
* IsBin
*
* Return true if the given char is 0 or 1
*/
static inline bool IsBin (const int ch)
{
return (ch == '0') || (ch == '1');
}
/**
* ColouriseA68kDoc
*
* Main function, which colourise a 68k source
*/
static void ColouriseA68kDoc (unsigned int startPos, int length, int initStyle, WordList *keywordlists[], Accessor &styler)
{
// Get references to keywords lists
WordList &cpuInstruction = *keywordlists[0];
WordList ®isters = *keywordlists[1];
WordList &directive = *keywordlists[2];
WordList &extInstruction = *keywordlists[3];
// Instanciate a context for our source
StyleContext sc(startPos, length, initStyle, styler);
/************************************************************
*
* Parse the text
*
************************************************************/
for ( ; sc.More(); sc.Forward())
{
char Buffer[100];
int OpType;
// Reset style at beginning of line
if (sc.atLineStart)
sc.SetState(SCE_A68K_DEFAULT);
/************************************************************
*
* Handle current state if we are not in the "default style"
*
************************************************************/
if (sc.state != SCE_A68K_DEFAULT)
{
// Check if current style continue.
// If this case, we loop because there is nothing else to do
if ((sc.state == SCE_A68K_COMMENT) || // Comment
((sc.state == SCE_A68K_NUMBER_DEC) && isdigit(sc.ch)) || // Decimal number
((sc.state == SCE_A68K_NUMBER_BIN) && IsBin(sc.ch)) || // Binary number
((sc.state == SCE_A68K_NUMBER_HEX) && isxdigit(sc.ch)) || // Hexa number
((sc.state == SCE_A68K_MACRO_ARG) && isdigit(sc.ch)) || // Arg of macro
((sc.state == SCE_A68K_STRING1) && (sc.ch != '\'')) || // String single-quoted
((sc.state == SCE_A68K_STRING2) && (sc.ch != '\"')) || // String double-quoted
// Label. ' ' and '\t' are needed to handle macro declarations
((sc.state == SCE_A68K_LABEL) && (sc.ch != ':') && (sc.ch != ' ') && (sc.ch != '\t')) ||
((sc.state == SCE_A68K_IDENTIFIER) && (sc.ch < 0x80) && IsIdentifierChar(sc.ch))) { // Identifier
continue;
}
// Check if some states terminate at the current char:
// we must include that char in the current style context
else if (((sc.state == SCE_A68K_STRING1) && (sc.ch < 0x80) && (sc.ch == '\'')) || // String single-quoted
((sc.state == SCE_A68K_STRING2) && (sc.ch < 0x80) && (sc.ch == '\"')) || // String double-quoted
((sc.state == SCE_A68K_LABEL) && (sc.ch < 0x80) && (sc.ch == ':'))) { // Label
sc.ForwardSetState(SCE_A68K_DEFAULT);
}
// Check if we are in the case of a label which terminates without ':'
// It should be a macro declaration, not a label
else if ((sc.state == SCE_A68K_LABEL) && (sc.ch < 0x80) && ((sc.ch == ' ') || (sc.ch == '\t'))) {
sc.ChangeState(SCE_A68K_MACRO_DECLARATION);
}
// Check if we are at the end of a identifier
// In this case, colourise it if was a keyword.
else if ((sc.state == SCE_A68K_IDENTIFIER) && !IsIdentifierChar(sc.ch)) {
sc.GetCurrentLowered(Buffer, sizeof(Buffer)); // Buffer the string of the current context
if (cpuInstruction.InList(Buffer)) // And check if it belongs to a keyword list
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);
}
// All special contexts are now handled.Come back to default style
sc.SetState(SCE_A68K_DEFAULT);
}
/************************************************************
*
* Check if we must enter a new state
*
************************************************************/
// Label and macro identifiers start at the beginning of a line
// We set both as a label, but if it wasn't one (no ':' at the end),
// it will be changed as a macro identifier.
if (sc.atLineStart && (sc.ch < 0x80) && IsIdentifierStart(sc.ch)) {
sc.SetState(SCE_A68K_LABEL);
}
else if ((sc.ch < 0x80) && (sc.ch == ';')) { // Comment
sc.SetState(SCE_A68K_COMMENT);
}
else if ((sc.ch < 0x80) && isdigit(sc.ch)) { // Decimal numbers haven't prefix
sc.SetState(SCE_A68K_NUMBER_DEC);
}
else if ((sc.ch < 0x80) && (sc.ch == '%')) { // Binary numbers are prefixed with '%'
sc.SetState(SCE_A68K_NUMBER_BIN);
}
else if ((sc.ch < 0x80) && (sc.ch == '$')) { // Hexadecimal numbers are prefixed with '$'
sc.SetState(SCE_A68K_NUMBER_HEX);
}
else if ((sc.ch < 0x80) && (sc.ch == '\'')) { // String (single-quoted)
sc.SetState(SCE_A68K_STRING1);
}
else if ((sc.ch < 0x80) && (sc.ch == '\"')) { // String (double-quoted)
sc.SetState(SCE_A68K_STRING2);
}
else if ((sc.ch < 0x80) && (sc.ch == '\') && (isdigit(sc.chNext))) { // Replacement symbols in macro
sc.SetState(SCE_A68K_MACRO_ARG);
}
else if ((sc.ch < 0x80) && IsIdentifierStart(sc.ch)) { // An identifier: constant, label, etc...
sc.SetState(SCE_A68K_IDENTIFIER);
}
else {
if (sc.ch < 0x80) {
OpType = GetOperatorType(sc.ch, sc.chNext); // Check if current char is an operator
if (OpType != NO_OPERATOR) {
sc.SetState(SCE_A68K_OPERATOR);
if (OpType == OPERATOR_2CHAR) { // Check if the operator is 2 bytes long
sc.ForwardSetState(SCE_A68K_OPERATOR); // (>> or <<)
}
}
}
}
} // End of for()
sc.Complete();
}
Folco (./116) :Alors il s'agit des règles personelles, à toi de voir si ça te convient, mais quand je coupe une expression sur plusieurs lignes:
Uther : Si t'as des critiques par rapport au post ./81, c'est le moment, merci d'avance (peut-être)
ex:if ((sc.state == SCE_A68K_COMMENT) // Comment || ((sc.state == SCE_A68K_NUMBER_DEC) && isdigit(sc.ch)) // Decimal number || ((sc.state == SCE_A68K_NUMBER_BIN) && IsBin(sc.ch)) // Binary number || ((sc.state == SCE_A68K_NUMBER_HEX) && isxdigit(sc.ch)) // Hexa number || ((sc.state == SCE_A68K_MACRO_ARG) && isdigit(sc.ch)) // Arg of macro || ((sc.state == SCE_A68K_STRING1) && (sc.ch != '\'')) // String single-quoted || ((sc.state == SCE_A68K_STRING2) && (sc.ch != '\"')) // String double-quoted // Label. ' ' and '\t' are needed to handle macro declarations || ((sc.state == SCE_A68K_LABEL) && (sc.ch != ':') && (sc.ch != ' ') && (sc.ch != '\t')) || ((sc.state == SCE_A68K_IDENTIFIER) && (sc.ch < 0x80) && IsIdentifierChar(ch))) // Identifier { continue;
if( (sc.state == SCE_A68K_COMMENT ) // Comment || ((sc.state == SCE_A68K_NUMBER_DEC) && isdigit(sc.ch)) // Decimal number || ((sc.state == SCE_A68K_NUMBER_BIN) && IsBin(sc.ch)) // Binary number || ((sc.state == SCE_A68K_NUMBER_HEX) && isxdigit(sc.ch)) // Hexa number || ((sc.state == SCE_A68K_MACRO_ARG ) && isdigit(sc.ch)) // Arg of macro || ((sc.state == SCE_A68K_STRING1 ) && (sc.ch != '\'')) // String single-quoted || ((sc.state == SCE_A68K_STRING2 ) && (sc.ch != '\"')) // String double-quoted // Label. ' ' and '\t' are needed to handle macro declarations || ((sc.state == SCE_A68K_LABEL ) && (sc.ch != ':') && (sc.ch != ' ') && (sc.ch != '\t')) || ((sc.state == SCE_A68K_IDENTIFIER) && (sc.ch < 0x80) && IsIdentifierChar(ch))) // Identifier { continue; }
Folco (./138) :Moi c'est l'inverse : pour les accolade d'habitude je ne fait jamais de retour à la ligne: l'indentation permet de voir simplement qu'on est dans un bloc.
Pour les accolades, moi aussi je préfère ce style, mais pour les toutes petites conditions (une seule instruction au cas où la condition est vraie), ça fait un code très long, donc plus chiant à bien visualiser.
Uther (./139) :
Je fais juste une exception pour les blocs qui suivent une expression sur plusieurs lignes car du coup l'indentation n'est plus aussi évidente. Dans ton code, pour l'exemple que j'ai pris, le "continue" se retrouve aligné avec l'expression, ce qui donne l'impression au premier coup d'oeil qu'il en fait partie.
void function() { if(chose) { prout(); } }ça permet de bien voir le proto de la fonction.
void function() { if(chose) { prout(); } }
squalyl (./143) :void function() { if(chose) { prout(); } }ça permet de bien voir le proto de la fonction.
et au boulot, on nous oblige à faire:void function() { if(chose) { prout(); } }
Folco (./144) :
Tiens, j'ai corrigé un bug (les arguments de macros dont le numéro était >= 10 étaient mal parsés).
J'ai mis l'archive a jour (lien identique).
Je ne vous félicite pas pour votre review les gars![]()
Pen^2 (./146) :Folco (./144) :
Tiens, j'ai corrigé un bug (les arguments de macros dont le numéro était >= 10 étaient mal parsés).
J'ai mis l'archive a jour (lien identique).
Je ne vous félicite pas pour votre review les gars![]()
Justement, on en discutait : on se demandait si tu allais finir par trouver
squalyl (./143) :Ok, Tu voulais dire que tu fais un retour a la ligne seulement pour les fonctions.void function() { if(chose) { prout(); } }ça permet de bien voir le proto de la fonction.
et au boulot, on nous oblige à faire:void function() { if(chose) { prout(); } }
void function() { if(chose) { prout(); } }d'ou le
squalyl (./143) :et au boulot, on nous oblige à faire:Le style "whitesmith". Il devrait juste y avoir une loi pour interdire ça.void function() { if(chose) { prout(); } }