More c/obj-c updates

This commit is contained in:
Garen Torikian 2012-09-09 22:56:00 -07:00 • committed by nightwing
commit ab8c3076c5
12 changed files with 1130 additions and 102 deletions

View file

@ -35,6 +35,9 @@ var oop = require("../lib/oop");
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
// used by objective-c
var cFunctions = exports.cFunctions = "\\s*\\bhypot(?:f|l)?|s(?:scanf|ystem|nprintf|ca(?:nf|lb(?:n(?:f|l)?|ln(?:f|l)?))|i(?:n(?:h(?:f|l)?|f|l)?|gn(?:al|bit))|tr(?:s(?:tr|pn)|nc(?:py|at|mp)|c(?:spn|hr|oll|py|at|mp)|to(?:imax|d|u(?:l(?:l)?|max)|k|f|l(?:d|l)?)|error|pbrk|ftime|len|rchr|xfrm)|printf|et(?:jmp|vbuf|locale|buf)|qrt(?:f|l)?|w(?:scanf|printf)|rand)|n(?:e(?:arbyint(?:f|l)?|xt(?:toward(?:f|l)?|after(?:f|l)?))|an(?:f|l)?)|c(?:s(?:in(?:h(?:f|l)?|f|l)?|qrt(?:f|l)?)|cos(?:h(?:f)?|f|l)?|imag(?:f|l)?|t(?:ime|an(?:h(?:f|l)?|f|l)?)|o(?:s(?:h(?:f|l)?|f|l)?|nj(?:f|l)?|pysign(?:f|l)?)|p(?:ow(?:f|l)?|roj(?:f|l)?)|e(?:il(?:f|l)?|xp(?:f|l)?)|l(?:o(?:ck|g(?:f|l)?)|earerr)|a(?:sin(?:h(?:f|l)?|f|l)?|cos(?:h(?:f|l)?|f|l)?|tan(?:h(?:f|l)?|f|l)?|lloc|rg(?:f|l)?|bs(?:f|l)?)|real(?:f|l)?|brt(?:f|l)?)|t(?:ime|o(?:upper|lower)|an(?:h(?:f|l)?|f|l)?|runc(?:f|l)?|gamma(?:f|l)?|mp(?:nam|file))|i(?:s(?:space|n(?:ormal|an)|cntrl|inf|digit|u(?:nordered|pper)|p(?:unct|rint)|finite|w(?:space|c(?:ntrl|type)|digit|upper|p(?:unct|rint)|lower|al(?:num|pha)|graph|xdigit|blank)|l(?:ower|ess(?:equal|greater)?)|al(?:num|pha)|gr(?:eater(?:equal)?|aph)|xdigit|blank)|logb(?:f|l)?|max(?:div|abs))|di(?:v|fftime)|_Exit|unget(?:c|wc)|p(?:ow(?:f|l)?|ut(?:s|c(?:har)?|wc(?:har)?)|error|rintf)|e(?:rf(?:c(?:f|l)?|f|l)?|x(?:it|p(?:2(?:f|l)?|f|l|m1(?:f|l)?)?))|v(?:s(?:scanf|nprintf|canf|printf|w(?:scanf|printf))|printf|f(?:scanf|printf|w(?:scanf|printf))|w(?:scanf|printf)|a_(?:start|copy|end|arg))|qsort|f(?:s(?:canf|e(?:tpos|ek))|close|tell|open|dim(?:f|l)?|p(?:classify|ut(?:s|c|w(?:s|c))|rintf)|e(?:holdexcept|set(?:e(?:nv|xceptflag)|round)|clearexcept|testexcept|of|updateenv|r(?:aiseexcept|ror)|get(?:e(?:nv|xceptflag)|round))|flush|w(?:scanf|ide|printf|rite)|loor(?:f|l)?|abs(?:f|l)?|get(?:s|c|pos|w(?:s|c))|re(?:open|e|ad|xp(?:f|l)?)|m(?:in(?:f|l)?|od(?:f|l)?|a(?:f|l|x(?:f|l)?)?))|l(?:d(?:iv|exp(?:f|l)?)|o(?:ngjmp|cal(?:time|econv)|g(?:1(?:p(?:f|l)?|0(?:f|l)?)|2(?:f|l)?|f|l|b(?:f|l)?)?)|abs|l(?:div|abs|r(?:int(?:f|l)?|ound(?:f|l)?))|r(?:int(?:f|l)?|ound(?:f|l)?)|gamma(?:f|l)?)|w(?:scanf|c(?:s(?:s(?:tr|pn)|nc(?:py|at|mp)|c(?:spn|hr|oll|py|at|mp)|to(?:imax|d|u(?:l(?:l)?|max)|k|f|l(?:d|l)?|mbs)|pbrk|ftime|len|r(?:chr|tombs)|xfrm)|to(?:b|mb)|rtomb)|printf|mem(?:set|c(?:hr|py|mp)|move))|a(?:s(?:sert|ctime|in(?:h(?:f|l)?|f|l)?)|cos(?:h(?:f|l)?|f|l)?|t(?:o(?:i|f|l(?:l)?)|exit|an(?:h(?:f|l)?|2(?:f|l)?|f|l)?)|b(?:s|ort))|g(?:et(?:s|c(?:har)?|env|wc(?:har)?)|mtime)|r(?:int(?:f|l)?|ound(?:f|l)?|e(?:name|alloc|wind|m(?:ove|quo(?:f|l)?|ainder(?:f|l)?))|a(?:nd|ise))|b(?:search|towc)|m(?:odf(?:f|l)?|em(?:set|c(?:hr|py|mp)|move)|ktime|alloc|b(?:s(?:init|towcs|rtowcs)|towc|len|r(?:towc|len)))\\b"
var c_cppHighlightRules = function() {
var keywordControls = (
@ -118,7 +121,7 @@ var c_cppHighlightRules = function() {
regex : "(?:#include|#pragma|#line|#define|#undef|#ifdef|#else|#elif|#endif|#ifndef)"
}, {
token : "support.function.C99.c",
regex : "\\s*\\bhypot(?:f|l)?|s(?:scanf|ystem|nprintf|ca(?:nf|lb(?:n(?:f|l)?|ln(?:f|l)?))|i(?:n(?:h(?:f|l)?|f|l)?|gn(?:al|bit))|tr(?:s(?:tr|pn)|nc(?:py|at|mp)|c(?:spn|hr|oll|py|at|mp)|to(?:imax|d|u(?:l(?:l)?|max)|k|f|l(?:d|l)?)|error|pbrk|ftime|len|rchr|xfrm)|printf|et(?:jmp|vbuf|locale|buf)|qrt(?:f|l)?|w(?:scanf|printf)|rand)|n(?:e(?:arbyint(?:f|l)?|xt(?:toward(?:f|l)?|after(?:f|l)?))|an(?:f|l)?)|c(?:s(?:in(?:h(?:f|l)?|f|l)?|qrt(?:f|l)?)|cos(?:h(?:f)?|f|l)?|imag(?:f|l)?|t(?:ime|an(?:h(?:f|l)?|f|l)?)|o(?:s(?:h(?:f|l)?|f|l)?|nj(?:f|l)?|pysign(?:f|l)?)|p(?:ow(?:f|l)?|roj(?:f|l)?)|e(?:il(?:f|l)?|xp(?:f|l)?)|l(?:o(?:ck|g(?:f|l)?)|earerr)|a(?:sin(?:h(?:f|l)?|f|l)?|cos(?:h(?:f|l)?|f|l)?|tan(?:h(?:f|l)?|f|l)?|lloc|rg(?:f|l)?|bs(?:f|l)?)|real(?:f|l)?|brt(?:f|l)?)|t(?:ime|o(?:upper|lower)|an(?:h(?:f|l)?|f|l)?|runc(?:f|l)?|gamma(?:f|l)?|mp(?:nam|file))|i(?:s(?:space|n(?:ormal|an)|cntrl|inf|digit|u(?:nordered|pper)|p(?:unct|rint)|finite|w(?:space|c(?:ntrl|type)|digit|upper|p(?:unct|rint)|lower|al(?:num|pha)|graph|xdigit|blank)|l(?:ower|ess(?:equal|greater)?)|al(?:num|pha)|gr(?:eater(?:equal)?|aph)|xdigit|blank)|logb(?:f|l)?|max(?:div|abs))|di(?:v|fftime)|_Exit|unget(?:c|wc)|p(?:ow(?:f|l)?|ut(?:s|c(?:har)?|wc(?:har)?)|error|rintf)|e(?:rf(?:c(?:f|l)?|f|l)?|x(?:it|p(?:2(?:f|l)?|f|l|m1(?:f|l)?)?))|v(?:s(?:scanf|nprintf|canf|printf|w(?:scanf|printf))|printf|f(?:scanf|printf|w(?:scanf|printf))|w(?:scanf|printf)|a_(?:start|copy|end|arg))|qsort|f(?:s(?:canf|e(?:tpos|ek))|close|tell|open|dim(?:f|l)?|p(?:classify|ut(?:s|c|w(?:s|c))|rintf)|e(?:holdexcept|set(?:e(?:nv|xceptflag)|round)|clearexcept|testexcept|of|updateenv|r(?:aiseexcept|ror)|get(?:e(?:nv|xceptflag)|round))|flush|w(?:scanf|ide|printf|rite)|loor(?:f|l)?|abs(?:f|l)?|get(?:s|c|pos|w(?:s|c))|re(?:open|e|ad|xp(?:f|l)?)|m(?:in(?:f|l)?|od(?:f|l)?|a(?:f|l|x(?:f|l)?)?))|l(?:d(?:iv|exp(?:f|l)?)|o(?:ngjmp|cal(?:time|econv)|g(?:1(?:p(?:f|l)?|0(?:f|l)?)|2(?:f|l)?|f|l|b(?:f|l)?)?)|abs|l(?:div|abs|r(?:int(?:f|l)?|ound(?:f|l)?))|r(?:int(?:f|l)?|ound(?:f|l)?)|gamma(?:f|l)?)|w(?:scanf|c(?:s(?:s(?:tr|pn)|nc(?:py|at|mp)|c(?:spn|hr|oll|py|at|mp)|to(?:imax|d|u(?:l(?:l)?|max)|k|f|l(?:d|l)?|mbs)|pbrk|ftime|len|r(?:chr|tombs)|xfrm)|to(?:b|mb)|rtomb)|printf|mem(?:set|c(?:hr|py|mp)|move))|a(?:s(?:sert|ctime|in(?:h(?:f|l)?|f|l)?)|cos(?:h(?:f|l)?|f|l)?|t(?:o(?:i|f|l(?:l)?)|exit|an(?:h(?:f|l)?|2(?:f|l)?|f|l)?)|b(?:s|ort))|g(?:et(?:s|c(?:har)?|env|wc(?:har)?)|mtime)|r(?:int(?:f|l)?|ound(?:f|l)?|e(?:name|alloc|wind|m(?:ove|quo(?:f|l)?|ainder(?:f|l)?))|a(?:nd|ise))|b(?:search|towc)|m(?:odf(?:f|l)?|em(?:set|c(?:hr|py|mp)|move)|ktime|alloc|b(?:s(?:init|towcs|rtowcs)|towc|len|r(?:towc|len)))\\b"
regex : cFunctions
}, {
// function myFunc(arg) { }
token : [

View file

@ -41,24 +41,48 @@ define(function(require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var CHighlightRules = require("./c_cpp_highlight_rules").c_cppHighlightRules;
var escapedConstRe = "\\\\(?:[abefnrtv'\"?\\\\]|" +
"[0-3]\\d{1,2}|" +
"[4-7]\\d?|" +
"222|" +
"x[a-zA-Z0-9]+)";
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
var C_Highlight_File = require("./c_cpp_highlight_rules");
var CHighlightRules = C_Highlight_File.c_cppHighlightRules;
var ObjectiveCHighlightRules = function() {
// regexp must not have capturing parentheses. Use (?:) instead.
// regexps are ordered -> the first match is used
var escapedConstRe = "\\\\(?:[abefnrtv'\"?\\\\]|" +
"[0-3]\\d{1,2}|" +
"[4-7]\\d?|" +
"222|" +
"x[a-zA-Z0-9]+)";
var specialVariables = [
{
"regex": "\\b_cmd\\b",
"token": "variable.other.selector.objc"
},
{
"regex": "\\b(?:self|super)\\b",
"token": "variable.language.objc"
}
];
var cRules = new CHighlightRules().getRules();
this.$rules =
{
"start": [
"start": [
{
token : "comment",
regex : "\\/\\/.*$"
},
DocCommentHighlightRules.getStartRule("doc-start"),
{
token : "comment", // multi line comment
merge : true,
regex : "\\/\\*",
next : "comment"
},
{
"token": [ "storage.type.objc", "punctuation.definition.storage.type.objc",
"entity.name.type.objc", "text", "punctuation.definition.entity.other.inherited-class.objc",
@ -68,10 +92,10 @@ var ObjectiveCHighlightRules = function() {
"next": "interface_protocol"
},
{
"token": [ "storage.type.objc", "punctuation.definition.storage.type.objc",
"entity.name.type.objc", "entity.other.inherited-class.objc"
"token": [ "storage.type.objc", "entity.name.type.objc",
"entity.other.inherited-class.objc"
],
"regex": "@(implementation)(\\s+[A-Za-z_][A-Za-z0-9_]*)(\\s*?::\\s*([A-Za-z][A-Za-z0-9]*))?",
"regex": "(@implementation)(\\s+[A-Za-z_][A-Za-z0-9_]*)(\\s*?::\\s*(?:[A-Za-z][A-Za-z0-9]*))?",
"next": "implementation"
},
{
@ -181,6 +205,11 @@ var ObjectiveCHighlightRules = function() {
"token": "punctuation.section.scope.begin.objc",
"regex": "\\[",
"next": "bracketed_content"
},
{
"token": "meta.function.objc",
"regex": "^(?:-|\\+)\\s*",
"next": "methods"
}
],
"interface_protocol": [
@ -251,24 +280,130 @@ var ObjectiveCHighlightRules = function() {
"next": "start"
},
{
"token": ["support.function.any-method.objc", "punctuation.separator.arguments.objc"],
"regex": "(?=predicateWithFormat:)(NSPredicate )(predicateWithFormat:)",
"token": ["support.function.any-method.objc"],
"regex": "(?:predicateWithFormat:| NSPredicate predicateWithFormat:)",
"next": "predicates"
},
{
"token": "support.function.C99.c",
"regex": C_Highlight_File.cFunctions
}
],
"predicates": [
{
"token": "punctuation.section.scope.end.objc",
"regex": "\]",
"next": "start"
},
{
"token": ["support.function.any-method.name-of-parameter.objc", "punctuation.separator.arguments.objc"],
"regex": "\\b(argument(?:Array|s))(:)"
},
{
"token": ["invalid.illegal.unknown-method.objc", "punctuation.separator.arguments.objc"],
"regex": "\\b(\w+)(:)"
},
{
"token": "punctuation.definition.string.begin.sdfsaf.objc",
"regex": '@"',
"next": "bracketed_strings"
}
],
"bracketed_strings": [
{
"token": "punctuation.section.scope.end.objc",
"regex": "\]",
"next": "start"
},
{
"token": "keyword.operator.logical.predicate.cocoa",
"regex": "\\b(?:AND|OR|NOT|IN)\\b"
},
{
"token": ["invalid.illegal.unknown-method.objc", "punctuation.separator.arguments.objc"],
"regex": "\\b(\w+)(:)"
},
{
"regex": "\\b(?:ALL|ANY|SOME|NONE)\\b",
"token": "constant.language.predicate.cocoa"
},
{
"regex": "\\b(?:NULL|NIL|SELF|TRUE|YES|FALSE|NO|FIRST|LAST|SIZE)\\b",
"token": "constant.language.predicate.cocoa"
},
{
"regex": "\\b(?:MATCHES|CONTAINS|BEGINSWITH|ENDSWITH|BETWEEN)\\b",
"token": "keyword.operator.comparison.predicate.cocoa"
},
{
"regex": "\\bC(?:ASEINSENSITIVE|I)\\b",
"token": "keyword.other.modifier.predicate.cocoa"
},
{
"regex": "\\b(?:ANYKEY|SUBQUERY|CAST|TRUEPREDICATE|FALSEPREDICATE)\\b",
"token": "keyword.other.predicate.cocoa"
},
{
"regex": escapedConstRe,
"token": "constant.character.escape.objc"
},
{
"regex": "\\\\.",
"token": "invalid.illegal.unknown-escape.objc"
},
{
"token": "string",
"regex": '[^"\\\\]'
},
{
"token": "punctuation.definition.string.end.objc",
"regex": "\"",
"next": "predicates"
}
],
"comment" : [
{
token : "comment", // closing comment
regex : ".*?\\*\\/",
next : "start"
}, {
token : "comment", // comment spanning whole line
merge : true,
regex : ".+"
}
],
"methods" : [
{
token : "meta.function.objc",
regex : "(?=\\{|#)|;",
next : "start"
}
]
}
// copy in C-Rules directly
for (var r in cRules) {
if (r == "start") {
for (var key in cRules[r]) {
this.$rules.start.push(cRules[r][key])
// copy in C-Rules directly
for (var r in cRules) {
if (r == "start") {
for (var key in cRules[r]) {
this.$rules.start.push(cRules[r][key])
}
}
else {
this.$rules[r] = cRules[r];
}
}
else {
this.$rules[r] = cRules[r];
var startRules = this.$rules.start;
for (var s in startRules) {
this.$rules.bracketed_content.push(startRules[s]);
}
}
for (var s in specialVariables) {
this.$rules.bracketed_content.push(specialVariables[s]);
}
this.embedRules(DocCommentHighlightRules, "doc-",
[ DocCommentHighlightRules.getEndRule("start") ]);
};
oop.inherits(ObjectiveCHighlightRules, CHighlightRules);