Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af4c34887f | ||
|
|
c8ebb59385 | ||
|
|
6668052266 | ||
|
|
91d69de57f | ||
|
|
01998a20bc | ||
|
|
4743bab662 | ||
|
|
41fcd43e6d | ||
|
|
50498ece46 | ||
|
|
b68e3e3b77 | ||
|
|
2a73fb8f72 |
@@ -15,7 +15,7 @@ By default, it highlights anything beginning with a capital letter in a certain
|
|||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
|
|
||||||
The simplest way is to just download the package and put it in this folder:
|
The simplest way is to just [download the package](https://github.com/ogham/Rust.bblm/releases/tag/0.1) and put it in this folder:
|
||||||
|
|
||||||
~/Application Support/BBEdit/Language Modules
|
~/Application Support/BBEdit/Language Modules
|
||||||
|
|
||||||
|
|||||||
22
info.plist
22
info.plist
@@ -46,10 +46,14 @@
|
|||||||
<key>me.bsago.bblm.rust.attribute</key>
|
<key>me.bsago.bblm.rust.attribute</key>
|
||||||
<string>#[attribute]</string>
|
<string>#[attribute]</string>
|
||||||
<key>me.bsago.bblm.rust.function</key>
|
<key>me.bsago.bblm.rust.function</key>
|
||||||
<string>fn function</string>
|
<string>fn functionname</string>
|
||||||
|
<key>me.bsago.bblm.rust.module</key>
|
||||||
|
<string>mod modulename</string>
|
||||||
</dict>
|
</dict>
|
||||||
<key>BBLMRunColors</key>
|
<key>BBLMRunColors</key>
|
||||||
<dict>
|
<dict>
|
||||||
|
<key>me.bsago.bblm.rust.module</key>
|
||||||
|
<string>rgb(135, 2, 219)</string>
|
||||||
<key>me.bsago.bblm.rust.lifetime</key>
|
<key>me.bsago.bblm.rust.lifetime</key>
|
||||||
<string>rgb(133, 20, 75)</string>
|
<string>rgb(133, 20, 75)</string>
|
||||||
<key>me.bsago.bblm.rust.attribute</key>
|
<key>me.bsago.bblm.rust.attribute</key>
|
||||||
@@ -69,6 +73,7 @@
|
|||||||
<string>as</string>
|
<string>as</string>
|
||||||
<string>box</string>
|
<string>box</string>
|
||||||
<string>break</string>
|
<string>break</string>
|
||||||
|
<string>const</string>
|
||||||
<string>continue</string>
|
<string>continue</string>
|
||||||
<string>crate</string>
|
<string>crate</string>
|
||||||
<string>else</string>
|
<string>else</string>
|
||||||
@@ -108,37 +113,22 @@
|
|||||||
<string>com.barebones.bblm.predefined-symbol</string>
|
<string>com.barebones.bblm.predefined-symbol</string>
|
||||||
<key>Keywords</key>
|
<key>Keywords</key>
|
||||||
<array>
|
<array>
|
||||||
<string>assert</string>
|
|
||||||
<string>bool</string>
|
<string>bool</string>
|
||||||
<string>char</string>
|
<string>char</string>
|
||||||
<string>debug</string>
|
|
||||||
<string>env</string>
|
|
||||||
<string>error</string>
|
|
||||||
<string>externfn</string>
|
|
||||||
<string>f32</string>
|
<string>f32</string>
|
||||||
<string>f64</string>
|
<string>f64</string>
|
||||||
<string>fail</string>
|
|
||||||
<string>float</string>
|
<string>float</string>
|
||||||
<string>fmt</string>
|
|
||||||
<string>i16</string>
|
<string>i16</string>
|
||||||
<string>i32</string>
|
<string>i32</string>
|
||||||
<string>i64</string>
|
<string>i64</string>
|
||||||
<string>i8</string>
|
<string>i8</string>
|
||||||
<string>include</string>
|
|
||||||
<string>include_bin</string>
|
|
||||||
<string>include_str</string>
|
|
||||||
<string>info</string>
|
|
||||||
<string>int</string>
|
<string>int</string>
|
||||||
<string>proto</string>
|
|
||||||
<string>str</string>
|
<string>str</string>
|
||||||
<string>stringify</string>
|
|
||||||
<string>u16</string>
|
<string>u16</string>
|
||||||
<string>u32</string>
|
<string>u32</string>
|
||||||
<string>u64</string>
|
<string>u64</string>
|
||||||
<string>u8</string>
|
<string>u8</string>
|
||||||
<string>uint</string>
|
<string>uint</string>
|
||||||
<string>vec</string>
|
|
||||||
<string>warn</string>
|
|
||||||
</array>
|
</array>
|
||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
|
|||||||
195
rust.mm
195
rust.mm
@@ -14,6 +14,7 @@ static NSString* const identifierColour = @"me.bsago.bblm.rust.identifier";
|
|||||||
static NSString* const attributeColour = @"me.bsago.bblm.rust.attribute";
|
static NSString* const attributeColour = @"me.bsago.bblm.rust.attribute";
|
||||||
static NSString* const lifetimeColour = @"me.bsago.bblm.rust.lifetime";
|
static NSString* const lifetimeColour = @"me.bsago.bblm.rust.lifetime";
|
||||||
static NSString* const functionColour = @"me.bsago.bblm.rust.function";
|
static NSString* const functionColour = @"me.bsago.bblm.rust.function";
|
||||||
|
static NSString* const moduleColour = @"me.bsago.bblm.rust.module";
|
||||||
|
|
||||||
static bool addRun(NSString *kind, int start,int len , const BBLMCallbackBlock& bblm_callbacks)
|
static bool addRun(NSString *kind, int start,int len , const BBLMCallbackBlock& bblm_callbacks)
|
||||||
{
|
{
|
||||||
@@ -153,15 +154,78 @@ SInt32 skipAttribute(BBLMTextIterator &iter)
|
|||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
SInt32 skipNumber(BBLMTextIterator &iter)
|
SInt32 skipUse(BBLMTextIterator &iter)
|
||||||
{
|
{
|
||||||
UInt32 length = 0;
|
SInt32 length = 0;
|
||||||
UniChar ch;
|
UniChar ch;
|
||||||
bool hasSuffix = false;
|
|
||||||
|
|
||||||
while ((ch = iter.GetNextChar()))
|
while ((ch = iter.GetNextChar()))
|
||||||
{
|
{
|
||||||
if (isdigit(ch) || (ch == '_' && length > 0))
|
if (islower(ch) || ch == ':' || ch == '_' || (length > 0 && isdigit(ch)))
|
||||||
|
{
|
||||||
|
length++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
iter--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
SInt32 skipNumber(BBLMTextIterator &iter)
|
||||||
|
{
|
||||||
|
UInt32 length = 0;
|
||||||
|
UniChar ch = iter.GetNextChar();
|
||||||
|
bool hasSuffix = false;
|
||||||
|
int base = 10;
|
||||||
|
|
||||||
|
if (ch == '0')
|
||||||
|
{
|
||||||
|
ch = iter.GetNextChar();
|
||||||
|
if (ch == 'x')
|
||||||
|
{
|
||||||
|
base = 16;
|
||||||
|
length += 2;
|
||||||
|
}
|
||||||
|
else if (ch == 'b')
|
||||||
|
{
|
||||||
|
base = 2;
|
||||||
|
length += 2;
|
||||||
|
}
|
||||||
|
else if (ch == 'o')
|
||||||
|
{
|
||||||
|
base = 8;
|
||||||
|
length += 2;
|
||||||
|
}
|
||||||
|
else if (ch)
|
||||||
|
{
|
||||||
|
length++;
|
||||||
|
iter--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ch)
|
||||||
|
{
|
||||||
|
iter--;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((ch = iter.GetNextChar()))
|
||||||
|
{
|
||||||
|
if ((base == 10) && (isdigit(ch) || ((ch == '_' || ch == '.') && length > 0)))
|
||||||
|
{
|
||||||
|
length++;
|
||||||
|
}
|
||||||
|
else if ((base == 2) && (ch == '0' || ch == '1'))
|
||||||
|
{
|
||||||
|
length++;
|
||||||
|
}
|
||||||
|
else if ((base == 8) && (ch >= '0' && ch <= '7'))
|
||||||
|
{
|
||||||
|
length++;
|
||||||
|
}
|
||||||
|
else if ((base == 16) && ((ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F') || isdigit(ch)))
|
||||||
{
|
{
|
||||||
length++;
|
length++;
|
||||||
}
|
}
|
||||||
@@ -492,18 +556,99 @@ OSErr calculateRuns(BBLMParamBlock ¶ms, const BBLMCallbackBlock *callbacks)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (!wordchr && ch == 'm')
|
||||||
|
{
|
||||||
|
ch = iter.GetNextChar();
|
||||||
|
if (ch == 'o')
|
||||||
|
{
|
||||||
|
ch = iter.GetNextChar();
|
||||||
|
if (ch == 'd')
|
||||||
|
{
|
||||||
|
ch = iter.GetNextChar();
|
||||||
|
if (isspace(ch))
|
||||||
|
{
|
||||||
|
if (!makeCodeRun(iter, runStart, *callbacks)) return noErr;
|
||||||
|
runStart = iter.Offset();
|
||||||
|
runLen = skipWhitespace(iter);
|
||||||
|
runLen += skipWord(iter);
|
||||||
|
if (!addRun(moduleColour, runStart, runLen, *callbacks)) return noErr;
|
||||||
|
runStart = iter.Offset();
|
||||||
|
}
|
||||||
|
else if (ch)
|
||||||
|
{
|
||||||
|
iter--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ch)
|
||||||
|
{
|
||||||
|
iter--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ch)
|
||||||
|
{
|
||||||
|
iter--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
else if (ch == 'f')
|
else if (!wordchr && ch == 'f')
|
||||||
{
|
{
|
||||||
ch = iter.GetNextChar();
|
ch = iter.GetNextChar();
|
||||||
if (ch == 'n')
|
if (ch == 'n')
|
||||||
{
|
{
|
||||||
if (!makeCodeRun(iter, runStart, *callbacks)) return noErr;
|
ch = iter.GetNextChar();
|
||||||
runStart = iter.Offset();
|
if (isspace(ch))
|
||||||
runLen = skipWhitespace(iter);
|
{
|
||||||
runLen += skipWord(iter);
|
if (!makeCodeRun(iter, runStart, *callbacks)) return noErr;
|
||||||
if (!addRun(functionColour, runStart, runLen, *callbacks)) return noErr;
|
runStart = iter.Offset();
|
||||||
runStart = iter.Offset();
|
runLen = skipWhitespace(iter);
|
||||||
|
runLen += skipWord(iter);
|
||||||
|
if (!addRun(functionColour, runStart, runLen, *callbacks)) return noErr;
|
||||||
|
runStart = iter.Offset();
|
||||||
|
}
|
||||||
|
else if (ch)
|
||||||
|
{
|
||||||
|
iter--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ch)
|
||||||
|
{
|
||||||
|
iter--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (!wordchr && ch == 'u')
|
||||||
|
{
|
||||||
|
ch = iter.GetNextChar();
|
||||||
|
if (ch == 's')
|
||||||
|
{
|
||||||
|
ch = iter.GetNextChar();
|
||||||
|
if (ch == 'e')
|
||||||
|
{
|
||||||
|
ch = iter.GetNextChar();
|
||||||
|
if (isspace(ch))
|
||||||
|
{
|
||||||
|
if (!makeCodeRun(iter, runStart, *callbacks)) return noErr;
|
||||||
|
runStart = iter.Offset();
|
||||||
|
runLen = skipWhitespace(iter);
|
||||||
|
runLen += skipUse(iter);
|
||||||
|
if (!addRun(kBBLMFileIncludeRunKind, runStart, runLen, *callbacks)) return noErr;
|
||||||
|
|
||||||
|
runStart = iter.Offset();
|
||||||
|
runLen = skipWord(iter);
|
||||||
|
if (!addRun(identifierColour, runStart, runLen, *callbacks)) return noErr;
|
||||||
|
|
||||||
|
runStart = iter.Offset();
|
||||||
|
}
|
||||||
|
else if (ch)
|
||||||
|
{
|
||||||
|
iter--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ch)
|
||||||
|
{
|
||||||
|
iter--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (ch)
|
else if (ch)
|
||||||
{
|
{
|
||||||
@@ -558,6 +703,25 @@ OSErr calculateRuns(BBLMParamBlock ¶ms, const BBLMCallbackBlock *callbacks)
|
|||||||
runStart = iter.Offset();
|
runStart = iter.Offset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (!wordchr && (ch == '+' || ch == '-'))
|
||||||
|
{
|
||||||
|
ch = iter.GetNextChar();
|
||||||
|
if (isdigit(ch))
|
||||||
|
{
|
||||||
|
iter -= 2;
|
||||||
|
if (!makeCodeRun(iter, runStart, *callbacks)) return noErr;
|
||||||
|
iter++;
|
||||||
|
runStart = iter.Offset() - 1;
|
||||||
|
runLen = skipNumber(iter) + 1;
|
||||||
|
if (!addRun(kBBLMNumberRunKind, runStart, runLen, *callbacks)) return noErr;
|
||||||
|
runStart = iter.Offset();
|
||||||
|
}
|
||||||
|
else if (ch)
|
||||||
|
{
|
||||||
|
iter--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
else if (!wordchr && isdigit(ch))
|
else if (!wordchr && isdigit(ch))
|
||||||
{
|
{
|
||||||
iter--;
|
iter--;
|
||||||
@@ -575,14 +739,15 @@ OSErr calculateRuns(BBLMParamBlock ¶ms, const BBLMCallbackBlock *callbacks)
|
|||||||
return noErr;
|
return noErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isSpecialKind(NSString* kind)
|
/*static bool isSpecialKind(NSString* kind)
|
||||||
{
|
{
|
||||||
return [kBBLMBlockCommentRunKind isEqualToString:kind]
|
return [kBBLMBlockCommentRunKind isEqualToString:kind]
|
||||||
|| [kBBLMLineCommentRunKind isEqualToString:kind]
|
|| [kBBLMLineCommentRunKind isEqualToString:kind]
|
||||||
|| [identifierColour isEqualToString:kind]
|
|| [identifierColour isEqualToString:kind]
|
||||||
|| [attributeColour isEqualToString:kind]
|
|| [attributeColour isEqualToString:kind]
|
||||||
|| [lifetimeColour isEqualToString:kind];
|
|| [lifetimeColour isEqualToString:kind]
|
||||||
}
|
|| [functionColour isEqualToString:kind];
|
||||||
|
}*/
|
||||||
|
|
||||||
OSErr adjustRange(BBLMParamBlock ¶ms, const BBLMCallbackBlock &callbacks)
|
OSErr adjustRange(BBLMParamBlock ¶ms, const BBLMCallbackBlock &callbacks)
|
||||||
{
|
{
|
||||||
@@ -592,7 +757,7 @@ OSErr adjustRange(BBLMParamBlock ¶ms, const BBLMCallbackBlock &callbacks)
|
|||||||
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--;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user