12 Commits
0.3 ... 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
Ben S
46fe844c16 Version bump 2015-02-21 13:29:11 +00:00
Ben S
bfdc57e356 Fix infinite loop when writing code at end of file
This resulted in my BBEdit hanging.
2015-02-21 13:27:29 +00:00
Ben S
1154b0df63 Highlight module names in 'use...as' statements 2015-02-21 13:27:05 +00:00
Ben S
2c05ab8682 Download link bump 2015-02-15 14:06:55 +00:00
5 changed files with 319 additions and 225 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 - Complete syntax highlighting
- Special support for lifetimes, attributes, and identifiers - 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 - Language features
- Go to start of/end of/previous/next function - Go to start of/end of/previous/next function
- Go to named symbol - Go to named symbol
- Indexed function menu - 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. 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 ### Installation
The simplest way is to just [download the package](https://github.com/ogham/Rust.bblm/releases/tag/0.2) 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 ~/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"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>
<string>English</string> <string>English</string>
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string> <string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key> <key>CFBundleIconFile</key>
<string></string> <string></string>
<key>CFBundleIdentifier</key> <key>CFBundleIdentifier</key>
<string>me.bsago.bblm.rust</string> <string>me.bsago.bblm.rust</string>
<key>CFBundleInfoDictionaryVersion</key> <key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string> <string>6.0</string>
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>BNDL</string> <string>BNDL</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>BBLM</string> <string>BBLM</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>8.0</string> <string>8.0</string>
<key>CSResourcesFileMapped</key> <key>CSResourcesFileMapped</key>
<true/> <true/>
<key>com.barebones.bblminfo</key> <key>com.barebones.bblminfo</key>
<array> <array>
<dict> <dict>
<key>BBLMCanGuessLanguage</key> <key>BBLMCanGuessLanguage</key>
<true/> <true/>
<key>BBLMColorsSyntax</key> <key>BBLMColorsSyntax</key>
<true/> <true/>
<key>BBLMDroppedFilePathStyle</key> <key>BBLMDroppedFilePathStyle</key>
<string>POSIX</string> <string>POSIX</string>
<key>BBLMCommentLineDefault</key> <key>BBLMCommentLineDefault</key>
<string>// </string> <string>// </string>
<key>BBLMCommentPrefixDefault</key> <key>BBLMCommentPrefixDefault</key>
<string>/* </string> <string>/* </string>
<key>BBLMCommentSuffixDefault</key> <key>BBLMCommentSuffixDefault</key>
<string> */</string> <string> */</string>
<key>BBLMIsCaseSensitive</key> <key>BBLMIsCaseSensitive</key>
<true/> <true/>
<key>BBLMRunNames</key> <key>BBLMRunNames</key>
<dict> <dict>
<key>me.bsago.bblm.rust.lifetime</key> <key>me.bsago.bblm.rust.lifetime</key>
<string>&apos;lifetime</string> <string>&apos;lifetime</string>
<key>me.bsago.bblm.rust.identifier</key> <key>me.bsago.bblm.rust.identifier</key>
<string>Identifier</string> <string>Identifier</string>
<key>me.bsago.bblm.rust.function</key> <key>me.bsago.bblm.rust.function</key>
<string>fn functionname</string> <string>fn functionname</string>
<key>me.bsago.bblm.rust.module</key> <key>me.bsago.bblm.rust.module</key>
<string>mod modulename</string> <string>mod modulename</string>
</dict> </dict>
<key>BBLMRunColors</key> <key>BBLMRunColors</key>
<dict> <dict>
<key>me.bsago.bblm.rust.module</key> <key>me.bsago.bblm.rust.module</key>
<string>rgb(135, 2, 219)</string> <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.identifier</key> <key>me.bsago.bblm.rust.identifier</key>
<string>rgb(61, 153, 112)</string> <string>rgb(61, 153, 112)</string>
<key>me.bsago.bblm.rust.function</key> <key>me.bsago.bblm.rust.function</key>
<string>rgb(219, 135, 2)</string> <string>rgb(219, 135, 2)</string>
</dict> </dict>
<key>BBLMKeywords</key> <key>BBLMKeywords</key>
<array> <array>
<dict> <dict>
<key>RunKind</key> <key>RunKind</key>
<string>com.barebones.bblm.keyword</string> <string>com.barebones.bblm.keyword</string>
<key>Keywords</key> <key>Keywords</key>
<array> <array>
<string>abstract</string> <string>abstract</string>
<string>alignof</string> <string>alignof</string>
<string>as</string> <string>as</string>
<string>become</string> <string>become</string>
<string>box</string> <string>box</string>
<string>break</string> <string>break</string>
<string>const</string> <string>const</string>
<string>continue</string> <string>continue</string>
<string>crate</string> <string>crate</string>
<string>do</string> <string>do</string>
<string>else</string> <string>else</string>
<string>enum</string> <string>enum</string>
<string>extern</string> <string>extern</string>
<string>false</string> <string>false</string>
<string>final</string> <string>final</string>
<string>fn</string> <string>fn</string>
<string>for</string> <string>for</string>
<string>if</string> <string>if</string>
<string>impl</string> <string>impl</string>
<string>in</string> <string>in</string>
<string>let</string> <string>let</string>
<string>loop</string> <string>loop</string>
<string>macro</string> <string>macro</string>
<string>macro_rules</string> <string>macro_rules</string>
<string>match</string> <string>match</string>
<string>mod</string> <string>mod</string>
<string>move</string> <string>move</string>
<string>mut</string> <string>mut</string>
<string>offsetof</string> <string>offsetof</string>
<string>override</string> <string>override</string>
<string>priv</string> <string>priv</string>
<string>proc</string> <string>proc</string>
<string>pub</string> <string>pub</string>
<string>pure</string> <string>pure</string>
<string>ref</string> <string>ref</string>
<string>return</string> <string>return</string>
<string>self</string> <string>self</string>
<string>sizeof</string> <string>sizeof</string>
<string>static</string> <string>static</string>
<string>struct</string> <string>struct</string>
<string>super</string> <string>super</string>
<string>trait</string> <string>trait</string>
<string>true</string> <string>true</string>
<string>type</string> <string>type</string>
<string>typeof</string> <string>typeof</string>
<string>unsafe</string> <string>unsafe</string>
<string>unsized</string> <string>unsized</string>
<string>use</string> <string>use</string>
<string>virtual</string> <string>virtual</string>
<string>where</string> <string>where</string>
<string>while</string> <string>while</string>
<string>yield</string> <string>yield</string>
</array> </array>
</dict> </dict>
<dict> <dict>
<key>RunKind</key> <key>RunKind</key>
<string>com.barebones.bblm.predefined-symbol</string> <string>com.barebones.bblm.predefined-symbol</string>
<key>Keywords</key> <key>Keywords</key>
<array> <array>
<string>bool</string> <string>blkcnt_t</string>
<string>char</string> <string>blksize_t</string>
<string>f32</string> <string>bool</string>
<string>f64</string> <string>c_char</string>
<string>float</string> <string>c_double</string>
<string>i16</string> <string>c_float</string>
<string>i32</string> <string>c_int</string>
<string>i64</string> <string>c_long</string>
<string>i8</string> <string>c_schar</string>
<string>isize</string> <string>c_short</string>
<string>str</string> <string>c_uchar</string>
<string>u16</string> <string>c_uint</string>
<string>u32</string> <string>c_ulong</string>
<string>u64</string> <string>c_ushort</string>
<string>u8</string> <string>char</string>
<string>usize</string> <string>clock_t</string>
</array> <string>dev_t</string>
</dict> <string>f32</string>
</array> <string>f64</string>
<key>BBLMLanguageCode</key> <string>float</string>
<string>Rust</string> <string>gid_t</string>
<key>BBLMLanguageDisplayName</key> <string>i16</string>
<string>Rust</string> <string>i32</string>
<key>BBLMEntryPointName</key> <string>i64</string>
<string>rustMain</string> <string>i8</string>
<key>BBLMScansFunctions</key> <string>ino_t</string>
<true/> <string>isize</string>
<key>BBLMFunctionScannerDoesFoldsToo</key> <string>mode_t</string>
<false/> <string>nlink_t</string>
<key>BBLMSuffixMap</key> <string>off_t</string>
<array> <string>pid_t</string>
<dict> <string>ptrdiff_t</string>
<key>BBLMLanguageSuffix</key> <string>size_t</string>
<string>.rs</string> <string>str</string>
</dict> <string>suseconds_t</string>
</array> <string>time_t</string>
<key>BBLMUseHTMLFileSearchRules</key> <string>u16</string>
<false/> <string>u32</string>
<key>BBLMSpellableRunKinds</key> <string>u64</string>
<array> <string>u8</string>
<string>com.barebones.bblm.line-comment</string> <string>uid_t</string>
<string>com.barebones.bblm.block-comment</string> <string>usize</string>
</array> <string>wchar_t</string>
<key>BBLMNonSpellableRunKinds</key> </array>
<array> </dict>
<string>com.barebones.bblm.code</string> </array>
<string>com.barebones.bblm.double-string</string> <key>BBLMLanguageCode</key>
</array> <string>Rust</string>
</dict> <key>BBLMLanguageDisplayName</key>
</array> <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> </dict>
</plist> </plist>

155
rust.mm
View File

@@ -386,70 +386,105 @@ SInt32 scanForSymbol(BBLMTextIterator &iter,
BBLMParamBlock &params, BBLMParamBlock &params,
const BBLMCallbackBlock *callbacks) const BBLMCallbackBlock *callbacks)
{ {
SInt32 whitespaceLen, wordLen; SInt32 whitespaceLen, wordLen = 0, parametersLen = 0;
UniChar ch;
int keywordLen = strlen(keyword); int keywordLen = strlen(keyword);
if (iter.strcmp(keyword, keywordLen) == 0) if (iter.strcmp(keyword, keywordLen) == 0)
{ {
iter += keywordLen; 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; iter -= keywordLen + whitespaceLen;
return 0;
if ((wordLen = skipWord(iter))) }
SInt32 start_of_name = iter.Offset();
SInt32 start_of_function;
while ((ch = iter.GetNextChar()))
{
if (ch == '{' || ch == ';')
{ {
UInt32 funLen = skipToEndOfFunction(iter); iter--;
start_of_function = iter.Offset();
// Skip over trait method definitions and extern functions break;
if (funLen == 0) }
else if (ch == '(')
{
while ((ch = iter.GetNextChar()))
{ {
return 0; whitespaceLen++;
if (ch == '{' || ch == ';')
{
break;
}
} }
// Ignore modules called 'test' iter--;
if (strcmp(keyword, "mod") == 0 && is_test) start_of_function = iter.Offset();
{ break;
return 0; }
} else if (ch == '\n')
{
UInt32 tokenOffset, funIndex; start_of_function = iter.Offset();
UInt32 nameLen; break;
BBLMProcInfo info; }
else if (ch)
iter -= (wordLen + funLen); {
iter -= (keywordLen + whitespaceLen); 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;
} }
else 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; return 0;
@@ -569,7 +604,7 @@ OSErr calculateRuns(BBLMParamBlock &params, const BBLMCallbackBlock *callbacks)
bool wordchr = false; bool wordchr = false;
while ((ch = iter.GetNextChar())) while ((ch = iter.GetNextChar()))
{ {
if (ch == 'r' && iter.strcmp("##\"", 3) == 0) if (ch == 'r' && iter.CharsLeft() >= 3 && iter.strcmp("##\"", 3) == 0)
{ {
iter--; iter--;
if (!makeCodeRun(iter, runStart, *callbacks)) return noErr; if (!makeCodeRun(iter, runStart, *callbacks)) return noErr;
@@ -675,7 +710,7 @@ OSErr calculateRuns(BBLMParamBlock &params, const BBLMCallbackBlock *callbacks)
iter--; iter--;
} }
} }
else if (ch == 'a' && iter.strcmp("cro_rules!", 10) == 0) else if (ch == 'a' && iter.CharsLeft() >= 10 && iter.strcmp("cro_rules!", 10) == 0)
{ {
iter += 10; iter += 10;
ch = iter.GetNextChar(); ch = iter.GetNextChar();
@@ -763,11 +798,31 @@ OSErr calculateRuns(BBLMParamBlock &params, const BBLMCallbackBlock *callbacks)
if (!addRun(kBBLMFileIncludeRunKind, runStart, runLen, *callbacks)) return noErr; if (!addRun(kBBLMFileIncludeRunKind, runStart, runLen, *callbacks)) return noErr;
break; break;
} }
else else if (ch)
{ {
spacey = isspace(ch) || ch == ':' || ch == '{'; spacey = isspace(ch) || ch == ':' || ch == '{';
runLen++; runLen++;
} }
else
{
break;
}
if (iter.strcmp(" as ", 4) == 0)
{
if (!addRun(kBBLMFileIncludeRunKind, runStart, runLen, *callbacks)) return noErr;
runStart = iter.Offset();
iter += 4;
if (!addRun(kBBLMCodeRunKind, runStart, 4, *callbacks)) return noErr;
runStart = iter.Offset();
runLen = skipWord(iter);
if (!addRun(moduleColour, runStart, runLen, *callbacks)) return noErr;
iter++;
runLen = 0;
break;
}
} }
if (!addRun(kBBLMFileIncludeRunKind, runStart, runLen, *callbacks)) return noErr; if (!addRun(kBBLMFileIncludeRunKind, runStart, runLen, *callbacks)) return noErr;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 293 KiB

After

Width:  |  Height:  |  Size: 294 KiB

View File

@@ -118,3 +118,14 @@
macro_rules! parse { macro_rules! parse {
($thing: expr) => { $thing }; ($thing: expr) => { $thing };
} }
// `use` statements
// ----------------
use flux;
use flux::capacitor;
use flux::capacitor::Component::*;
use flux::capacitor::Component::{ImpurePalladium, ThinkingAluminium, TimeyWimeyDevice};
use flux::capacitor as cap;
use super;
use self;