Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
822eb95303 | ||
|
|
da342c1b7d | ||
|
|
81197c7d45 | ||
|
|
e6c0074733 | ||
|
|
5452afbb9c | ||
|
|
2c06798f84 | ||
|
|
d2549503b5 | ||
|
|
3b9fc0817c | ||
|
|
82931045a2 | ||
|
|
51e8755030 | ||
|
|
9932fb4761 | ||
|
|
79a65307f0 | ||
|
|
c98ec54134 | ||
|
|
98a15cf36a | ||
|
|
34bbe47973 | ||
|
|
69e12ea420 | ||
|
|
92862fc0a3 | ||
|
|
dbb13d4816 | ||
|
|
38deac77fe | ||
|
|
affebcf878 | ||
|
|
55bbe945ae | ||
|
|
3b76b3429f |
@@ -1,6 +1,8 @@
|
|||||||
BBEdit language module for Rust
|
BBEdit language module for Rust
|
||||||
===============================
|
===============================
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
This is a BBEdit 11 Language Module for [Rust](http://www.rust-lang.org). It provides the following features:
|
This is a BBEdit 11 Language Module for [Rust](http://www.rust-lang.org). It provides the following features:
|
||||||
|
|
||||||
- Complete syntax highlighting
|
- Complete syntax highlighting
|
||||||
@@ -15,7 +17,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](https://github.com/ogham/Rust.bblm/releases/tag/0.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.2) and put it in this folder:
|
||||||
|
|
||||||
~/Application Support/BBEdit/Language Modules
|
~/Application Support/BBEdit/Language Modules
|
||||||
|
|
||||||
@@ -24,4 +26,3 @@ Then restart your BBEdit and it should be picked up.
|
|||||||
### Compilation
|
### Compilation
|
||||||
|
|
||||||
To compile your own version, you'll need Xcode. The default schema outputs a `.bblm`. You'll also need the BBEdit SDK. The project assumes it's mounted under `/Volumes/BBEdit SDK`.
|
To compile your own version, you'll need Xcode. The default schema outputs a `.bblm`. You'll also need the BBEdit SDK. The project assumes it's mounted under `/Volumes/BBEdit SDK`.
|
||||||
|
|
||||||
|
|||||||
26
info.plist
26
info.plist
@@ -43,8 +43,6 @@
|
|||||||
<string>'lifetime</string>
|
<string>'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.attribute</key>
|
|
||||||
<string>#[attribute]</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>
|
||||||
@@ -56,8 +54,6 @@
|
|||||||
<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.attribute</key>
|
|
||||||
<string>rgb(177, 13, 201)</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>
|
||||||
@@ -70,16 +66,21 @@
|
|||||||
<string>com.barebones.bblm.keyword</string>
|
<string>com.barebones.bblm.keyword</string>
|
||||||
<key>Keywords</key>
|
<key>Keywords</key>
|
||||||
<array>
|
<array>
|
||||||
|
<string>abstract</string>
|
||||||
|
<string>alignof</string>
|
||||||
<string>as</string>
|
<string>as</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>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>fn</string>
|
<string>fn</string>
|
||||||
<string>for</string>
|
<string>for</string>
|
||||||
<string>if</string>
|
<string>if</string>
|
||||||
@@ -87,25 +88,36 @@
|
|||||||
<string>in</string>
|
<string>in</string>
|
||||||
<string>let</string>
|
<string>let</string>
|
||||||
<string>loop</string>
|
<string>loop</string>
|
||||||
<string>macro_rules!</string>
|
<string>macro</string>
|
||||||
|
<string>macro_rules</string>
|
||||||
<string>match</string>
|
<string>match</string>
|
||||||
<string>mod</string>
|
<string>mod</string>
|
||||||
|
<string>move</string>
|
||||||
<string>mut</string>
|
<string>mut</string>
|
||||||
|
<string>offsetof</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>ref</string>
|
<string>ref</string>
|
||||||
<string>return</string>
|
<string>return</string>
|
||||||
<string>self</string>
|
<string>self</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>unsafe</string>
|
<string>unsafe</string>
|
||||||
|
<string>unsized</string>
|
||||||
<string>use</string>
|
<string>use</string>
|
||||||
|
<string>virtual</string>
|
||||||
|
<string>where</string>
|
||||||
<string>while</string>
|
<string>while</string>
|
||||||
|
<string>yield</string>
|
||||||
</array>
|
</array>
|
||||||
</dict>
|
</dict>
|
||||||
<dict>
|
<dict>
|
||||||
@@ -122,13 +134,13 @@
|
|||||||
<string>i32</string>
|
<string>i32</string>
|
||||||
<string>i64</string>
|
<string>i64</string>
|
||||||
<string>i8</string>
|
<string>i8</string>
|
||||||
<string>int</string>
|
<string>isize</string>
|
||||||
<string>str</string>
|
<string>str</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>usize</string>
|
||||||
</array>
|
</array>
|
||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
|
|||||||
358
rust.mm
358
rust.mm
@@ -8,10 +8,9 @@
|
|||||||
#include "BBLMInterface.h"
|
#include "BBLMInterface.h"
|
||||||
#include "BBLMTextIterator.h"
|
#include "BBLMTextIterator.h"
|
||||||
|
|
||||||
#define kMaxLineLength 256
|
#define kMaxLineLength 256
|
||||||
|
|
||||||
static NSString* const identifierColour = @"me.bsago.bblm.rust.identifier";
|
static NSString* const identifierColour = @"me.bsago.bblm.rust.identifier";
|
||||||
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 NSString* const moduleColour = @"me.bsago.bblm.rust.module";
|
||||||
@@ -31,14 +30,56 @@ static bool addRun(NSString *kind, int start,int len , const BBLMCallbackBlock&
|
|||||||
SInt32 skipString(BBLMTextIterator &iter)
|
SInt32 skipString(BBLMTextIterator &iter)
|
||||||
{
|
{
|
||||||
SInt32 length = 1;
|
SInt32 length = 1;
|
||||||
UniChar terminator = iter.GetNextChar();
|
|
||||||
UniChar ch;
|
UniChar ch;
|
||||||
|
|
||||||
|
if (iter.strcmp("\"", 1) == 0)
|
||||||
|
{
|
||||||
|
iter += 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((ch = iter.GetNextChar()))
|
||||||
|
{
|
||||||
|
length++;
|
||||||
|
if (ch == '"')
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ch == '\\')
|
||||||
|
{
|
||||||
|
iter++;
|
||||||
|
length++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
SInt32 skipRawString(BBLMTextIterator &iter)
|
||||||
|
{
|
||||||
|
SInt32 length = 4;
|
||||||
|
UniChar ch;
|
||||||
|
|
||||||
|
if (iter.strcmp("r##\"", 4) == 0)
|
||||||
|
{
|
||||||
|
iter += 4;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
while ((ch = iter.GetNextChar()))
|
while ((ch = iter.GetNextChar()))
|
||||||
{
|
{
|
||||||
length++;
|
length++;
|
||||||
if (ch == terminator)
|
if (iter.strcmp("\"##", 3) == 0)
|
||||||
{
|
{
|
||||||
|
length += 3;
|
||||||
|
iter += 3;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +97,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 +111,7 @@ SInt32 skipLineComment(BBLMTextIterator &iter)
|
|||||||
length++;
|
length++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,10 +125,10 @@ SInt32 skipBlockComment(BBLMTextIterator &iter)
|
|||||||
iter++;
|
iter++;
|
||||||
length++;
|
length++;
|
||||||
}
|
}
|
||||||
|
|
||||||
iter += 2;
|
iter += 2;
|
||||||
length += 2;
|
length += 2;
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +136,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 +149,7 @@ SInt32 skipWhitespace(BBLMTextIterator &iter)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,10 +157,10 @@ 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 == '_' || (length > 0 && isdigit(ch)))
|
||||||
{
|
{
|
||||||
length++;
|
length++;
|
||||||
}
|
}
|
||||||
@@ -129,49 +170,52 @@ SInt32 skipWord(BBLMTextIterator &iter)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
SInt32 skipAttribute(BBLMTextIterator &iter)
|
SInt32 skipAttribute(BBLMTextIterator &iter)
|
||||||
{
|
|
||||||
SInt32 length = 1;
|
|
||||||
UniChar ch;
|
|
||||||
|
|
||||||
iter++;
|
|
||||||
while ((ch = iter.GetNextChar()))
|
|
||||||
{
|
|
||||||
if (ch == '\n' || ch == '\r')
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
length++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return length;
|
|
||||||
}
|
|
||||||
|
|
||||||
SInt32 skipUse(BBLMTextIterator &iter)
|
|
||||||
{
|
{
|
||||||
SInt32 length = 0;
|
SInt32 length = 0;
|
||||||
UniChar ch;
|
UniChar ch;
|
||||||
|
|
||||||
|
if (iter.strcmp("#[", 2) == 0)
|
||||||
|
{
|
||||||
|
length += 2;
|
||||||
|
iter += 2;
|
||||||
|
}
|
||||||
|
else if (iter.strcmp("#![", 3) == 0)
|
||||||
|
{
|
||||||
|
length += 3;
|
||||||
|
iter += 3;
|
||||||
|
}
|
||||||
|
else if (iter.strcmp("#", 1) == 0)
|
||||||
|
{
|
||||||
|
iter++;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
while ((ch = iter.GetNextChar()))
|
while ((ch = iter.GetNextChar()))
|
||||||
{
|
{
|
||||||
if (islower(ch) || ch == ':' || ch == '_' || (length > 0 && isdigit(ch)))
|
if (ch == ']')
|
||||||
{
|
{
|
||||||
length++;
|
length++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (ch == '\n' || ch == '\r')
|
||||||
|
{
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
iter--;
|
length++;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +225,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,29 +254,38 @@ 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)))
|
||||||
{
|
{
|
||||||
length++;
|
length++;
|
||||||
}
|
}
|
||||||
else if ((base == 2) && (ch == '0' || ch == '1'))
|
else if ((base == 2) && (ch == '0' || ch == '1' || ((ch == '_' || ch == '.') && length > 0)))
|
||||||
{
|
{
|
||||||
length++;
|
length++;
|
||||||
}
|
}
|
||||||
else if ((base == 8) && (ch >= '0' && ch <= '7'))
|
else if ((base == 8) && ((ch >= '0' && ch <= '7') || ((ch == '_' || ch == '.') && length > 0)))
|
||||||
{
|
{
|
||||||
length++;
|
length++;
|
||||||
}
|
}
|
||||||
else if ((base == 16) && ((ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F') || isdigit(ch)))
|
else if ((base == 16) && ((ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F') || isdigit(ch) || ((ch == '_' || ch == '.') && length > 0)))
|
||||||
{
|
{
|
||||||
length++;
|
length++;
|
||||||
}
|
}
|
||||||
else if (ch == 'f' || ch == 'u' || ch == 'i')
|
else if (ch == 'f' || ch == 'u' || ch == 'i')
|
||||||
{
|
{
|
||||||
hasSuffix = true;
|
|
||||||
length++;
|
length++;
|
||||||
|
if (ch != 'f' && iter.strcmp("s", 1) == 0)
|
||||||
|
{
|
||||||
|
// Parse 'us' or 'is' machine-dependent suffixes
|
||||||
|
length++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Otherwise, allow for numbers at the end
|
||||||
|
hasSuffix = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -241,7 +294,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 +308,7 @@ SInt32 skipNumber(BBLMTextIterator &iter)
|
|||||||
length += 2;
|
length += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,11 +317,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 +340,42 @@ 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 ';':
|
||||||
|
// If the definition just ends with a semicolon, then it's
|
||||||
|
// either a function in a trait definition, or a C function
|
||||||
|
// definition in an extern, neither of which we want in the
|
||||||
|
// function list.
|
||||||
|
if (braceLevel < 1) return 0;
|
||||||
|
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,28 +388,44 @@ 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;
|
||||||
if ((whitespaceLen = skipWhitespace(iter)))
|
if ((whitespaceLen = skipWhitespace(iter)))
|
||||||
{
|
{
|
||||||
|
bool is_test = iter.strcmp("test", 4) == 0;
|
||||||
|
|
||||||
if ((wordLen = skipWord(iter)))
|
if ((wordLen = skipWord(iter)))
|
||||||
{
|
{
|
||||||
UInt32 funLen = skipToEndOfFunction(iter);
|
UInt32 funLen = skipToEndOfFunction(iter);
|
||||||
|
|
||||||
|
// Skip over trait method definitions and extern functions
|
||||||
|
if (funLen == 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;
|
BBLMProcInfo info;
|
||||||
|
|
||||||
iter -= (wordLen + funLen);
|
iter -= (wordLen + funLen);
|
||||||
nameLen = keywordLen + whitespaceLen + wordLen;
|
|
||||||
iter -= (keywordLen + whitespaceLen);
|
iter -= (keywordLen + whitespaceLen);
|
||||||
|
|
||||||
|
nameLen = keywordLen + whitespaceLen + wordLen;
|
||||||
|
|
||||||
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 +437,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);
|
||||||
|
bblmAddFoldRange(callbacks, info.fFunctionStart, funLen, kBBLMFunctionAutoFold);
|
||||||
iter += (keywordLen + whitespaceLen);
|
iter += (keywordLen + whitespaceLen);
|
||||||
return info.fFunctionEnd;
|
return info.fFunctionEnd;
|
||||||
}
|
}
|
||||||
@@ -374,7 +451,7 @@ SInt32 scanForSymbol(BBLMTextIterator &iter,
|
|||||||
iter -= keywordLen;
|
iter -= keywordLen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,24 +461,24 @@ static OSErr scanForFunctions(BBLMParamBlock ¶ms, 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 +496,38 @@ static OSErr scanForFunctions(BBLMParamBlock ¶ms, 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 +541,7 @@ static OSErr scanForFunctions(BBLMParamBlock ¶ms, const BBLMCallbackBlock *c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return noErr;
|
return noErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -487,12 +564,25 @@ OSErr calculateRuns(BBLMParamBlock ¶ms, 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()))
|
||||||
{
|
{
|
||||||
if (ch == '"')
|
if (ch == 'r' && iter.strcmp("##\"", 3) == 0)
|
||||||
|
{
|
||||||
|
iter--;
|
||||||
|
if (!makeCodeRun(iter, runStart, *callbacks)) return noErr;
|
||||||
|
runStart = iter.Offset();
|
||||||
|
runLen = skipRawString(iter);
|
||||||
|
|
||||||
|
// Use the heredoc colour to highlight raw strings.
|
||||||
|
// It's not exactly a heredoc, but it's the closest!
|
||||||
|
if (!addRun(kBBLMHereDocStringRunKind, runStart, runLen, *callbacks)) return noErr;
|
||||||
|
runStart = iter.Offset();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (ch == '"')
|
||||||
{
|
{
|
||||||
iter--;
|
iter--;
|
||||||
if (!makeCodeRun(iter, runStart, *callbacks)) return noErr;
|
if (!makeCodeRun(iter, runStart, *callbacks)) return noErr;
|
||||||
@@ -501,7 +591,7 @@ OSErr calculateRuns(BBLMParamBlock ¶ms, 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 +646,7 @@ OSErr calculateRuns(BBLMParamBlock ¶ms, const BBLMCallbackBlock *callbacks)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (!wordchr && ch == 'm')
|
else if (!wordchr && ch == 'm')
|
||||||
{
|
{
|
||||||
ch = iter.GetNextChar();
|
ch = iter.GetNextChar();
|
||||||
@@ -585,12 +675,30 @@ OSErr calculateRuns(BBLMParamBlock ¶ms, const BBLMCallbackBlock *callbacks)
|
|||||||
iter--;
|
iter--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (ch == 'a' && iter.strcmp("cro_rules!", 10) == 0)
|
||||||
|
{
|
||||||
|
iter += 10;
|
||||||
|
ch = iter.GetNextChar();
|
||||||
|
if (isspace(ch))
|
||||||
|
{
|
||||||
|
if (!makeCodeRun(iter, runStart, *callbacks)) return noErr;
|
||||||
|
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)
|
else if (ch)
|
||||||
{
|
{
|
||||||
iter--;
|
iter--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (!wordchr && ch == 'f')
|
else if (!wordchr && ch == 'f')
|
||||||
{
|
{
|
||||||
ch = iter.GetNextChar();
|
ch = iter.GetNextChar();
|
||||||
@@ -616,7 +724,7 @@ OSErr calculateRuns(BBLMParamBlock ¶ms, const BBLMCallbackBlock *callbacks)
|
|||||||
iter--;
|
iter--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (!wordchr && ch == 'u')
|
else if (!wordchr && ch == 'u')
|
||||||
{
|
{
|
||||||
ch = iter.GetNextChar();
|
ch = iter.GetNextChar();
|
||||||
@@ -628,17 +736,44 @@ OSErr calculateRuns(BBLMParamBlock ¶ms, const BBLMCallbackBlock *callbacks)
|
|||||||
ch = iter.GetNextChar();
|
ch = iter.GetNextChar();
|
||||||
if (isspace(ch))
|
if (isspace(ch))
|
||||||
{
|
{
|
||||||
|
skipWhitespace(iter);
|
||||||
if (!makeCodeRun(iter, runStart, *callbacks)) return noErr;
|
if (!makeCodeRun(iter, runStart, *callbacks)) return noErr;
|
||||||
|
|
||||||
runStart = iter.Offset();
|
runStart = iter.Offset();
|
||||||
runLen = skipWhitespace(iter);
|
runLen = 0;
|
||||||
runLen += skipUse(iter);
|
bool spacey = false;
|
||||||
|
|
||||||
|
while ((ch = iter.GetNextChar()))
|
||||||
|
{
|
||||||
|
if (spacey && isupper(ch))
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
runLen = 0;
|
||||||
|
}
|
||||||
|
else if (ch == ';' || ch == '\n')
|
||||||
|
{
|
||||||
|
iter--;
|
||||||
|
if (!addRun(kBBLMFileIncludeRunKind, runStart, runLen, *callbacks)) return noErr;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
spacey = isspace(ch) || ch == ':' || ch == '{';
|
||||||
|
runLen++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
runStart = iter.Offset();
|
|
||||||
}
|
}
|
||||||
else if (ch)
|
else if (ch)
|
||||||
{
|
{
|
||||||
@@ -655,7 +790,7 @@ OSErr calculateRuns(BBLMParamBlock ¶ms, const BBLMCallbackBlock *callbacks)
|
|||||||
iter--;
|
iter--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (ch == '/')
|
else if (ch == '/')
|
||||||
{
|
{
|
||||||
ch = iter.GetNextChar();
|
ch = iter.GetNextChar();
|
||||||
@@ -682,17 +817,28 @@ OSErr calculateRuns(BBLMParamBlock ¶ms, const BBLMCallbackBlock *callbacks)
|
|||||||
iter--;
|
iter--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (ch == '#')
|
else if (ch == '#')
|
||||||
{
|
{
|
||||||
iter--;
|
iter--;
|
||||||
if (!makeCodeRun(iter, runStart, *callbacks)) return noErr;
|
if (!makeCodeRun(iter, runStart, *callbacks)) return noErr;
|
||||||
runStart = iter.Offset();
|
runStart = iter.Offset();
|
||||||
runLen = skipAttribute(iter);
|
runLen = skipAttribute(iter);
|
||||||
if (!addRun(attributeColour, runStart, runLen, *callbacks)) return noErr;
|
if (!addRun(kBBLMPreprocessorRunKind, runStart, runLen, *callbacks)) return noErr;
|
||||||
runStart = iter.Offset();
|
runStart = iter.Offset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (ch == '$')
|
||||||
|
{
|
||||||
|
iter--;
|
||||||
|
if (!makeCodeRun(iter, runStart, *callbacks)) return noErr;
|
||||||
|
runStart = iter.Offset();
|
||||||
|
iter++;
|
||||||
|
runLen = skipWord(iter) + 1;
|
||||||
|
if (runLen > 1 && !addRun(kBBLMVariableRunKind, runStart, runLen, *callbacks)) return noErr;
|
||||||
|
runStart = iter.Offset();
|
||||||
|
}
|
||||||
|
|
||||||
else if (!wordchr && isupper(ch))
|
else if (!wordchr && isupper(ch))
|
||||||
{
|
{
|
||||||
iter--;
|
iter--;
|
||||||
@@ -702,7 +848,7 @@ OSErr calculateRuns(BBLMParamBlock ¶ms, 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 +867,7 @@ OSErr calculateRuns(BBLMParamBlock ¶ms, const BBLMCallbackBlock *callbacks)
|
|||||||
iter--;
|
iter--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (!wordchr && isdigit(ch))
|
else if (!wordchr && isdigit(ch))
|
||||||
{
|
{
|
||||||
iter--;
|
iter--;
|
||||||
@@ -731,10 +877,10 @@ OSErr calculateRuns(BBLMParamBlock ¶ms, 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) || ch == '_';
|
||||||
}
|
}
|
||||||
|
|
||||||
makeCodeRun(iter, runStart, *callbacks);
|
makeCodeRun(iter, runStart, *callbacks);
|
||||||
return noErr;
|
return noErr;
|
||||||
}
|
}
|
||||||
@@ -756,12 +902,12 @@ OSErr adjustRange(BBLMParamBlock ¶ms, 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 +915,12 @@ OSErr adjustRange(BBLMParamBlock ¶ms, const BBLMCallbackBlock &callbacks)
|
|||||||
OSErr guessLanguage(BBLMParamBlock ¶ms)
|
OSErr guessLanguage(BBLMParamBlock ¶ms)
|
||||||
{
|
{
|
||||||
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 +933,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 +963,7 @@ extern "C"
|
|||||||
default:
|
default:
|
||||||
result = paramErr;
|
result = paramErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
screenshot.png
Normal file
BIN
screenshot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 293 KiB |
120
smoke.rs
Normal file
120
smoke.rs
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
// Keywords
|
||||||
|
// --------
|
||||||
|
|
||||||
|
abstract, alignof, as, become, box, break, const, continue, crate, do, else, enum,
|
||||||
|
extern, false, final, fn, for, if, impl, in, let, loop, macro, match, mod, move, mut,
|
||||||
|
offsetof, override, priv, pub, pure, ref, return, sizeof, static, self, struct, super,
|
||||||
|
true, trait, type, typeof, unsafe, unsized, use, virtual, where, while, yield.
|
||||||
|
|
||||||
|
// Types
|
||||||
|
// -----
|
||||||
|
|
||||||
|
- ()
|
||||||
|
- bool, char, str
|
||||||
|
- u8, u16, u32, u64
|
||||||
|
- i8, i16, i32, i64
|
||||||
|
- f32, f64
|
||||||
|
- usize, isize
|
||||||
|
|
||||||
|
- int, uint // these are no longer valid!
|
||||||
|
|
||||||
|
// Comments
|
||||||
|
// --------
|
||||||
|
|
||||||
|
// This is a comment
|
||||||
|
/* So is this */
|
||||||
|
|
||||||
|
/// This is a doc comment
|
||||||
|
/** So is this */
|
||||||
|
|
||||||
|
// Characters and Lifetimes
|
||||||
|
// ------------------------
|
||||||
|
|
||||||
|
'a' // a character
|
||||||
|
'a // a lifetime
|
||||||
|
'static // also a lifetime
|
||||||
|
b'a' // a byte
|
||||||
|
|
||||||
|
' ' // this is also a character (space)
|
||||||
|
'\t' // characters can be escaped
|
||||||
|
'\'' // including the quote character itself!
|
||||||
|
|
||||||
|
"geese" // a string
|
||||||
|
r##"geese"## // a raw string. This part should not be highlighted!
|
||||||
|
b"geese" // a byte string
|
||||||
|
br##"geese"## // a raw byte string. This part should still not be highlighted
|
||||||
|
|
||||||
|
"there's a \" in this string" // be sure to handle escapes
|
||||||
|
"\"geese\"" // including at the edges
|
||||||
|
|
||||||
|
r##"there's a " in this string"## // the string shouldn't end until ##
|
||||||
|
r##"there's a # in this string"## // even if there's a # in the middle
|
||||||
|
|
||||||
|
// " // in case the above failed :)
|
||||||
|
|
||||||
|
// Decimal Numbers
|
||||||
|
// ---------------
|
||||||
|
|
||||||
|
7, 12, 1048576 // are all numbers
|
||||||
|
1_000_000 // is a number with underscore separators
|
||||||
|
_, _1000, 1000_ // beware of sole/leading/trailing underscores
|
||||||
|
|
||||||
|
// Hex Numbers
|
||||||
|
// -----------
|
||||||
|
|
||||||
|
0xff // hex numbers start with 0x
|
||||||
|
0xFF // and can be in lowercase or uppercase
|
||||||
|
0x0123_4567 // and can have separators
|
||||||
|
|
||||||
|
// Octal Numbers
|
||||||
|
// -------------
|
||||||
|
|
||||||
|
0o77 // octal numbers start with 0o
|
||||||
|
0o12345678909 // and should finish after an 8 or 9
|
||||||
|
|
||||||
|
// Binary Numbers
|
||||||
|
// --------------
|
||||||
|
|
||||||
|
0b0000_1111 // binary numbers start with 0b
|
||||||
|
0b01234311 // and should finish after a 2 or higher
|
||||||
|
|
||||||
|
// Floating-Point Numbers
|
||||||
|
// ----------------------
|
||||||
|
|
||||||
|
6.022E-23 // floating point notation
|
||||||
|
5.974e24 // lowercase e
|
||||||
|
7.348e+22 // uppercase E and plus
|
||||||
|
|
||||||
|
let tuple = ((8, 4), 48);
|
||||||
|
let a = tuple.0.0;
|
||||||
|
|
||||||
|
// Numeric Suffixes
|
||||||
|
// ----------------
|
||||||
|
|
||||||
|
123i32, 123u32 // numbers can have literals
|
||||||
|
123_u32, 0xff_u8
|
||||||
|
0o70_i16, 0b1111_1111_1001_0000_i32
|
||||||
|
0us, 7is
|
||||||
|
|
||||||
|
123.0f64
|
||||||
|
0.1f64
|
||||||
|
0.1f32
|
||||||
|
12E+99_f64
|
||||||
|
2.f64 // Invalid!
|
||||||
|
|
||||||
|
// Attributes
|
||||||
|
// ----------
|
||||||
|
|
||||||
|
#[attribute]
|
||||||
|
#[derive(This, That, Other)]
|
||||||
|
#![top_level_attribute]
|
||||||
|
#not_an_attribute
|
||||||
|
|
||||||
|
#[macro_use] use this_is_not_an_attribute;
|
||||||
|
|
||||||
|
// Macros
|
||||||
|
// ------
|
||||||
|
|
||||||
|
macro_rules! parse {
|
||||||
|
($thing: expr) => { $thing };
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user