Skip to content

Instantly share code, notes, and snippets.

@tomgrohl
Created January 25, 2012 20:19
Show Gist options
  • Save tomgrohl/1678423 to your computer and use it in GitHub Desktop.
Save tomgrohl/1678423 to your computer and use it in GitHub Desktop.
Rust Bundle for TextMate
{ scopeName = 'source.rs';
comment = 'Rust Syntax: version 0.1';
fileTypes = ( 'rs', 'jsx' );
foldingStartMarker = '^.*\bfn\s*(\w+\s*)?\([^\)]*\)(\s*\{[^\}]*)?\s*$';
foldingStopMarker = '^\s*\}';
patterns = (
{ name = 'meta.class.rs';
comment = 'match stuff like: Sound.prototype = { … } when extending an object';
match = '([a-zA-Z_?.$][\w?.$]*)\.(prototype)\s*(=)\s*';
captures = {
1 = { name = 'support.class.rs'; };
2 = { name = 'support.constant.rs'; };
3 = { name = 'keyword.operator.rs'; };
};
},
{ name = 'meta.fn.rs';
comment = 'match regular fn like: fn myFunc(arg) { … }';
match = '\b(fn)\s+([a-zA-Z_$]\w*)?\s*(\()(.*?)(\))';
captures = {
1 = { name = 'storage.type.fn.rs'; };
2 = { name = 'entity.name.fn.rs'; };
3 = { name = 'punctuation.definition.parameters.begin.rs'; };
4 = { name = 'variable.parameter.fn.rs'; };
5 = { name = 'punctuation.definition.parameters.end.rs'; };
};
},
{ name = 'meta.class.instance.constructor';
match = '(new)\s+(\w+(?:\.\w*)?)';
captures = {
1 = { name = 'keyword.operator.new.rs'; };
2 = { name = 'entity.name.type.instance.rs'; };
};
},
{ name = 'constant.numeric.rs';
match = '\b((0(x|X)[0-9a-fA-F]+)|([0-9]+(\.[0-9]+)?))\b';
},
{ name = 'string.quoted.single.rs';
begin = "'";
end = "'";
beginCaptures = { 0 = { name = 'punctuation.definition.string.begin.rs'; }; };
endCaptures = { 0 = { name = 'punctuation.definition.string.end.rs'; }; };
patterns = (
{ name = 'constant.character.escape.rs';
match = '\\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.)';
},
);
},
{ name = 'string.quoted.double.rs';
begin = '"';
end = '"';
beginCaptures = { 0 = { name = 'punctuation.definition.string.begin.rs'; }; };
endCaptures = { 0 = { name = 'punctuation.definition.string.end.rs'; }; };
patterns = (
{ name = 'constant.character.escape.rs';
match = '\\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]|37[0-7]?|[4-7][0-7]?|.)';
},
);
},
{ name = 'comment.block.documentation.rs';
begin = '/\*\*(?!/)';
end = '\*/';
captures = { 0 = { name = 'punctuation.definition.comment.rs'; }; };
},
{ name = 'comment.block.rs';
begin = '/\*';
end = '\*/';
captures = { 0 = { name = 'punctuation.definition.comment.rs'; }; };
},
{ name = 'comment.line.double-slash.rs';
match = '(//).*$\n?';
captures = { 1 = { name = 'punctuation.definition.comment.rs'; }; };
},
{ name = 'storage.type.rs';
match = '\b(bool|byte|char|class|double|enum|float|fn|int|use|uint|iface|impl|interface|long|type|short|ret|resource|str|var|mod|native|let|void)\b';
},
{ name = 'storage.modifier.rs';
match = '\b(const|export|extends|final|implements|native|private|protected|public|static|synchronized|throws|transient|volatile)\b';
},
{ name = 'keyword.control.rs';
match = '\b(\||break|alt|catch|continue|default|do|else|finally|for|to|if|import|package|return|switch|throw|try|while)\b';
},
{ name = 'keyword.operator.rs';
match = '\b(delete|in|instanceof|new|typeof|with|as)\b';
},
{ name = 'constant.language.boolean.true.rs';
match = '\btrue\b';
},
{ name = 'constant.language.boolean.false.rs';
match = '\bfalse\b';
},
{ name = 'constant.language.null.rs';
match = '\bnull\b';
},
{ name = 'variable.language.rs';
match = '\b(super|self)\b';
},
{ name = 'keyword.other.rs';
match = '\b(log,assert)\b';
},
{ name = 'support.class.rs';
match = '\b(std|str|io|float|consts|crypto|vec|unsafe|ptr)\b';
},
{ name = 'support.fn.rs';
match = '\b(s(h(ift|ow(Mod(elessDialog|alDialog)|Help))|croll(X|By(Pages|Lines)?|Y|To)?|t(op|rike)|i(n|zeToContent|debar|gnText)|ort|u(p|b(str(ing)?)?)|pli(ce|t)|e(nd|t(Re(sizable|questHeader)|M(i(nutes|lliseconds)|onth)|Seconds|Ho(tKeys|urs)|Year|Cursor|Time(out)?|Interval|ZOptions|Date|UTC(M(i(nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(ome|andleEvent)|navigate|c(har(CodeAt|At)|o(s|n(cat|textual|firm)|mpile)|eil|lear(Timeout|Interval)?|a(ptureEvents|ll)|reate(StyleSheet|Popup|EventObject))|t(o(GMTString|S(tring|ource)|U(TCString|pperCase)|Lo(caleString|werCase))|est|a(n|int(Enabled)?))|i(s(NaN|Finite)|ndexOf|talics)|d(isableExternalCapture|ump|etachEvent)|u(n(shift|taint|escape|watch)|pdateCommands)|j(oin|avaEnabled)|p(o(p|w)|ush|lugins.refresh|a(ddings|rse(Int|Float)?)|r(int|ompt|eference))|e(scape|nableExternalCapture|val|lementFromPoint|x(p|ec(Script|Command)?))|valueOf|UTC|queryCommand(State|Indeterm|Enabled|Value)|f(i(nd|le(ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(nt(size|color)|rward)|loor|romCharCode)|watch|l(ink|o(ad|g)|astIndexOf)|a(sin|nchor|cos|t(tachEvent|ob|an(2)?)|pply|lert|b(s|ort))|r(ou(nd|teEvents)|e(size(By|To)|calc|turnValue|place|verse|l(oad|ease(Capture|Events)))|andom)|g(o|et(ResponseHeader|M(i(nutes|lliseconds)|onth)|Se(conds|lection)|Hours|Year|Time(zoneOffset)?|Da(y|te)|UTC(M(i(nutes|lliseconds)|onth)|Seconds|Hours|Da(y|te)|FullYear)|FullYear|A(ttention|llResponseHeaders)))|m(in|ove(B(y|elow)|To(Absolute)?|Above)|ergeAttributes|a(tch|rgins|x))|b(toa|ig|o(ld|rderWidths)|link|ack))\b(?=\()';
},
{ name = 'support.constant.rs';
match = '(?<=\.)(s(ystemLanguage|cr(ipts|ollbars|een(X|Y|Top|Left))|t(yle(Sheets)?|atus(Text|bar)?)|ibling(Below|Above)|ource|uffixes|e(curity(Policy)?|l(ection|f)))|h(istory|ost(name)?|as(h|Focus))|y|X(MLDocument|SLDocument)|n(ext|ame(space(s|URI)|Prop))|M(IN_VALUE|AX_VALUE)|c(haracterSet|o(n(structor|trollers)|okieEnabled|lorDepth|mp(onents|lete))|urrent|puClass|l(i(p(boardData)?|entInformation)|osed|asses)|alle(e|r)|rypto)|t(o(olbar|p)|ext(Transform|Indent|Decoration|Align)|ags)|SQRT(1_2|2)|i(n(ner(Height|Width)|put)|ds|gnoreCase)|zIndex|o(scpu|n(readystatechange|Line)|uter(Height|Width)|p(sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(i(splay|alog(Height|Top|Width|Left|Arguments)|rectories)|e(scription|fault(Status|Ch(ecked|arset)|View)))|u(ser(Profile|Language|Agent)|n(iqueID|defined)|pdateInterval)|_content|p(ixelDepth|ort|ersonalbar|kcs11|l(ugins|atform)|a(thname|dding(Right|Bottom|Top|Left)|rent(Window|Layer)?|ge(X(Offset)?|Y(Offset)?))|r(o(to(col|type)|duct(Sub)?|mpter)|e(vious|fix)))|e(n(coding|abledPlugin)|x(ternal|pando)|mbeds)|v(isibility|endor(Sub)?|Linkcolor)|URLUnencoded|P(I|OSITIVE_INFINITY)|f(ilename|o(nt(Size|Family|Weight)|rmName)|rame(s|Element)|gColor)|E|whiteSpace|l(i(stStyleType|n(eHeight|kColor))|o(ca(tion(bar)?|lName)|wsrc)|e(ngth|ft(Context)?)|a(st(M(odified|atch)|Index|Paren)|yer(s|X)|nguage))|a(pp(MinorVersion|Name|Co(deName|re)|Version)|vail(Height|Top|Width|Left)|ll|r(ity|guments)|Linkcolor|bove)|r(ight(Context)?|e(sponse(XML|Text)|adyState))|global|x|m(imeTypes|ultiline|enubar|argin(Right|Bottom|Top|Left))|L(N(10|2)|OG(10E|2E))|b(o(ttom|rder(Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(Color|Image)))\b';
},
{ name = 'keyword.operator.rs';
match = '!|\$|%|&|\*|\-\-|\-|\+\+|\+|~|-->|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|(?<!\()/=|%=|\+=|\-=|&=|\^=|\b(in|instanceof|new|delete|typeof|void)\b';
},
{ name = 'constant.language.rs';
match = '\b(Infinity|NaN|undefined)\b';
},
{ name = 'string.regexp.rs';
begin = '(?<=[=(:]|^|ret)\s*(/)(?![/*+{}?])';
end = '(/)[igm]*';
beginCaptures = { 1 = { name = 'punctuation.definition.string.begin.rs'; }; };
endCaptures = { 1 = { name = 'punctuation.definition.string.end.rs'; }; };
patterns = (
{ name = 'constant.character.escape.rs';
match = '\\.';
},
);
},
{ name = 'punctuation.terminator.statement.rs';
match = '\;';
},
{ name = 'meta.delimiter.object.comma.rs';
match = ',[ |\t]*';
},
{ name = 'meta.delimiter.method.period.rs';
match = '\.';
},
{ name = 'meta.brace.curly.rs';
match = '\{|\}';
},
{ name = 'meta.brace.round.rs';
match = '\(|\)';
},
{ name = 'meta.brace.square.rs';
match = '\[|\]';
},
{
name = 'meta.fn.rs';
match = '(#)[a-zA-Z][a-zA-Z0-9_-]*';
}
);
}
@rwaldron
Copy link

@tomgrohl you should contribute this gist to this repo: https://github.com/DylanLukes/Rust.tmbundle

WIN! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment