8 Commits
0.3.1 ... 0.4.0

Author SHA1 Message Date
Ben S
6bc2dac873 Another version bump! 2015-05-03 12:25:52 +01:00
Ben S
07b020f253 Detab the plist 2015-05-03 12:24:31 +01:00
Ben S
ec10c4bf7f Add loads more built-in types 2015-05-03 12:24:22 +01:00
Ben S
e28267063f Update README 2015-03-16 22:02:24 +00:00
Ben S
adbf51d973 Add code folding!
Also, fix weird-looking function definitions.
2015-03-16 21:49:15 +00:00
Ben S
439556cbe4 Check end of word after scanning functions
'enumerate' is not 'enum' with some bits after it!
2015-03-16 18:35:00 +00:00
Ben S
0fe7412e14 Parse definitions with lifetimes correctly
This is actually achieved by making the parsing *more lenient* instead of more strict. The view looks more cluttered as a result, but at least it's *correct*. Nothing I can do about the clutter, as far as I know - BBEdit only allows us to use substrings of the document in the menu, so I can't strip out the lifetimes.
2015-03-16 18:19:56 +00:00
Ben S
565243f64b Update screenshot 2015-02-21 13:44:55 +00:00
4 changed files with 285 additions and 222 deletions

View File

@@ -7,17 +7,18 @@ This is a BBEdit 11 Language Module for [Rust](http://www.rust-lang.org). It pro
- Complete syntax highlighting
- Special support for lifetimes, attributes, and identifiers
- Customisable colours using the [BBEdit 11 colour thing](http://barebones.com/products/bbedit/bbedit11.html)
- Customisable colours using the [BBEdit 11 colour editor](http://barebones.com/products/bbedit/bbedit11.html)
- Language features
- Go to start of/end of/previous/next function
- Go to named symbol
- Indexed function menu
- Code folding
By default, it highlights anything beginning with a capital letter in a certain colour. To turn this off, just change the Identifier colour to be the same as the default text colour in Preferences.
### Installation
The simplest way is to just [download the package](https://github.com/ogham/Rust.bblm/releases/tag/0.3.1) and put it in this folder:
The simplest way is to just [download the package](https://github.com/ogham/Rust.bblm/releases/tag/0.4.0) and put it in this folder:
~/Application Support/BBEdit/Language Modules

View File

@@ -2,178 +2,205 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>me.bsago.bblm.rust</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleSignature</key>
<string>BBLM</string>
<key>CFBundleVersion</key>
<string>8.0</string>
<key>CSResourcesFileMapped</key>
<true/>
<key>com.barebones.bblminfo</key>
<array>
<dict>
<key>BBLMCanGuessLanguage</key>
<true/>
<key>BBLMColorsSyntax</key>
<true/>
<key>BBLMDroppedFilePathStyle</key>
<string>POSIX</string>
<key>BBLMCommentLineDefault</key>
<string>// </string>
<key>BBLMCommentPrefixDefault</key>
<string>/* </string>
<key>BBLMCommentSuffixDefault</key>
<string> */</string>
<key>BBLMIsCaseSensitive</key>
<true/>
<key>BBLMRunNames</key>
<dict>
<key>me.bsago.bblm.rust.lifetime</key>
<string>&apos;lifetime</string>
<key>me.bsago.bblm.rust.identifier</key>
<string>Identifier</string>
<key>me.bsago.bblm.rust.function</key>
<string>fn functionname</string>
<key>me.bsago.bblm.rust.module</key>
<string>mod modulename</string>
</dict>
<key>BBLMRunColors</key>
<dict>
<key>me.bsago.bblm.rust.module</key>
<string>rgb(135, 2, 219)</string>
<key>me.bsago.bblm.rust.lifetime</key>
<string>rgb(133, 20, 75)</string>
<key>me.bsago.bblm.rust.identifier</key>
<string>rgb(61, 153, 112)</string>
<key>me.bsago.bblm.rust.function</key>
<string>rgb(219, 135, 2)</string>
</dict>
<key>BBLMKeywords</key>
<array>
<dict>
<key>RunKind</key>
<string>com.barebones.bblm.keyword</string>
<key>Keywords</key>
<array>
<string>abstract</string>
<string>alignof</string>
<string>as</string>
<string>become</string>
<string>box</string>
<string>break</string>
<string>const</string>
<string>continue</string>
<string>crate</string>
<string>do</string>
<string>else</string>
<string>enum</string>
<string>extern</string>
<string>false</string>
<string>final</string>
<string>fn</string>
<string>for</string>
<string>if</string>
<string>impl</string>
<string>in</string>
<string>let</string>
<string>loop</string>
<string>macro</string>
<string>macro_rules</string>
<string>match</string>
<string>mod</string>
<string>move</string>
<string>mut</string>
<string>offsetof</string>
<string>override</string>
<string>priv</string>
<string>proc</string>
<string>pub</string>
<string>pure</string>
<string>ref</string>
<string>return</string>
<string>self</string>
<string>sizeof</string>
<string>static</string>
<string>struct</string>
<string>super</string>
<string>trait</string>
<string>true</string>
<string>type</string>
<string>typeof</string>
<string>unsafe</string>
<string>unsized</string>
<string>use</string>
<string>virtual</string>
<string>where</string>
<string>while</string>
<string>yield</string>
</array>
</dict>
<dict>
<key>RunKind</key>
<string>com.barebones.bblm.predefined-symbol</string>
<key>Keywords</key>
<array>
<string>bool</string>
<string>char</string>
<string>f32</string>
<string>f64</string>
<string>float</string>
<string>i16</string>
<string>i32</string>
<string>i64</string>
<string>i8</string>
<string>isize</string>
<string>str</string>
<string>u16</string>
<string>u32</string>
<string>u64</string>
<string>u8</string>
<string>usize</string>
</array>
</dict>
</array>
<key>BBLMLanguageCode</key>
<string>Rust</string>
<key>BBLMLanguageDisplayName</key>
<string>Rust</string>
<key>BBLMEntryPointName</key>
<string>rustMain</string>
<key>BBLMScansFunctions</key>
<true/>
<key>BBLMFunctionScannerDoesFoldsToo</key>
<false/>
<key>BBLMSuffixMap</key>
<array>
<dict>
<key>BBLMLanguageSuffix</key>
<string>.rs</string>
</dict>
</array>
<key>BBLMUseHTMLFileSearchRules</key>
<false/>
<key>BBLMSpellableRunKinds</key>
<array>
<string>com.barebones.bblm.line-comment</string>
<string>com.barebones.bblm.block-comment</string>
</array>
<key>BBLMNonSpellableRunKinds</key>
<array>
<string>com.barebones.bblm.code</string>
<string>com.barebones.bblm.double-string</string>
</array>
</dict>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>me.bsago.bblm.rust</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleSignature</key>
<string>BBLM</string>
<key>CFBundleVersion</key>
<string>8.0</string>
<key>CSResourcesFileMapped</key>
<true/>
<key>com.barebones.bblminfo</key>
<array>
<dict>
<key>BBLMCanGuessLanguage</key>
<true/>
<key>BBLMColorsSyntax</key>
<true/>
<key>BBLMDroppedFilePathStyle</key>
<string>POSIX</string>
<key>BBLMCommentLineDefault</key>
<string>// </string>
<key>BBLMCommentPrefixDefault</key>
<string>/* </string>
<key>BBLMCommentSuffixDefault</key>
<string> */</string>
<key>BBLMIsCaseSensitive</key>
<true/>
<key>BBLMRunNames</key>
<dict>
<key>me.bsago.bblm.rust.lifetime</key>
<string>&apos;lifetime</string>
<key>me.bsago.bblm.rust.identifier</key>
<string>Identifier</string>
<key>me.bsago.bblm.rust.function</key>
<string>fn functionname</string>
<key>me.bsago.bblm.rust.module</key>
<string>mod modulename</string>
</dict>
<key>BBLMRunColors</key>
<dict>
<key>me.bsago.bblm.rust.module</key>
<string>rgb(135, 2, 219)</string>
<key>me.bsago.bblm.rust.lifetime</key>
<string>rgb(133, 20, 75)</string>
<key>me.bsago.bblm.rust.identifier</key>
<string>rgb(61, 153, 112)</string>
<key>me.bsago.bblm.rust.function</key>
<string>rgb(219, 135, 2)</string>
</dict>
<key>BBLMKeywords</key>
<array>
<dict>
<key>RunKind</key>
<string>com.barebones.bblm.keyword</string>
<key>Keywords</key>
<array>
<string>abstract</string>
<string>alignof</string>
<string>as</string>
<string>become</string>
<string>box</string>
<string>break</string>
<string>const</string>
<string>continue</string>
<string>crate</string>
<string>do</string>
<string>else</string>
<string>enum</string>
<string>extern</string>
<string>false</string>
<string>final</string>
<string>fn</string>
<string>for</string>
<string>if</string>
<string>impl</string>
<string>in</string>
<string>let</string>
<string>loop</string>
<string>macro</string>
<string>macro_rules</string>
<string>match</string>
<string>mod</string>
<string>move</string>
<string>mut</string>
<string>offsetof</string>
<string>override</string>
<string>priv</string>
<string>proc</string>
<string>pub</string>
<string>pure</string>
<string>ref</string>
<string>return</string>
<string>self</string>
<string>sizeof</string>
<string>static</string>
<string>struct</string>
<string>super</string>
<string>trait</string>
<string>true</string>
<string>type</string>
<string>typeof</string>
<string>unsafe</string>
<string>unsized</string>
<string>use</string>
<string>virtual</string>
<string>where</string>
<string>while</string>
<string>yield</string>
</array>
</dict>
<dict>
<key>RunKind</key>
<string>com.barebones.bblm.predefined-symbol</string>
<key>Keywords</key>
<array>
<string>blkcnt_t</string>
<string>blksize_t</string>
<string>bool</string>
<string>c_char</string>
<string>c_double</string>
<string>c_float</string>
<string>c_int</string>
<string>c_long</string>
<string>c_schar</string>
<string>c_short</string>
<string>c_uchar</string>
<string>c_uint</string>
<string>c_ulong</string>
<string>c_ushort</string>
<string>char</string>
<string>clock_t</string>
<string>dev_t</string>
<string>f32</string>
<string>f64</string>
<string>float</string>
<string>gid_t</string>
<string>i16</string>
<string>i32</string>
<string>i64</string>
<string>i8</string>
<string>ino_t</string>
<string>isize</string>
<string>mode_t</string>
<string>nlink_t</string>
<string>off_t</string>
<string>pid_t</string>
<string>ptrdiff_t</string>
<string>size_t</string>
<string>str</string>
<string>suseconds_t</string>
<string>time_t</string>
<string>u16</string>
<string>u32</string>
<string>u64</string>
<string>u8</string>
<string>uid_t</string>
<string>usize</string>
<string>wchar_t</string>
</array>
</dict>
</array>
<key>BBLMLanguageCode</key>
<string>Rust</string>
<key>BBLMLanguageDisplayName</key>
<string>Rust</string>
<key>BBLMEntryPointName</key>
<string>rustMain</string>
<key>BBLMScansFunctions</key>
<true/>
<key>BBLMFunctionScannerDoesFoldsToo</key>
<true/>
<key>BBLMSuffixMap</key>
<array>
<dict>
<key>BBLMLanguageSuffix</key>
<string>.rs</string>
</dict>
</array>
<key>BBLMUseHTMLFileSearchRules</key>
<false/>
<key>BBLMSpellableRunKinds</key>
<array>
<string>com.barebones.bblm.line-comment</string>
<string>com.barebones.bblm.block-comment</string>
</array>
<key>BBLMNonSpellableRunKinds</key>
<array>
<string>com.barebones.bblm.code</string>
<string>com.barebones.bblm.double-string</string>
</array>
</dict>
</array>
</dict>
</plist>

129
rust.mm
View File

@@ -386,70 +386,105 @@ SInt32 scanForSymbol(BBLMTextIterator &iter,
BBLMParamBlock &params,
const BBLMCallbackBlock *callbacks)
{
SInt32 whitespaceLen, wordLen;
SInt32 whitespaceLen, wordLen = 0, parametersLen = 0;
UniChar ch;
int keywordLen = strlen(keyword);
if (iter.strcmp(keyword, keywordLen) == 0)
{
iter += keywordLen;
if ((whitespaceLen = skipWhitespace(iter)))
// Check for end of word, so 'enum' doesn't also match 'enumerate'.
// But also check for '<', so 'impl<'a>' is a legit statement, even with no whitespace.
whitespaceLen = skipWhitespace(iter);
if (whitespaceLen == 0 && iter.strcmp("<", 1) != 0)
{
bool is_test = iter.strcmp("test", 4) == 0;
if ((wordLen = skipWord(iter)))
iter -= keywordLen + whitespaceLen;
return 0;
}
SInt32 start_of_name = iter.Offset();
SInt32 start_of_function;
while ((ch = iter.GetNextChar()))
{
if (ch == '{' || ch == ';')
{
UInt32 funLen = skipToEndOfFunction(iter);
// Skip over trait method definitions and extern functions
if (funLen == 0)
iter--;
start_of_function = iter.Offset();
break;
}
else if (ch == '(')
{
while ((ch = iter.GetNextChar()))
{
return 0;
whitespaceLen++;
if (ch == '{' || ch == ';')
{
break;
}
}
// Ignore modules called 'test'
if (strcmp(keyword, "mod") == 0 && is_test)
{
return 0;
}
UInt32 tokenOffset, funIndex;
UInt32 nameLen;
BBLMProcInfo info;
iter -= (wordLen + funLen);
iter -= (keywordLen + whitespaceLen);
nameLen = keywordLen + whitespaceLen + wordLen;
bblmAddTokenToBuffer(callbacks, params.fFcnParams.fTokenBuffer, iter.Address(),
nameLen, &tokenOffset);
iter += (nameLen - wordLen);
iter -= (keywordLen + whitespaceLen);
info.fFirstChar = info.fFunctionStart = iter.Offset();
info.fSelStart = iter.Offset() + keywordLen + whitespaceLen;
info.fSelEnd = info.fSelStart + wordLen;
info.fFunctionEnd = info.fSelEnd + funLen;
info.fIndentLevel = indentLevel;
info.fKind = typeIfSo;
info.fFlags = 0;
info.fNameStart = tokenOffset;
info.fNameLength = nameLen;
bblmAddFunctionToList(callbacks, params.fFcnParams.fFcnList, info, &funIndex);
bblmAddFoldRange(callbacks, info.fFunctionStart, funLen, kBBLMFunctionAutoFold);
iter += (keywordLen + whitespaceLen);
return info.fFunctionEnd;
iter--;
start_of_function = iter.Offset();
break;
}
else if (ch == '\n')
{
start_of_function = iter.Offset();
break;
}
else if (ch)
{
whitespaceLen++;
}
else
{
iter -= (whitespaceLen + keywordLen);
return 0;
}
}
else
UInt32 funLen = skipToEndOfFunction(iter);
// Skip over trait method definitions and extern functions
if (funLen == 0)
{
iter -= keywordLen;
return 0;
}
UInt32 tokenOffset, funIndex;
UInt32 nameLen;
iter -= (wordLen + funLen);
iter -= (keywordLen + whitespaceLen);
nameLen = keywordLen + whitespaceLen + wordLen;
bblmAddTokenToBuffer(callbacks, params.fFcnParams.fTokenBuffer, iter.Address(),
nameLen, &tokenOffset);
iter += (nameLen - wordLen);
iter -= (keywordLen + whitespaceLen);
BBLMProcInfo info;
info.fFirstChar = info.fFunctionStart = iter.Offset();
info.fSelStart = iter.Offset() + keywordLen + whitespaceLen;
info.fSelEnd = info.fSelStart + wordLen;
info.fFunctionStart = start_of_function;
info.fFunctionEnd = info.fSelEnd + funLen;
info.fIndentLevel = indentLevel;
info.fKind = typeIfSo;
info.fFlags = 0;
info.fNameStart = tokenOffset;
info.fNameLength = nameLen;
bblmAddFunctionToList(callbacks, params.fFcnParams.fFcnList, info, &funIndex);
// But still allow the user to fold them
// (the length changes here are to cut off the opening { and closing } from the fold range
bblmAddFoldRange(callbacks, start_of_function + 1, funLen - 2, kBBLMFunctionAutoFold);
iter += (keywordLen + whitespaceLen);
return info.fFunctionEnd;
}
return 0;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 293 KiB

After

Width:  |  Height:  |  Size: 294 KiB