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

@@ -125,22 +125,49 @@
<string>com.barebones.bblm.predefined-symbol</string> <string>com.barebones.bblm.predefined-symbol</string>
<key>Keywords</key> <key>Keywords</key>
<array> <array>
<string>blkcnt_t</string>
<string>blksize_t</string>
<string>bool</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>char</string>
<string>clock_t</string>
<string>dev_t</string>
<string>f32</string> <string>f32</string>
<string>f64</string> <string>f64</string>
<string>float</string> <string>float</string>
<string>gid_t</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>ino_t</string>
<string>isize</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>str</string>
<string>suseconds_t</string>
<string>time_t</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>uid_t</string>
<string>usize</string> <string>usize</string>
<string>wchar_t</string>
</array> </array>
</dict> </dict>
</array> </array>
@@ -153,7 +180,7 @@
<key>BBLMScansFunctions</key> <key>BBLMScansFunctions</key>
<true/> <true/>
<key>BBLMFunctionScannerDoesFoldsToo</key> <key>BBLMFunctionScannerDoesFoldsToo</key>
<false/> <true/>
<key>BBLMSuffixMap</key> <key>BBLMSuffixMap</key>
<array> <array>
<dict> <dict>

109
rust.mm
View File

@@ -386,18 +386,63 @@ 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)))
{
bool is_test = iter.strcmp("test", 4) == 0;
if ((wordLen = skipWord(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)
{ {
iter -= keywordLen + whitespaceLen;
return 0;
}
SInt32 start_of_name = iter.Offset();
SInt32 start_of_function;
while ((ch = iter.GetNextChar()))
{
if (ch == '{' || ch == ';')
{
iter--;
start_of_function = iter.Offset();
break;
}
else if (ch == '(')
{
while ((ch = iter.GetNextChar()))
{
whitespaceLen++;
if (ch == '{' || ch == ';')
{
break;
}
}
iter--;
start_of_function = iter.Offset();
break;
}
else if (ch == '\n')
{
start_of_function = iter.Offset();
break;
}
else if (ch)
{
whitespaceLen++;
}
else
{
return 0;
}
}
UInt32 funLen = skipToEndOfFunction(iter); UInt32 funLen = skipToEndOfFunction(iter);
// Skip over trait method definitions and extern functions // Skip over trait method definitions and extern functions
@@ -406,15 +451,8 @@ SInt32 scanForSymbol(BBLMTextIterator &iter,
return 0; return 0;
} }
// Ignore modules called 'test'
if (strcmp(keyword, "mod") == 0 && is_test)
{
return 0;
}
UInt32 tokenOffset, funIndex; UInt32 tokenOffset, funIndex;
UInt32 nameLen; UInt32 nameLen;
BBLMProcInfo info;
iter -= (wordLen + funLen); iter -= (wordLen + funLen);
iter -= (keywordLen + whitespaceLen); iter -= (keywordLen + whitespaceLen);
@@ -425,32 +463,29 @@ SInt32 scanForSymbol(BBLMTextIterator &iter,
nameLen, &tokenOffset); nameLen, &tokenOffset);
iter += (nameLen - wordLen); iter += (nameLen - wordLen);
iter -= (keywordLen + whitespaceLen); iter -= (keywordLen + whitespaceLen);
BBLMProcInfo info;
info.fFirstChar = info.fFunctionStart = iter.Offset(); info.fFirstChar = info.fFunctionStart = iter.Offset();
info.fSelStart = iter.Offset() + keywordLen + whitespaceLen; info.fSelStart = iter.Offset() + keywordLen + whitespaceLen;
info.fSelEnd = info.fSelStart + wordLen; info.fSelEnd = info.fSelStart + wordLen;
info.fFunctionStart = start_of_function;
info.fFunctionEnd = info.fSelEnd + funLen; info.fFunctionEnd = info.fSelEnd + funLen;
info.fIndentLevel = indentLevel; info.fIndentLevel = indentLevel;
info.fKind = typeIfSo; info.fKind = typeIfSo;
info.fFlags = 0; info.fFlags = 0;
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);
bblmAddFoldRange(callbacks, info.fFunctionStart, funLen, kBBLMFunctionAutoFold);
// 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); iter += (keywordLen + whitespaceLen);
return info.fFunctionEnd; return info.fFunctionEnd;
} }
else
{
iter -= (whitespaceLen + keywordLen);
}
}
else
{
iter -= keywordLen;
}
}
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;