remove trailing spaces

This commit is contained in:
Sean S
2014-11-29 16:43:56 +00:00
parent 38deac77fe
commit dbb13d4816

142
rust.mm
View File

@@ -33,7 +33,7 @@ SInt32 skipString(BBLMTextIterator &iter)
SInt32 length = 1; SInt32 length = 1;
UniChar terminator = iter.GetNextChar(); UniChar terminator = iter.GetNextChar();
UniChar ch; UniChar ch;
while ((ch = iter.GetNextChar())) while ((ch = iter.GetNextChar()))
{ {
length++; length++;
@@ -41,14 +41,14 @@ SInt32 skipString(BBLMTextIterator &iter)
{ {
break; break;
} }
if (ch == '\\') if (ch == '\\')
{ {
iter++; iter++;
length++; length++;
} }
} }
return length; return length;
} }
@@ -56,7 +56,7 @@ SInt32 skipLineComment(BBLMTextIterator &iter)
{ {
SInt32 length = 2; SInt32 length = 2;
UniChar ch; UniChar ch;
iter += 2; iter += 2;
while ((ch = iter.GetNextChar())) while ((ch = iter.GetNextChar()))
{ {
@@ -70,7 +70,7 @@ SInt32 skipLineComment(BBLMTextIterator &iter)
length++; length++;
} }
} }
return length; return length;
} }
@@ -84,10 +84,10 @@ SInt32 skipBlockComment(BBLMTextIterator &iter)
iter++; iter++;
length++; length++;
} }
iter += 2; iter += 2;
length += 2; length += 2;
return length; return length;
} }
@@ -95,7 +95,7 @@ SInt32 skipWhitespace(BBLMTextIterator &iter)
{ {
SInt32 length = 0; SInt32 length = 0;
UniChar ch; UniChar ch;
while ((ch = iter.GetNextChar())) while ((ch = iter.GetNextChar()))
{ {
if (isspace(ch)) if (isspace(ch))
@@ -108,7 +108,7 @@ SInt32 skipWhitespace(BBLMTextIterator &iter)
break; break;
} }
} }
return length; return length;
} }
@@ -116,7 +116,7 @@ SInt32 skipWord(BBLMTextIterator &iter)
{ {
SInt32 length = 0; SInt32 length = 0;
UniChar ch; UniChar ch;
while ((ch = iter.GetNextChar())) while ((ch = iter.GetNextChar()))
{ {
if (isalpha(ch) || ch == '_') if (isalpha(ch) || ch == '_')
@@ -129,7 +129,7 @@ SInt32 skipWord(BBLMTextIterator &iter)
break; break;
} }
} }
return length; return length;
} }
@@ -137,7 +137,7 @@ SInt32 skipAttribute(BBLMTextIterator &iter)
{ {
SInt32 length = 1; SInt32 length = 1;
UniChar ch; UniChar ch;
iter++; iter++;
while ((ch = iter.GetNextChar())) while ((ch = iter.GetNextChar()))
{ {
@@ -150,7 +150,7 @@ SInt32 skipAttribute(BBLMTextIterator &iter)
length++; length++;
} }
} }
return length; return length;
} }
@@ -158,7 +158,7 @@ SInt32 skipUse(BBLMTextIterator &iter)
{ {
SInt32 length = 0; SInt32 length = 0;
UniChar ch; UniChar ch;
while ((ch = iter.GetNextChar())) while ((ch = iter.GetNextChar()))
{ {
if (islower(ch) || ch == ':' || ch == '_' || (length > 0 && isdigit(ch))) if (islower(ch) || ch == ':' || ch == '_' || (length > 0 && isdigit(ch)))
@@ -171,7 +171,7 @@ SInt32 skipUse(BBLMTextIterator &iter)
break; break;
} }
} }
return length; return length;
} }
@@ -181,7 +181,7 @@ SInt32 skipNumber(BBLMTextIterator &iter)
UniChar ch = iter.GetNextChar(); UniChar ch = iter.GetNextChar();
bool hasSuffix = false; bool hasSuffix = false;
int base = 10; int base = 10;
if (ch == '0') if (ch == '0')
{ {
ch = iter.GetNextChar(); ch = iter.GetNextChar();
@@ -210,7 +210,7 @@ SInt32 skipNumber(BBLMTextIterator &iter)
{ {
iter--; iter--;
} }
while ((ch = iter.GetNextChar())) while ((ch = iter.GetNextChar()))
{ {
if ((base == 10) && (isdigit(ch) || ((ch == '_' || ch == '.') && length > 0))) if ((base == 10) && (isdigit(ch) || ((ch == '_' || ch == '.') && length > 0)))
@@ -241,7 +241,7 @@ SInt32 skipNumber(BBLMTextIterator &iter)
break; break;
} }
} }
if (hasSuffix) if (hasSuffix)
{ {
if (iter.strcmp("8", 1) == 0) if (iter.strcmp("8", 1) == 0)
@@ -255,7 +255,7 @@ SInt32 skipNumber(BBLMTextIterator &iter)
length += 2; length += 2;
} }
} }
return length; return length;
} }
@@ -264,11 +264,11 @@ SInt32 skipToEndOfFunction(BBLMTextIterator &iter)
SInt32 length = 0; SInt32 length = 0;
UniChar ch; UniChar ch;
int braceLevel = 0, parenLevel = 0, bracketLevel = 0; int braceLevel = 0, parenLevel = 0, bracketLevel = 0;
while ((ch = iter.GetNextChar())) while ((ch = iter.GetNextChar()))
{ {
length++; length++;
switch (ch) { switch (ch) {
case '/': case '/':
ch = iter.GetNextChar(); ch = iter.GetNextChar();
@@ -287,34 +287,34 @@ SInt32 skipToEndOfFunction(BBLMTextIterator &iter)
iter--; iter--;
} }
break; break;
case '{': case '{':
braceLevel++; braceLevel++;
break; break;
case '}': case '}':
braceLevel--; braceLevel--;
if (braceLevel < 1) return length; if (braceLevel < 1) return length;
break; break;
case '(': case '(':
parenLevel++; parenLevel++;
break; break;
case ')': case ')':
parenLevel--; parenLevel--;
break; break;
case '[': case '[':
bracketLevel++; bracketLevel++;
break; break;
case ']': case ']':
bracketLevel--; bracketLevel--;
break; break;
} }
} }
return length; return length;
} }
@@ -327,7 +327,7 @@ SInt32 scanForSymbol(BBLMTextIterator &iter,
{ {
SInt32 whitespaceLen, wordLen; SInt32 whitespaceLen, wordLen;
int keywordLen = strlen(keyword); int keywordLen = strlen(keyword);
if (iter.strcmp(keyword, keywordLen) == 0) if (iter.strcmp(keyword, keywordLen) == 0)
{ {
iter += keywordLen; iter += keywordLen;
@@ -339,16 +339,16 @@ SInt32 scanForSymbol(BBLMTextIterator &iter,
UInt32 tokenOffset, funIndex; UInt32 tokenOffset, funIndex;
UInt32 nameLen; UInt32 nameLen;
BBLMProcInfo info; BBLMProcInfo info;
iter -= (wordLen + funLen); iter -= (wordLen + funLen);
nameLen = keywordLen + whitespaceLen + wordLen; nameLen = keywordLen + whitespaceLen + wordLen;
iter -= (keywordLen + whitespaceLen); iter -= (keywordLen + whitespaceLen);
bblmAddTokenToBuffer(callbacks, params.fFcnParams.fTokenBuffer, iter.Address(), bblmAddTokenToBuffer(callbacks, params.fFcnParams.fTokenBuffer, iter.Address(),
nameLen, &tokenOffset); nameLen, &tokenOffset);
iter += (nameLen - wordLen); iter += (nameLen - wordLen);
iter -= (keywordLen + whitespaceLen); iter -= (keywordLen + whitespaceLen);
info.fFirstChar = info.fFunctionStart = iter.Offset(); info.fFirstChar = info.fFunctionStart = iter.Offset();
info.fSelStart = iter.Offset() + keywordLen + whitespaceLen; info.fSelStart = iter.Offset() + keywordLen + whitespaceLen;
@@ -360,7 +360,7 @@ SInt32 scanForSymbol(BBLMTextIterator &iter,
info.fNameStart = tokenOffset; info.fNameStart = tokenOffset;
info.fNameLength = nameLen; info.fNameLength = nameLen;
bblmAddFunctionToList(callbacks, params.fFcnParams.fFcnList, info, &funIndex); bblmAddFunctionToList(callbacks, params.fFcnParams.fFcnList, info, &funIndex);
iter += (keywordLen + whitespaceLen); iter += (keywordLen + whitespaceLen);
return info.fFunctionEnd; return info.fFunctionEnd;
} }
@@ -374,7 +374,7 @@ SInt32 scanForSymbol(BBLMTextIterator &iter,
iter -= keywordLen; iter -= keywordLen;
} }
} }
return 0; return 0;
} }
@@ -384,24 +384,24 @@ static OSErr scanForFunctions(BBLMParamBlock &params, const BBLMCallbackBlock *c
UniChar ch; UniChar ch;
std::stack<int> indents; std::stack<int> indents;
SInt32 funEnd; SInt32 funEnd;
while ((ch = iter.GetNextChar())) while ((ch = iter.GetNextChar()))
{ {
while (!indents.empty() && iter.Offset() >= indents.top()) while (!indents.empty() && iter.Offset() >= indents.top())
{ {
indents.pop(); indents.pop();
} }
const char* symbolToScanFor = NULL; const char* symbolToScanFor = NULL;
int typeIfSo; int typeIfSo;
switch (ch) switch (ch)
{ {
case '"': case '"':
iter--; iter--;
skipString(iter); skipString(iter);
break; break;
case '/': case '/':
ch = iter.GetNextChar(); ch = iter.GetNextChar();
if (ch == '/') if (ch == '/')
@@ -419,38 +419,38 @@ static OSErr scanForFunctions(BBLMParamBlock &params, const BBLMCallbackBlock *c
iter--; iter--;
} }
break; break;
case 'e': case 'e':
symbolToScanFor = "enum"; symbolToScanFor = "enum";
typeIfSo = kBBLMFunctionMark; typeIfSo = kBBLMFunctionMark;
break; break;
case 'f': case 'f':
symbolToScanFor = "fn"; symbolToScanFor = "fn";
typeIfSo = kBBLMFunctionMark; typeIfSo = kBBLMFunctionMark;
break; break;
case 'i': case 'i':
symbolToScanFor = "impl"; symbolToScanFor = "impl";
typeIfSo = kBBLMTypedef; typeIfSo = kBBLMTypedef;
break; break;
case 'm': case 'm':
symbolToScanFor = "mod"; symbolToScanFor = "mod";
typeIfSo = kBBLMFunctionMark; typeIfSo = kBBLMFunctionMark;
break; break;
case 's': case 's':
symbolToScanFor = "struct"; symbolToScanFor = "struct";
typeIfSo = kBBLMFunctionMark; typeIfSo = kBBLMFunctionMark;
break; break;
case 't': case 't':
symbolToScanFor = "trait"; symbolToScanFor = "trait";
typeIfSo = kBBLMFunctionMark; typeIfSo = kBBLMFunctionMark;
break; break;
} }
if (symbolToScanFor != NULL) if (symbolToScanFor != NULL)
{ {
iter--; iter--;
@@ -464,7 +464,7 @@ static OSErr scanForFunctions(BBLMParamBlock &params, const BBLMCallbackBlock *c
} }
} }
} }
return noErr; return noErr;
} }
@@ -487,7 +487,7 @@ OSErr calculateRuns(BBLMParamBlock &params, const BBLMCallbackBlock *callbacks)
BBLMTextIterator iter(params, 0); BBLMTextIterator iter(params, 0);
SInt32 runStart = iter.Offset(); SInt32 runStart = iter.Offset();
SInt32 runLen; SInt32 runLen;
UniChar ch; UniChar ch;
bool wordchr = false; bool wordchr = false;
while ((ch = iter.GetNextChar())) while ((ch = iter.GetNextChar()))
@@ -501,7 +501,7 @@ OSErr calculateRuns(BBLMParamBlock &params, const BBLMCallbackBlock *callbacks)
if (!addRun(kBBLMDoubleQuotedStringRunKind, runStart, runLen, *callbacks)) return noErr; if (!addRun(kBBLMDoubleQuotedStringRunKind, runStart, runLen, *callbacks)) return noErr;
runStart = iter.Offset(); runStart = iter.Offset();
} }
// Have to distinguish the following things: // Have to distinguish the following things:
// 'a' (character) // 'a' (character)
// '\a' (escaped character) // '\a' (escaped character)
@@ -556,7 +556,7 @@ OSErr calculateRuns(BBLMParamBlock &params, const BBLMCallbackBlock *callbacks)
} }
} }
} }
else if (!wordchr && ch == 'm') else if (!wordchr && ch == 'm')
{ {
ch = iter.GetNextChar(); ch = iter.GetNextChar();
@@ -590,7 +590,7 @@ OSErr calculateRuns(BBLMParamBlock &params, const BBLMCallbackBlock *callbacks)
iter--; iter--;
} }
} }
else if (!wordchr && ch == 'f') else if (!wordchr && ch == 'f')
{ {
ch = iter.GetNextChar(); ch = iter.GetNextChar();
@@ -616,7 +616,7 @@ OSErr calculateRuns(BBLMParamBlock &params, const BBLMCallbackBlock *callbacks)
iter--; iter--;
} }
} }
else if (!wordchr && ch == 'u') else if (!wordchr && ch == 'u')
{ {
ch = iter.GetNextChar(); ch = iter.GetNextChar();
@@ -633,11 +633,11 @@ OSErr calculateRuns(BBLMParamBlock &params, const BBLMCallbackBlock *callbacks)
runLen = skipWhitespace(iter); runLen = skipWhitespace(iter);
runLen += skipUse(iter); runLen += skipUse(iter);
if (!addRun(kBBLMFileIncludeRunKind, runStart, runLen, *callbacks)) return noErr; if (!addRun(kBBLMFileIncludeRunKind, runStart, runLen, *callbacks)) return noErr;
runStart = iter.Offset(); runStart = iter.Offset();
runLen = skipWord(iter); runLen = skipWord(iter);
if (!addRun(identifierColour, runStart, runLen, *callbacks)) return noErr; if (!addRun(identifierColour, runStart, runLen, *callbacks)) return noErr;
runStart = iter.Offset(); runStart = iter.Offset();
} }
else if (ch) else if (ch)
@@ -655,7 +655,7 @@ OSErr calculateRuns(BBLMParamBlock &params, const BBLMCallbackBlock *callbacks)
iter--; iter--;
} }
} }
else if (ch == '/') else if (ch == '/')
{ {
ch = iter.GetNextChar(); ch = iter.GetNextChar();
@@ -682,7 +682,7 @@ OSErr calculateRuns(BBLMParamBlock &params, const BBLMCallbackBlock *callbacks)
iter--; iter--;
} }
} }
else if (ch == '#') else if (ch == '#')
{ {
iter--; iter--;
@@ -692,7 +692,7 @@ OSErr calculateRuns(BBLMParamBlock &params, const BBLMCallbackBlock *callbacks)
if (!addRun(attributeColour, runStart, runLen, *callbacks)) return noErr; if (!addRun(attributeColour, runStart, runLen, *callbacks)) return noErr;
runStart = iter.Offset(); runStart = iter.Offset();
} }
else if (!wordchr && isupper(ch)) else if (!wordchr && isupper(ch))
{ {
iter--; iter--;
@@ -702,7 +702,7 @@ OSErr calculateRuns(BBLMParamBlock &params, const BBLMCallbackBlock *callbacks)
if (!addRun(identifierColour, runStart, runLen, *callbacks)) return noErr; if (!addRun(identifierColour, runStart, runLen, *callbacks)) return noErr;
runStart = iter.Offset(); runStart = iter.Offset();
} }
else if (!wordchr && (ch == '+' || ch == '-')) else if (!wordchr && (ch == '+' || ch == '-'))
{ {
ch = iter.GetNextChar(); ch = iter.GetNextChar();
@@ -721,7 +721,7 @@ OSErr calculateRuns(BBLMParamBlock &params, const BBLMCallbackBlock *callbacks)
iter--; iter--;
} }
} }
else if (!wordchr && isdigit(ch)) else if (!wordchr && isdigit(ch))
{ {
iter--; iter--;
@@ -731,10 +731,10 @@ OSErr calculateRuns(BBLMParamBlock &params, const BBLMCallbackBlock *callbacks)
if (!addRun(kBBLMNumberRunKind, runStart, runLen, *callbacks)) return noErr; if (!addRun(kBBLMNumberRunKind, runStart, runLen, *callbacks)) return noErr;
runStart = iter.Offset(); runStart = iter.Offset();
} }
wordchr = isalpha(ch) || isdigit(ch); wordchr = isalpha(ch) || isdigit(ch);
} }
makeCodeRun(iter, runStart, *callbacks); makeCodeRun(iter, runStart, *callbacks);
return noErr; return noErr;
} }
@@ -756,12 +756,12 @@ OSErr adjustRange(BBLMParamBlock &params, const BBLMCallbackBlock &callbacks)
SInt32 charPos; SInt32 charPos;
SInt32 length; SInt32 length;
UInt32 index = params.fAdjustRangeParams.fStartIndex; UInt32 index = params.fAdjustRangeParams.fStartIndex;
while (index > 0 && bblmGetRun(&callbacks, index, language, kind, charPos, length)/* && isSpecialKind(kind)*/) while (index > 0 && bblmGetRun(&callbacks, index, language, kind, charPos, length)/* && isSpecialKind(kind)*/)
{ {
index--; index--;
} }
params.fAdjustRangeParams.fStartIndex = index; params.fAdjustRangeParams.fStartIndex = index;
return noErr; return noErr;
} }
@@ -769,12 +769,12 @@ OSErr adjustRange(BBLMParamBlock &params, const BBLMCallbackBlock &callbacks)
OSErr guessLanguage(BBLMParamBlock &params) OSErr guessLanguage(BBLMParamBlock &params)
{ {
BBLMTextIterator iter(params); BBLMTextIterator iter(params);
if (iter.strcmp("use ", 4) == 0 || iter.strcmp("#![crate_id", 11) == 0) if (iter.strcmp("use ", 4) == 0 || iter.strcmp("#![crate_id", 11) == 0)
{ {
params.fGuessLanguageParams.fGuessResult = kBBLMGuessDefiniteYes; params.fGuessLanguageParams.fGuessResult = kBBLMGuessDefiniteYes;
} }
return noErr; return noErr;
} }
@@ -787,29 +787,29 @@ extern "C"
{ {
// Dispatch message. // Dispatch message.
OSErr result = noErr; OSErr result = noErr;
switch (params.fMessage) switch (params.fMessage)
{ {
case kBBLMDisposeMessage: case kBBLMDisposeMessage:
case kBBLMSetCategoriesMessage: case kBBLMSetCategoriesMessage:
// Message understood, but no action required. // Message understood, but no action required.
break; break;
case kBBLMInitMessage: case kBBLMInitMessage:
break; break;
case kBBLMScanForFunctionsMessage: case kBBLMScanForFunctionsMessage:
result = scanForFunctions(params, &bblmCallbacks); result = scanForFunctions(params, &bblmCallbacks);
break; break;
case kBBLMCalculateRunsMessage: case kBBLMCalculateRunsMessage:
result = calculateRuns(params, &bblmCallbacks); result = calculateRuns(params, &bblmCallbacks);
break; break;
case kBBLMGuessLanguageMessage: case kBBLMGuessLanguageMessage:
result = guessLanguage(params); result = guessLanguage(params);
break; break;
case kBBLMAdjustRangeMessage: case kBBLMAdjustRangeMessage:
result = adjustRange(params, bblmCallbacks); result = adjustRange(params, bblmCallbacks);
break; break;
@@ -817,7 +817,7 @@ extern "C"
default: default:
result = paramErr; result = paramErr;
} }
return result; return result;
} }
} }