From 43f966bd5fec5f2493b04b58801321644e3860d8 Mon Sep 17 00:00:00 2001 From: nightwing Date: Fri, 31 Aug 2012 19:21:47 +0400 Subject: [PATCH] convert rest of the modes to new style --- lib/ace/mode/_test/tokens_liquid.json | 2 +- lib/ace/mode/c_cpp_highlight_rules.js | 30 ++- lib/ace/mode/clojure_highlight_rules.js | 164 +++++++------- lib/ace/mode/coffee_highlight_rules.js | 69 +++--- lib/ace/mode/csharp_highlight_rules.js | 28 +-- lib/ace/mode/css_highlight_rules.js | 59 +---- lib/ace/mode/glsl_highlight_rules.js | 32 ++- lib/ace/mode/golang_highlight_rules.js | 37 ++-- lib/ace/mode/groovy_highlight_rules.js | 64 +++--- lib/ace/mode/haxe_highlight_rules.js | 26 +-- lib/ace/mode/java_highlight_rules.js | 48 ++-- lib/ace/mode/liquid_highlight_rules.js | 244 ++++++++++----------- lib/ace/mode/lua_highlight_rules.js | 115 +++++----- lib/ace/mode/ocaml_highlight_rules.js | 31 ++- lib/ace/mode/perl_highlight_rules.js | 34 ++- lib/ace/mode/pgsql_highlight_rules.js | 57 +++-- lib/ace/mode/powershell_highlight_rules.js | 32 ++- lib/ace/mode/python_highlight_rules.js | 43 ++-- lib/ace/mode/ruby_highlight_rules.js | 54 ++--- lib/ace/mode/scad_highlight_rules.js | 26 +-- lib/ace/mode/scala_highlight_rules.js | 48 ++-- lib/ace/mode/sh_highlight_rules.js | 28 +-- lib/ace/mode/sql_highlight_rules.js | 33 ++- lib/ace/mode/tcl_highlight_rules.js | 14 +- lib/ace/mode/xquery_highlight_rules.js | 16 +- 25 files changed, 562 insertions(+), 772 deletions(-) diff --git a/lib/ace/mode/_test/tokens_liquid.json b/lib/ace/mode/_test/tokens_liquid.json index 36a09bc2..779eeb8f 100644 --- a/lib/ace/mode/_test/tokens_liquid.json +++ b/lib/ace/mode/_test/tokens_liquid.json @@ -1060,7 +1060,7 @@ "text", "keyword", "text", - "identifier", + "variable.language", "text", "identifier", "text", diff --git a/lib/ace/mode/c_cpp_highlight_rules.js b/lib/ace/mode/c_cpp_highlight_rules.js index 236b7284..5f021dbb 100644 --- a/lib/ace/mode/c_cpp_highlight_rules.js +++ b/lib/ace/mode/c_cpp_highlight_rules.js @@ -42,27 +42,32 @@ define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); -var lang = require("../lib/lang"); var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules; var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var c_cppHighlightRules = function() { - var keywords = lang.arrayToMap( - ("and|double|not_eq|throw|and_eq|dynamic_cast|operator|true|" + + var keywords = ( + "and|double|not_eq|throw|and_eq|dynamic_cast|operator|true|" + "asm|else|or|try|auto|enum|or_eq|typedef|bitand|explicit|private|" + "typeid|bitor|extern|protected|typename|bool|false|public|union|" + "break|float|register|unsigned|case|fro|reinterpret-cast|using|catch|" + "friend|return|virtual|char|goto|short|void|class|if|signed|volatile|" + "compl|inline|sizeof|wchar_t|const|int|static|while|const-cast|long|" + "static_cast|xor|continue|mutable|struct|xor_eq|default|namespace|" + - "switch|delete|new|template|do|not|this|for").split("|") + "switch|delete|new|template|do|not|this|for" ); - var buildinConstants = lang.arrayToMap( - ("NULL").split("|") + var buildinConstants = ( + "NULL" ); + var keywordMapper = this.createKeywordMapper({ + "variable.language": "this", + "keyword": keywords, + "constant.language": buildinConstants + }, "identifier"); + // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -107,16 +112,7 @@ var c_cppHighlightRules = function() { token : "keyword", // pre-compiler directivs regex : "(?:#include|#pragma|#line|#define|#undef|#ifdef|#else|#elif|#endif|#ifndef)" }, { - token : function(value) { - if (value == "this") - return "variable.language"; - else if (keywords.hasOwnProperty(value)) - return "keyword"; - else if (buildinConstants.hasOwnProperty(value)) - return "constant.language"; - else - return "identifier"; - }, + token : keywordMapper, regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" }, { token : "keyword.operator", @@ -169,7 +165,7 @@ var c_cppHighlightRules = function() { } ] }; - + this.embedRules(DocCommentHighlightRules, "doc-", [ DocCommentHighlightRules.getEndRule("start") ]); }; diff --git a/lib/ace/mode/clojure_highlight_rules.js b/lib/ace/mode/clojure_highlight_rules.js index 3ac380c3..8865c3af 100644 --- a/lib/ace/mode/clojure_highlight_rules.js +++ b/lib/ace/mode/clojure_highlight_rules.js @@ -41,93 +41,94 @@ define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); -var lang = require("../lib/lang"); var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var ClojureHighlightRules = function() { - var builtinFunctions = lang.arrayToMap( - ('* *1 *2 *3 *agent* *allow-unresolved-vars* *assert* *clojure-version* ' + - '*command-line-args* *compile-files* *compile-path* *e *err* *file* ' + - '*flush-on-newline* *in* *macro-meta* *math-context* *ns* *out* ' + - '*print-dup* *print-length* *print-level* *print-meta* *print-readably* ' + - '*read-eval* *source-path* *use-context-classloader* ' + - '*warn-on-reflection* + - -> -> ->> ->> .. / < < <= <= = ' + - '== > > >= >= accessor aclone ' + - 'add-classpath add-watch agent agent-errors aget alength alias all-ns ' + - 'alter alter-meta! alter-var-root amap ancestors and apply areduce ' + - 'array-map aset aset-boolean aset-byte aset-char aset-double aset-float ' + - 'aset-int aset-long aset-short assert assoc assoc! assoc-in associative? ' + - 'atom await await-for await1 bases bean bigdec bigint binding bit-and ' + - 'bit-and-not bit-clear bit-flip bit-not bit-or bit-set bit-shift-left ' + - 'bit-shift-right bit-test bit-xor boolean boolean-array booleans ' + - 'bound-fn bound-fn* butlast byte byte-array bytes cast char char-array ' + - 'char-escape-string char-name-string char? chars chunk chunk-append ' + - 'chunk-buffer chunk-cons chunk-first chunk-next chunk-rest chunked-seq? ' + - 'class class? clear-agent-errors clojure-version coll? comment commute ' + - 'comp comparator compare compare-and-set! compile complement concat cond ' + - 'condp conj conj! cons constantly construct-proxy contains? count ' + - 'counted? create-ns create-struct cycle dec decimal? declare definline ' + - 'defmacro defmethod defmulti defn defn- defonce defstruct delay delay? ' + - 'deliver deref derive descendants destructure disj disj! dissoc dissoc! ' + - 'distinct distinct? doall doc dorun doseq dosync dotimes doto double ' + - 'double-array doubles drop drop-last drop-while empty empty? ensure ' + - 'enumeration-seq eval even? every? false? ffirst file-seq filter find ' + - 'find-doc find-ns find-var first float float-array float? floats flush ' + - 'fn fn? fnext for force format future future-call future-cancel ' + - 'future-cancelled? future-done? future? gen-class gen-interface gensym ' + - 'get get-in get-method get-proxy-class get-thread-bindings get-validator ' + - 'hash hash-map hash-set identical? identity if-let if-not ifn? import ' + - 'in-ns inc init-proxy instance? int int-array integer? interleave intern ' + - 'interpose into into-array ints io! isa? iterate iterator-seq juxt key ' + - 'keys keyword keyword? last lazy-cat lazy-seq let letfn line-seq list ' + - 'list* list? load load-file load-reader load-string loaded-libs locking ' + - 'long long-array longs loop macroexpand macroexpand-1 make-array ' + - 'make-hierarchy map map? mapcat max max-key memfn memoize merge ' + - 'merge-with meta method-sig methods min min-key mod name namespace neg? ' + - 'newline next nfirst nil? nnext not not-any? not-empty not-every? not= ' + - 'ns ns-aliases ns-imports ns-interns ns-map ns-name ns-publics ' + - 'ns-refers ns-resolve ns-unalias ns-unmap nth nthnext num number? odd? ' + - 'or parents partial partition pcalls peek persistent! pmap pop pop! ' + - 'pop-thread-bindings pos? pr pr-str prefer-method prefers ' + - 'primitives-classnames print print-ctor print-doc print-dup print-method ' + - 'print-namespace-doc print-simple print-special-doc print-str printf ' + - 'println println-str prn prn-str promise proxy proxy-call-with-super ' + - 'proxy-mappings proxy-name proxy-super push-thread-bindings pvalues quot ' + - 'rand rand-int range ratio? rational? rationalize re-find re-groups ' + - 're-matcher re-matches re-pattern re-seq read read-line read-string ' + - 'reduce ref ref-history-count ref-max-history ref-min-history ref-set ' + - 'refer refer-clojure release-pending-sends rem remove remove-method ' + - 'remove-ns remove-watch repeat repeatedly replace replicate require ' + - 'reset! reset-meta! resolve rest resultset-seq reverse reversible? rseq ' + - 'rsubseq second select-keys send send-off seq seq? seque sequence ' + - 'sequential? set set-validator! set? short short-array shorts ' + - 'shutdown-agents slurp some sort sort-by sorted-map sorted-map-by ' + - 'sorted-set sorted-set-by sorted? special-form-anchor special-symbol? ' + - 'split-at split-with str stream? string? struct struct-map subs subseq ' + - 'subvec supers swap! symbol symbol? sync syntax-symbol-anchor take ' + - 'take-last take-nth take-while test the-ns time to-array to-array-2d ' + - 'trampoline transient tree-seq true? type unchecked-add unchecked-dec ' + - 'unchecked-divide unchecked-inc unchecked-multiply unchecked-negate ' + - 'unchecked-remainder unchecked-subtract underive unquote ' + - 'unquote-splicing update-in update-proxy use val vals var-get var-set ' + - 'var? vary-meta vec vector vector? when when-first when-let when-not ' + - 'while with-bindings with-bindings* with-in-str with-loading-context ' + - 'with-local-vars with-meta with-open with-out-str with-precision xml-seq ' + - 'zero? zipmap ').split(" ") + var builtinFunctions = ( + '* *1 *2 *3 *agent* *allow-unresolved-vars* *assert* *clojure-version* ' + + '*command-line-args* *compile-files* *compile-path* *e *err* *file* ' + + '*flush-on-newline* *in* *macro-meta* *math-context* *ns* *out* ' + + '*print-dup* *print-length* *print-level* *print-meta* *print-readably* ' + + '*read-eval* *source-path* *use-context-classloader* ' + + '*warn-on-reflection* + - -> ->> .. / < <= = ' + + '== > > >= >= accessor aclone ' + + 'add-classpath add-watch agent agent-errors aget alength alias all-ns ' + + 'alter alter-meta! alter-var-root amap ancestors and apply areduce ' + + 'array-map aset aset-boolean aset-byte aset-char aset-double aset-float ' + + 'aset-int aset-long aset-short assert assoc assoc! assoc-in associative? ' + + 'atom await await-for await1 bases bean bigdec bigint binding bit-and ' + + 'bit-and-not bit-clear bit-flip bit-not bit-or bit-set bit-shift-left ' + + 'bit-shift-right bit-test bit-xor boolean boolean-array booleans ' + + 'bound-fn bound-fn* butlast byte byte-array bytes cast char char-array ' + + 'char-escape-string char-name-string char? chars chunk chunk-append ' + + 'chunk-buffer chunk-cons chunk-first chunk-next chunk-rest chunked-seq? ' + + 'class class? clear-agent-errors clojure-version coll? comment commute ' + + 'comp comparator compare compare-and-set! compile complement concat cond ' + + 'condp conj conj! cons constantly construct-proxy contains? count ' + + 'counted? create-ns create-struct cycle dec decimal? declare definline ' + + 'defmacro defmethod defmulti defn defn- defonce defstruct delay delay? ' + + 'deliver deref derive descendants destructure disj disj! dissoc dissoc! ' + + 'distinct distinct? doall doc dorun doseq dosync dotimes doto double ' + + 'double-array doubles drop drop-last drop-while empty empty? ensure ' + + 'enumeration-seq eval even? every? false? ffirst file-seq filter find ' + + 'find-doc find-ns find-var first float float-array float? floats flush ' + + 'fn fn? fnext for force format future future-call future-cancel ' + + 'future-cancelled? future-done? future? gen-class gen-interface gensym ' + + 'get get-in get-method get-proxy-class get-thread-bindings get-validator ' + + 'hash hash-map hash-set identical? identity if-let if-not ifn? import ' + + 'in-ns inc init-proxy instance? int int-array integer? interleave intern ' + + 'interpose into into-array ints io! isa? iterate iterator-seq juxt key ' + + 'keys keyword keyword? last lazy-cat lazy-seq let letfn line-seq list ' + + 'list* list? load load-file load-reader load-string loaded-libs locking ' + + 'long long-array longs loop macroexpand macroexpand-1 make-array ' + + 'make-hierarchy map map? mapcat max max-key memfn memoize merge ' + + 'merge-with meta method-sig methods min min-key mod name namespace neg? ' + + 'newline next nfirst nil? nnext not not-any? not-empty not-every? not= ' + + 'ns ns-aliases ns-imports ns-interns ns-map ns-name ns-publics ' + + 'ns-refers ns-resolve ns-unalias ns-unmap nth nthnext num number? odd? ' + + 'or parents partial partition pcalls peek persistent! pmap pop pop! ' + + 'pop-thread-bindings pos? pr pr-str prefer-method prefers ' + + 'primitives-classnames print print-ctor print-doc print-dup print-method ' + + 'print-namespace-doc print-simple print-special-doc print-str printf ' + + 'println println-str prn prn-str promise proxy proxy-call-with-super ' + + 'proxy-mappings proxy-name proxy-super push-thread-bindings pvalues quot ' + + 'rand rand-int range ratio? rational? rationalize re-find re-groups ' + + 're-matcher re-matches re-pattern re-seq read read-line read-string ' + + 'reduce ref ref-history-count ref-max-history ref-min-history ref-set ' + + 'refer refer-clojure release-pending-sends rem remove remove-method ' + + 'remove-ns remove-watch repeat repeatedly replace replicate require ' + + 'reset! reset-meta! resolve rest resultset-seq reverse reversible? rseq ' + + 'rsubseq second select-keys send send-off seq seq? seque sequence ' + + 'sequential? set set-validator! set? short short-array shorts ' + + 'shutdown-agents slurp some sort sort-by sorted-map sorted-map-by ' + + 'sorted-set sorted-set-by sorted? special-form-anchor special-symbol? ' + + 'split-at split-with str stream? string? struct struct-map subs subseq ' + + 'subvec supers swap! symbol symbol? sync syntax-symbol-anchor take ' + + 'take-last take-nth take-while test the-ns time to-array to-array-2d ' + + 'trampoline transient tree-seq true? type unchecked-add unchecked-dec ' + + 'unchecked-divide unchecked-inc unchecked-multiply unchecked-negate ' + + 'unchecked-remainder unchecked-subtract underive unquote ' + + 'unquote-splicing update-in update-proxy use val vals var-get var-set ' + + 'var? vary-meta vec vector vector? when when-first when-let when-not ' + + 'while with-bindings with-bindings* with-in-str with-loading-context ' + + 'with-local-vars with-meta with-open with-out-str with-precision xml-seq ' + + 'zero? zipmap' ); - var keywords = lang.arrayToMap( - ('def do fn if let loop monitor-enter monitor-exit new quote recur set! ' + - 'throw try var').split(" ") + var keywords = ('throw try var ' + + 'def do fn if let loop monitor-enter monitor-exit new quote recur set!' ); - var buildinConstants = lang.arrayToMap( - ("true false nil").split(" ") - ); + var buildinConstants = ("true false nil"); + var keywordMapper = this.createKeywordMapper({ + "keyword": keywords, + "constant.language": buildinConstants, + "support.function": builtinFunctions + }, "identifier", false, " "); // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -175,16 +176,7 @@ var ClojureHighlightRules = function() { token : "constant.language", regex : '[!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+||=|!=|<=|>=|<>|<|>|!|&&]' }, { - token : function(value) { - if (keywords.hasOwnProperty(value)) - return "keyword"; - else if (buildinConstants.hasOwnProperty(value)) - return "constant.language"; - else if (builtinFunctions.hasOwnProperty(value)) - return "support.function"; - else - return "identifier"; - }, + token : keywordMapper, // TODO: Unicode escape sequences // TODO: Unicode identifiers regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" diff --git a/lib/ace/mode/coffee_highlight_rules.js b/lib/ace/mode/coffee_highlight_rules.js index d3fe7884..ffe6319e 100644 --- a/lib/ace/mode/coffee_highlight_rules.js +++ b/lib/ace/mode/coffee_highlight_rules.js @@ -38,10 +38,9 @@ define(function(require, exports, module) { "use strict"; - var lang = require("../lib/lang"); var oop = require("../lib/oop"); var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; - + oop.inherits(CoffeeHighlightRules, TextHighlightRules); function CoffeeHighlightRules() { @@ -52,34 +51,41 @@ define(function(require, exports, module) { regex : ".+" }; - var keywords = lang.arrayToMap(( + var keywords = ( "this|throw|then|try|typeof|super|switch|return|break|by)|continue|" + "catch|class|in|instanceof|is|isnt|if|else|extends|for|forown|" + "finally|function|while|when|new|no|not|delete|debugger|do|loop|of|off|" + - "or|on|unless|until|and|yes").split("|") + "or|on|unless|until|and|yes" ); - - var langConstant = lang.arrayToMap(( - "true|false|null|undefined").split("|") + + var langConstant = ( + "true|false|null|undefined" ); - - var illegal = lang.arrayToMap(( + + var illegal = ( "case|const|default|function|var|void|with|enum|export|implements|" + "interface|let|package|private|protected|public|static|yield|" + - "__hasProp|extends|slice|bind|indexOf").split("|") + "__hasProp|extends|slice|bind|indexOf" ); - - var supportClass = lang.arrayToMap(( + + var supportClass = ( "Array|Boolean|Date|Function|Number|Object|RegExp|ReferenceError|" + - "RangeError|String|SyntaxError|Error|EvalError|TypeError|URIError").split("|") + "String|RangeError|SyntaxError|Error|EvalError|TypeError|URIError" ); - - var supportFunction = lang.arrayToMap(( + + var supportFunction = ( "Math|JSON|isNaN|isFinite|parseInt|parseFloat|encodeURI|" + - "encodeURIComponent|decodeURI|decodeURIComponent|RangeError|String|" + - "SyntaxError|Error|EvalError|TypeError|URIError").split("|") + "encodeURIComponent|decodeURI|decodeURIComponent|String|" ); + var keywordMapper = this.createKeywordMapper({ + "keyword": keywords, + "constant.language": langConstant, + "invalid.illegal": illegal, + "language.support.class": supportClass, + "language.support.function": supportFunction, + }, "identifier"); + this.$rules = { start : [ { @@ -89,20 +95,7 @@ define(function(require, exports, module) { token : "variable", regex : "@(?:" + identifier + ")?" }, { - token: function(value) { - if (keywords.hasOwnProperty(value)) - return "keyword"; - else if (langConstant.hasOwnProperty(value)) - return "constant.language"; - else if (illegal.hasOwnProperty(value)) - return "invalid.illegal"; - else if (supportClass.hasOwnProperty(value)) - return "language.support.class"; - else if (supportFunction.hasOwnProperty(value)) - return "language.support.function"; - else - return "identifier"; - }, + token: keywordMapper, regex : identifier }, { token : "constant.numeric", @@ -164,40 +157,40 @@ define(function(require, exports, module) { token : "text", regex : "\\s+" }], - + qdoc : [{ token : "string", regex : ".*?'''", next : "start" }, stringfill], - + qqdoc : [{ token : "string", regex : '.*?"""', next : "start" }, stringfill], - + qstring : [{ token : "string", regex : "[^\\\\']*(?:\\\\.[^\\\\']*)*'", merge : true, next : "start" }, stringfill], - + qqstring : [{ token : "string", regex : '[^\\\\"]*(?:\\\\.[^\\\\"]*)*"', merge : true, next : "start" }, stringfill], - + js : [{ token : "string", merge : true, regex : "[^\\\\`]*(?:\\\\.[^\\\\`]*)*`", next : "start" }, stringfill], - + heregex : [{ token : "string.regex", regex : '.*?///[imgy]{0,4}', @@ -210,7 +203,7 @@ define(function(require, exports, module) { merge : true, regex : "\\S+" }], - + comment : [{ token : "comment", regex : '.*?###', diff --git a/lib/ace/mode/csharp_highlight_rules.js b/lib/ace/mode/csharp_highlight_rules.js index 7713e40b..22bbd82c 100644 --- a/lib/ace/mode/csharp_highlight_rules.js +++ b/lib/ace/mode/csharp_highlight_rules.js @@ -2,20 +2,15 @@ define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); -var lang = require("../lib/lang"); var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules; var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var CSharpHighlightRules = function() { - - var keywords = lang.arrayToMap( - ("abstract|event|new|struct|as|explicit|null|switch|base|extern|object|this|bool|false|operator|throw|break|finally|out|true|byte|fixed|override|try|case|float|params|typeof|catch|for|private|uint|char|foreach|protected|ulong|checked|goto|public|unchecked|class|if|readonly|unsafe|const|implicit|ref|ushort|continue|in|return|using|decimal|int|sbyte|virtual|default|interface|sealed|volatile|delegate|internal|short|void|do|is|sizeof|while|double|lock|stackalloc|else|long|static|enum|namespace|string|var|dynamic").split("|") - ); - - var buildinConstants = lang.arrayToMap( - ("null|true|false").split("|") - ); - + var keywordMapper = this.createKeywordMapper({ + "variable.language": "this", + "keyword": "abstract|event|new|struct|as|explicit|null|switch|base|extern|object|this|bool|false|operator|throw|break|finally|out|true|byte|fixed|override|try|case|float|params|typeof|catch|for|private|uint|char|foreach|protected|ulong|checked|goto|public|unchecked|class|if|readonly|unsafe|const|implicit|ref|ushort|continue|in|return|using|decimal|int|sbyte|virtual|default|interface|sealed|volatile|delegate|internal|short|void|do|is|sizeof|while|double|lock|stackalloc|else|long|static|enum|namespace|string|var|dynamic", + "constant.language": "null|true|false" + }, "identifier"); // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -51,16 +46,7 @@ var CSharpHighlightRules = function() { token : "constant.language.boolean", regex : "(?:true|false)\\b" }, { - token : function(value) { - if (value == "this") - return "variable.language"; - else if (keywords.hasOwnProperty(value)) - return "keyword"; - else if (buildinConstants.hasOwnProperty(value)) - return "constant.language"; - else - return "identifier"; - }, + token : keywordMapper, // TODO: Unicode escape sequences // TODO: Unicode identifiers regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" @@ -93,7 +79,7 @@ var CSharpHighlightRules = function() { } ] }; - + this.embedRules(DocCommentHighlightRules, "doc-", [ DocCommentHighlightRules.getEndRule("start") ]); }; diff --git a/lib/ace/mode/css_highlight_rules.js b/lib/ace/mode/css_highlight_rules.js index 8ac88e74..59324780 100644 --- a/lib/ace/mode/css_highlight_rules.js +++ b/lib/ace/mode/css_highlight_rules.js @@ -43,37 +43,21 @@ var lang = require("../lib/lang"); var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var CssHighlightRules = function() { + var keywordMapper = this.createKeywordMapper({ + "support.type": "animation-fill-mode|alignment-adjust|alignment-baseline|animation-delay|animation-direction|animation-duration|animation-iteration-count|animation-name|animation-play-state|animation-timing-function|animation|appearance|azimuth|backface-visibility|background-attachment|background-break|background-clip|background-color|background-image|background-origin|background-position|background-repeat|background-size|background|baseline-shift|binding|bleed|bookmark-label|bookmark-level|bookmark-state|bookmark-target|border-bottom|border-bottom-color|border-bottom-left-radius|border-bottom-right-radius|border-bottom-style|border-bottom-width|border-collapse|border-color|border-image|border-image-outset|border-image-repeat|border-image-slice|border-image-source|border-image-width|border-left|border-left-color|border-left-style|border-left-width|border-radius|border-right|border-right-color|border-right-style|border-right-width|border-spacing|border-style|border-top|border-top-color|border-top-left-radius|border-top-right-radius|border-top-style|border-top-width|border-width|border|bottom|box-align|box-decoration-break|box-direction|box-flex-group|box-flex|box-lines|box-ordinal-group|box-orient|box-pack|box-shadow|box-sizing|break-after|break-before|break-inside|caption-side|clear|clip|color-profile|color|column-count|column-fill|column-gap|column-rule|column-rule-color|column-rule-style|column-rule-width|column-span|column-width|columns|content|counter-increment|counter-reset|crop|cue-after|cue-before|cue|cursor|direction|display|dominant-baseline|drop-initial-after-adjust|drop-initial-after-align|drop-initial-before-adjust|drop-initial-before-align|drop-initial-size|drop-initial-value|elevation|empty-cells|fit|fit-position|float-offset|float|font-family|font-size|font-size-adjust|font-stretch|font-style|font-variant|font-weight|font|grid-columns|grid-rows|hanging-punctuation|height|hyphenate-after|hyphenate-before|hyphenate-character|hyphenate-lines|hyphenate-resource|hyphens|icon|image-orientation|image-rendering|image-resolution|inline-box-align|left|letter-spacing|line-height|line-stacking-ruby|line-stacking-shift|line-stacking-strategy|line-stacking|list-style-image|list-style-position|list-style-type|list-style|margin-bottom|margin-left|margin-right|margin-top|margin|mark-after|mark-before|mark|marks|marquee-direction|marquee-play-count|marquee-speed|marquee-style|max-height|max-width|min-height|min-width|move-to|nav-down|nav-index|nav-left|nav-right|nav-up|opacity|orphans|outline-color|outline-offset|outline-style|outline-width|outline|overflow-style|overflow-x|overflow-y|overflow|padding-bottom|padding-left|padding-right|padding-top|padding|page-break-after|page-break-before|page-break-inside|page-policy|page|pause-after|pause-before|pause|perspective-origin|perspective|phonemes|pitch-range|pitch|play-during|position|presentation-level|punctuation-trim|quotes|rendering-intent|resize|rest-after|rest-before|rest|richness|right|rotation-point|rotation|ruby-align|ruby-overhang|ruby-position|ruby-span|size|speak-header|speak-numeral|speak-punctuation|speak|speech-rate|stress|string-set|table-layout|target-name|target-new|target-position|target|text-align-last|text-align|text-decoration|text-emphasis|text-height|text-indent|text-justify|text-outline|text-shadow|text-transform|text-wrap|top|transform-origin|transform-style|transform|transition-delay|transition-duration|transition-property|transition-timing-function|transition|unicode-bidi|vertical-align|visibility|voice-balance|voice-duration|voice-family|voice-pitch-range|voice-pitch|voice-rate|voice-stress|voice-volume|volume|white-space-collapse|white-space|widows|width|word-break|word-spacing|word-wrap|z-index", + "support.function": "rgb|rgba|url|attr|counter|counters", + "support.constant": "absolute|after-edge|after|all-scroll|all|alphabetic|always|antialiased|armenian|auto|avoid-column|avoid-page|avoid|balance|baseline|before-edge|before|below|bidi-override|block-line-height|block|bold|bolder|border-box|both|bottom|box|break-all|break-word|capitalize|caps-height|caption|center|central|char|circle|cjk-ideographic|clone|close-quote|col-resize|collapse|column|consider-shifts|contain|content-box|cover|crosshair|cubic-bezier|dashed|decimal-leading-zero|decimal|default|disabled|disc|disregard-shifts|distribute-all-lines|distribute-letter|distribute-space|distribute|dotted|double|e-resize|ease-in|ease-in-out|ease-out|ease|ellipsis|end|exclude-ruby|fill|fixed|georgian|glyphs|grid-height|groove|hand|hanging|hebrew|help|hidden|hiragana-iroha|hiragana|horizontal|icon|ideograph-alpha|ideograph-numeric|ideograph-parenthesis|ideograph-space|ideographic|inactive|include-ruby|inherit|initial|inline-block|inline-box|inline-line-height|inline-table|inline|inset|inside|inter-ideograph|inter-word|invert|italic|justify|katakana-iroha|katakana|keep-all|last|left|lighter|line-edge|line-through|line|linear|list-item|local|loose|lower-alpha|lower-greek|lower-latin|lower-roman|lowercase|lr-tb|ltr|mathematical|max-height|max-size|medium|menu|message-box|middle|move|n-resize|ne-resize|newspaper|no-change|no-close-quote|no-drop|no-open-quote|no-repeat|none|normal|not-allowed|nowrap|nw-resize|oblique|open-quote|outset|outside|overline|padding-box|page|pointer|pre-line|pre-wrap|pre|preserve-3d|progress|relative|repeat-x|repeat-y|repeat|replaced|reset-size|ridge|right|round|row-resize|rtl|s-resize|scroll|se-resize|separate|slice|small-caps|small-caption|solid|space|square|start|static|status-bar|step-end|step-start|steps|stretch|strict|sub|super|sw-resize|table-caption|table-cell|table-column-group|table-column|table-footer-group|table-header-group|table-row-group|table-row|table|tb-rl|text-after-edge|text-before-edge|text-bottom|text-size|text-top|text|thick|thin|transparent|underline|upper-alpha|upper-latin|upper-roman|uppercase|use-script|vertical-ideographic|vertical-text|visible|w-resize|wait|whitespace|z-index|zero", + "support.constant.color": "aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow", + "support.constant.fonts": "arial|century|comic|courier|garamond|georgia|helvetica|impact|lucida|symbol|system|tahoma|times|trebuchet|utopia|verdana|webdings|sans-serif|serif|monospace" + }, "text", true); - var properties = lang.arrayToMap( - ("animation-fill-mode|alignment-adjust|alignment-baseline|animation-delay|animation-direction|animation-duration|animation-iteration-count|animation-name|animation-play-state|animation-timing-function|animation|appearance|azimuth|backface-visibility|background-attachment|background-break|background-clip|background-color|background-image|background-origin|background-position|background-repeat|background-size|background|baseline-shift|binding|bleed|bookmark-label|bookmark-level|bookmark-state|bookmark-target|border-bottom|border-bottom-color|border-bottom-left-radius|border-bottom-right-radius|border-bottom-style|border-bottom-width|border-collapse|border-color|border-image|border-image-outset|border-image-repeat|border-image-slice|border-image-source|border-image-width|border-left|border-left-color|border-left-style|border-left-width|border-radius|border-right|border-right-color|border-right-style|border-right-width|border-spacing|border-style|border-top|border-top-color|border-top-left-radius|border-top-right-radius|border-top-style|border-top-width|border-width|border|bottom|box-align|box-decoration-break|box-direction|box-flex-group|box-flex|box-lines|box-ordinal-group|box-orient|box-pack|box-shadow|box-sizing|break-after|break-before|break-inside|caption-side|clear|clip|color-profile|color|column-count|column-fill|column-gap|column-rule|column-rule-color|column-rule-style|column-rule-width|column-span|column-width|columns|content|counter-increment|counter-reset|crop|cue-after|cue-before|cue|cursor|direction|display|dominant-baseline|drop-initial-after-adjust|drop-initial-after-align|drop-initial-before-adjust|drop-initial-before-align|drop-initial-size|drop-initial-value|elevation|empty-cells|fit|fit-position|float-offset|float|font-family|font-size|font-size-adjust|font-stretch|font-style|font-variant|font-weight|font|grid-columns|grid-rows|hanging-punctuation|height|hyphenate-after|hyphenate-before|hyphenate-character|hyphenate-lines|hyphenate-resource|hyphens|icon|image-orientation|image-rendering|image-resolution|inline-box-align|left|letter-spacing|line-height|line-stacking-ruby|line-stacking-shift|line-stacking-strategy|line-stacking|list-style-image|list-style-position|list-style-type|list-style|margin-bottom|margin-left|margin-right|margin-top|margin|mark-after|mark-before|mark|marks|marquee-direction|marquee-play-count|marquee-speed|marquee-style|max-height|max-width|min-height|min-width|move-to|nav-down|nav-index|nav-left|nav-right|nav-up|opacity|orphans|outline-color|outline-offset|outline-style|outline-width|outline|overflow-style|overflow-x|overflow-y|overflow|padding-bottom|padding-left|padding-right|padding-top|padding|page-break-after|page-break-before|page-break-inside|page-policy|page|pause-after|pause-before|pause|perspective-origin|perspective|phonemes|pitch-range|pitch|play-during|position|presentation-level|punctuation-trim|quotes|rendering-intent|resize|rest-after|rest-before|rest|richness|right|rotation-point|rotation|ruby-align|ruby-overhang|ruby-position|ruby-span|size|speak-header|speak-numeral|speak-punctuation|speak|speech-rate|stress|string-set|table-layout|target-name|target-new|target-position|target|text-align-last|text-align|text-decoration|text-emphasis|text-height|text-indent|text-justify|text-outline|text-shadow|text-transform|text-wrap|top|transform-origin|transform-style|transform|transition-delay|transition-duration|transition-property|transition-timing-function|transition|unicode-bidi|vertical-align|visibility|voice-balance|voice-duration|voice-family|voice-pitch-range|voice-pitch|voice-rate|voice-stress|voice-volume|volume|white-space-collapse|white-space|widows|width|word-break|word-spacing|word-wrap|z-index").split("|") - ); - - var functions = lang.arrayToMap( - ("rgb|rgba|url|attr|counter|counters").split("|") - ); - - var constants = lang.arrayToMap( - ("absolute|after-edge|after|all-scroll|all|alphabetic|always|antialiased|armenian|auto|avoid-column|avoid-page|avoid|balance|baseline|before-edge|before|below|bidi-override|block-line-height|block|bold|bolder|border-box|both|bottom|box|break-all|break-word|capitalize|caps-height|caption|center|central|char|circle|cjk-ideographic|clone|close-quote|col-resize|collapse|column|consider-shifts|contain|content-box|cover|crosshair|cubic-bezier|dashed|decimal-leading-zero|decimal|default|disabled|disc|disregard-shifts|distribute-all-lines|distribute-letter|distribute-space|distribute|dotted|double|e-resize|ease-in|ease-in-out|ease-out|ease|ellipsis|end|exclude-ruby|fill|fixed|font-size|font|georgian|glyphs|grid-height|groove|hand|hanging|hebrew|help|hidden|hiragana-iroha|hiragana|horizontal|icon|ideograph-alpha|ideograph-numeric|ideograph-parenthesis|ideograph-space|ideographic|inactive|include-ruby|inherit|initial|inline-block|inline-box|inline-line-height|inline-table|inline|inset|inside|inter-ideograph|inter-word|invert|italic|justify|katakana-iroha|katakana|keep-all|last|left|lighter|line-edge|line-through|line|linear|list-item|local|loose|lower-alpha|lower-greek|lower-latin|lower-roman|lowercase|lr-tb|ltr|mathematical|max-height|max-size|medium|menu|message-box|middle|move|n-resize|ne-resize|newspaper|no-change|no-close-quote|no-drop|no-open-quote|no-repeat|none|normal|not-allowed|nowrap|nw-resize|oblique|open-quote|outset|outside|overline|padding-box|page|pointer|pre-line|pre-wrap|pre|preserve-3d|progress|relative|repeat-x|repeat-y|repeat|replaced|reset-size|ridge|right|round|row-resize|rtl|s-resize|scroll|se-resize|separate|slice|small-caps|small-caption|solid|space|square|start|static|status-bar|step-end|step-start|steps|stretch|strict|sub|super|sw-resize|table-caption|table-cell|table-column-group|table-column|table-footer-group|table-header-group|table-row-group|table-row|table|tb-rl|text-after-edge|text-before-edge|text-bottom|text-size|text-top|text|thick|thin|top|transparent|underline|upper-alpha|upper-latin|upper-roman|uppercase|use-script|vertical-ideographic|vertical-text|visible|w-resize|wait|whitespace|z-index|zero").split("|") - ); - - var colors = lang.arrayToMap( - ("aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|" + - "purple|red|silver|teal|white|yellow").split("|") - ); - - var fonts = lang.arrayToMap( - ("arial|century|comic|courier|garamond|georgia|helvetica|impact|lucida|" + - "symbol|system|tahoma|times|trebuchet|utopia|verdana|webdings|sans-serif|" + - "serif|monospace").split("|") - ); - // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used var numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))"; var pseudoElements = "(\\:+)\\b(after|before|first-letter|first-line|moz-selection|selection)\\b"; var pseudoClasses = "(:)\\b(active|checked|disabled|empty|enabled|first-child|first-of-type|focus|hover|indeterminate|invalid|last-child|last-of-type|link|not|nth-child|nth-last-child|nth-last-of-type|nth-of-type|only-child|only-of-type|required|root|target|valid|visited)\\b"; - + var base_ruleset = [ { token : "comment", // multi line comment @@ -99,34 +83,15 @@ var CssHighlightRules = function() { token : "constant.numeric", // hex3 color regex : "#[a-f0-9]{3}" }, { - token : ["punctuation", "entity.other.attribute-name.pseudo-element.css"], + token : ["punctuation", "entity.other.attribute-name.pseudo-element.css"], regex : pseudoElements }, { - token : ["punctuation", "entity.other.attribute-name.pseudo-class.css"], + token : ["punctuation", "entity.other.attribute-name.pseudo-class.css"], regex : pseudoClasses }, { - token : function(value) { - if (properties.hasOwnProperty(value.toLowerCase())) { - return "support.type"; - } - else if (functions.hasOwnProperty(value.toLowerCase())) { - return "support.function"; - } - else if (constants.hasOwnProperty(value.toLowerCase())) { - return "support.constant"; - } - else if (colors.hasOwnProperty(value.toLowerCase())) { - return "support.constant.color"; - } - else if (fonts.hasOwnProperty(value.toLowerCase())) { - return "support.constant.fonts"; - } - else { - return "text"; - } - }, + token : keywordMapper, regex : "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*" - } + } ]; var ruleset = lang.copyArray(base_ruleset); diff --git a/lib/ace/mode/glsl_highlight_rules.js b/lib/ace/mode/glsl_highlight_rules.js index ec83ae02..b192b2df 100644 --- a/lib/ace/mode/glsl_highlight_rules.js +++ b/lib/ace/mode/glsl_highlight_rules.js @@ -39,21 +39,20 @@ define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); -var lang = require("../lib/lang"); var c_cppHighlightRules = require("./c_cpp_highlight_rules").c_cppHighlightRules; var glslHighlightRules = function() { - var keywords = lang.arrayToMap( - ("attribute|const|uniform|varying|break|continue|do|for|while|" + + var keywords = ( + "attribute|const|uniform|varying|break|continue|do|for|while|" + "if|else|in|out|inout|float|int|void|bool|true|false|" + "lowp|mediump|highp|precision|invariant|discard|return|mat2|mat3|" + "mat4|vec2|vec3|vec4|ivec2|ivec3|ivec4|bvec2|bvec3|bvec4|sampler2D|" + - "samplerCube|struct").split("|") + "samplerCube|struct" ); - var buildinConstants = lang.arrayToMap( - ("radians|degrees|sin|cos|tan|asin|acos|atan|pow|" + + var buildinConstants = ( + "radians|degrees|sin|cos|tan|asin|acos|atan|pow|" + "exp|log|exp2|log2|sqrt|inversesqrt|abs|sign|floor|ceil|fract|mod|" + "min|max|clamp|mix|step|smoothstep|length|distance|dot|cross|" + "normalize|faceforward|reflect|refract|matrixCompMult|lessThan|" + @@ -67,22 +66,19 @@ var glslHighlightRules = function() { // The following two are only for MIME x-shader/x-vertex. "gl_Position|gl_PointSize|" + // The following five are only for MIME x-shader/x-fragment. - "gl_FragCoord|gl_FrontFacing|gl_PointCoord|gl_FragColor|gl_FragData").split("|") + "gl_FragCoord|gl_FrontFacing|gl_PointCoord|gl_FragColor|gl_FragData" ); + var keywordMapper = this.createKeywordMapper({ + "variable.language": "this", + "keyword": keywords, + "constant.language": buildinConstants + }, "identifier"); + this.$rules = new c_cppHighlightRules().$rules; this.$rules.start.forEach(function(rule) { - if (typeof rule.token == "function") - rule.token = function(value) { - if (value == "this") - return "variable.language"; - else if (keywords.hasOwnProperty(value)) - return "keyword"; - else if (buildinConstants.hasOwnProperty(value)) - return "constant.language"; - else - return "identifier"; - }; + if (typeof rule.token == "function") + rule.token = keywordMapper; }) }; diff --git a/lib/ace/mode/golang_highlight_rules.js b/lib/ace/mode/golang_highlight_rules.js index 4b450055..ad0a85b0 100644 --- a/lib/ace/mode/golang_highlight_rules.js +++ b/lib/ace/mode/golang_highlight_rules.js @@ -1,20 +1,22 @@ define(function(require, exports, module) { var oop = require("../lib/oop"); - var lang = require("../lib/lang"); var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules; var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var GolangHighlightRules = function() { - var keywords = lang.arrayToMap( - ("true|else|false|break|case|return|goto|if|const|" + - "continue|struct|default|switch|for|" + - "func|import|package|chan|defer|fallthrough|go|interface|map|range" + - "select|type|var").split("|") + var keywords = ( + "true|else|false|break|case|return|goto|if|const|" + + "continue|struct|default|switch|for|" + + "func|import|package|chan|defer|fallthrough|go|interface|map|range" + + "select|type|var" ); + var buildinConstants = ("nil|true|false|iota"); - var buildinConstants = lang.arrayToMap( - ("nil|true|false|iota").split("|") - ); + var keywordMapper = this.createKeywordMapper({ + "variable.language": "this", + "keyword": keywords, + "constant.language": buildinConstants + }, "identifier"); this.$rules = { "start" : [ @@ -57,16 +59,7 @@ define(function(require, exports, module) { token : "keyword", // pre-compiler directivs regex : "(?:#include|#pragma|#line|#define|#undef|#ifdef|#else|#elif|#endif|#ifndef)" }, { - token : function(value) { - if (value == "this") - return "variable.language"; - else if (keywords.hasOwnProperty(value)) - return "keyword"; - else if (buildinConstants.hasOwnProperty(value)) - return "constant.language"; - else - return "identifier"; - }, + token : keywordMapper, regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" }, { token : "keyword.operator", @@ -119,9 +112,9 @@ define(function(require, exports, module) { } ] }; - - this.embedRules(DocCommentHighlightRules, "doc-", - [ DocCommentHighlightRules.getEndRule("start") ]); + + this.embedRules(DocCommentHighlightRules, "doc-", + [ DocCommentHighlightRules.getEndRule("start") ]); } oop.inherits(GolangHighlightRules, TextHighlightRules); diff --git a/lib/ace/mode/groovy_highlight_rules.js b/lib/ace/mode/groovy_highlight_rules.js index 6a151eca..b9f4033a 100644 --- a/lib/ace/mode/groovy_highlight_rules.js +++ b/lib/ace/mode/groovy_highlight_rules.js @@ -2,31 +2,30 @@ define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); -var lang = require("../lib/lang"); var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules; var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var GroovyHighlightRules = function() { - var keywords = lang.arrayToMap( - ("assert|with|abstract|continue|for|new|switch|" + - "assert|default|goto|package|synchronized|" + - "boolean|do|if|private|this|" + - "break|double|implements|protected|throw|" + - "byte|else|import|public|throws|" + - "case|enum|instanceof|return|transient|" + - "catch|extends|int|short|try|" + - "char|final|interface|static|void|" + - "class|finally|long|strictfp|volatile|" + - "def|float|native|super|while").split("|") + var keywords = ( + "assert|with|abstract|continue|for|new|switch|" + + "assert|default|goto|package|synchronized|" + + "boolean|do|if|private|this|" + + "break|double|implements|protected|throw|" + + "byte|else|import|public|throws|" + + "case|enum|instanceof|return|transient|" + + "catch|extends|int|short|try|" + + "char|final|interface|static|void|" + + "class|finally|long|strictfp|volatile|" + + "def|float|native|super|while" ); - var buildinConstants = lang.arrayToMap( - ("null|Infinity|NaN|undefined").split("|") + var buildinConstants = ( + "null|Infinity|NaN|undefined" ); - var langClasses = lang.arrayToMap( - ("AbstractMethodError|AssertionError|ClassCircularityError|"+ + var langClasses = ( + "AbstractMethodError|AssertionError|ClassCircularityError|"+ "ClassFormatError|Deprecated|EnumConstantNotPresentException|"+ "ExceptionInInitializerError|IllegalAccessError|"+ "IllegalThreadStateException|InstantiationError|InternalError|"+ @@ -49,12 +48,18 @@ var GroovyHighlightRules = function() { "ArrayStoreException|ClassCastException|LinkageError|"+ "NoClassDefFoundError|ClassNotFoundException|RuntimeException|"+ "Exception|ThreadDeath|Error|Throwable|System|ClassLoader|"+ - "Cloneable|Class|CharSequence|Comparable|String|Object").split("|") - ); - - var importClasses = lang.arrayToMap( - ("").split("|") + "Cloneable|Class|CharSequence|Comparable|String|Object" ); + + // TODO var importClasses = ""; + + var keywordMapper = this.createKeywordMapper({ + "variable.language": "this", + "keyword": keywords, + "support.function": langClasses, + "constant.language": buildinConstants + }, "identifier"); + // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -97,20 +102,7 @@ var GroovyHighlightRules = function() { token : "constant.language.boolean", regex : "(?:true|false)\\b" }, { - token : function(value) { - if (value == "this") - return "variable.language"; - else if (keywords.hasOwnProperty(value)) - return "keyword"; - else if (langClasses.hasOwnProperty(value)) - return "support.function"; - else if (importClasses.hasOwnProperty(value)) - return "support.function"; - else if (buildinConstants.hasOwnProperty(value)) - return "constant.language"; - else - return "identifier"; - }, + token : keywordMapper, // TODO: Unicode escape sequences // TODO: Unicode identifiers regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" @@ -172,7 +164,7 @@ var GroovyHighlightRules = function() { } ] }; - + this.embedRules(DocCommentHighlightRules, "doc-", [ DocCommentHighlightRules.getEndRule("start") ]); }; diff --git a/lib/ace/mode/haxe_highlight_rules.js b/lib/ace/mode/haxe_highlight_rules.js index 5b17c650..4e7f18b1 100644 --- a/lib/ace/mode/haxe_highlight_rules.js +++ b/lib/ace/mode/haxe_highlight_rules.js @@ -2,20 +2,25 @@ define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); -var lang = require("../lib/lang"); + var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules; var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var HaxeHighlightRules = function() { - var keywords = lang.arrayToMap( - ("break|case|cast|catch|class|continue|default|else|enum|extends|for|function|if|implements|import|in|inline|interface|new|override|package|private|public|return|static|super|switch|this|throw|trace|try|typedef|untyped|var|while|Array|Void|Bool|Int|UInt|Float|Dynamic|String|List|Hash|IntHash|Error|Unknown|Type|Std").split("|") + var keywords = ( + "break|case|cast|catch|class|continue|default|else|enum|extends|for|function|if|implements|import|in|inline|interface|new|override|package|private|public|return|static|super|switch|this|throw|trace|try|typedef|untyped|var|while|Array|Void|Bool|Int|UInt|Float|Dynamic|String|List|Hash|IntHash|Error|Unknown|Type|Std" ); - var buildinConstants = lang.arrayToMap( - ("null|true|false").split("|") + var buildinConstants = ( + "null|true|false" ); + var keywordMapper = this.createKeywordMapper({ + "variable.language": "this", + "keyword": keywords, + "constant.language": buildinConstants + }, "identifier"); // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -51,16 +56,7 @@ var HaxeHighlightRules = function() { token : "constant.language.boolean", regex : "(?:true|false)\\b" }, { - token : function(value) { - if (value == "this") - return "variable.language"; - else if (keywords.hasOwnProperty(value)) - return "keyword"; - else if (buildinConstants.hasOwnProperty(value)) - return "constant.language"; - else - return "identifier"; - }, + token : keywordMapper, // TODO: Unicode escape sequences // TODO: Unicode identifiers regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" diff --git a/lib/ace/mode/java_highlight_rules.js b/lib/ace/mode/java_highlight_rules.js index 77efd672..a37f9586 100644 --- a/lib/ace/mode/java_highlight_rules.js +++ b/lib/ace/mode/java_highlight_rules.js @@ -2,15 +2,14 @@ define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); -var lang = require("../lib/lang"); var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules; var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var JavaHighlightRules = function() { // taken from http://download.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html - var keywords = lang.arrayToMap( - ("abstract|continue|for|new|switch|" + + var keywords = ( + "abstract|continue|for|new|switch|" + "assert|default|goto|package|synchronized|" + "boolean|do|if|private|this|" + "break|double|implements|protected|throw|" + @@ -19,15 +18,14 @@ var JavaHighlightRules = function() { "catch|extends|int|short|try|" + "char|final|interface|static|void|" + "class|finally|long|strictfp|volatile|" + - "const|float|native|super|while").split("|") + "const|float|native|super|while" ); - var buildinConstants = lang.arrayToMap( - ("null|Infinity|NaN|undefined").split("|") - ); + var buildinConstants = ("null|Infinity|NaN|undefined"); - var langClasses = lang.arrayToMap( - ("AbstractMethodError|AssertionError|ClassCircularityError|"+ + + var langClasses = ( + "AbstractMethodError|AssertionError|ClassCircularityError|"+ "ClassFormatError|Deprecated|EnumConstantNotPresentException|"+ "ExceptionInInitializerError|IllegalAccessError|"+ "IllegalThreadStateException|InstantiationError|InternalError|"+ @@ -50,12 +48,17 @@ var JavaHighlightRules = function() { "ArrayStoreException|ClassCastException|LinkageError|"+ "NoClassDefFoundError|ClassNotFoundException|RuntimeException|"+ "Exception|ThreadDeath|Error|Throwable|System|ClassLoader|"+ - "Cloneable|Class|CharSequence|Comparable|String|Object").split("|") - ); - - var importClasses = lang.arrayToMap( - ("").split("|") + "Cloneable|Class|CharSequence|Comparable|String|Object" ); + + var keywordMapper = this.createKeywordMapper({ + "variable.language": "this", + "keyword": keywords, + "constant.language": buildinConstants, + "support.function": langClasses, + + }, "identifier"); + // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -90,20 +93,7 @@ var JavaHighlightRules = function() { token : "constant.language.boolean", regex : "(?:true|false)\\b" }, { - token : function(value) { - if (value == "this") - return "variable.language"; - else if (keywords.hasOwnProperty(value)) - return "keyword"; - else if (langClasses.hasOwnProperty(value)) - return "support.function"; - else if (importClasses.hasOwnProperty(value)) - return "support.function"; - else if (buildinConstants.hasOwnProperty(value)) - return "constant.language"; - else - return "identifier"; - }, + token : keywordMapper, // TODO: Unicode escape sequences // TODO: Unicode identifiers regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" @@ -133,7 +123,7 @@ var JavaHighlightRules = function() { } ] }; - + this.embedRules(DocCommentHighlightRules, "doc-", [ DocCommentHighlightRules.getEndRule("start") ]); }; diff --git a/lib/ace/mode/liquid_highlight_rules.js b/lib/ace/mode/liquid_highlight_rules.js index cb8fcb35..26f3649a 100644 --- a/lib/ace/mode/liquid_highlight_rules.js +++ b/lib/ace/mode/liquid_highlight_rules.js @@ -41,157 +41,149 @@ define(function(require, exports, module) { var oop = require("../lib/oop"); var CssHighlightRules = require("./css_highlight_rules").CssHighlightRules; var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules; -var lang = require("../lib/lang"); var xmlUtil = require("./xml_util"); var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var LiquidHighlightRules = function() { // see: https://developer.mozilla.org/en/Liquid/Reference/Global_Objects - var functions = lang.arrayToMap( + var functions = ( // Standard Filters - ("date|capitalize|downcase|upcase|first|last|join|sort|map|size|escape|" + + "date|capitalize|downcase|upcase|first|last|join|sort|map|size|escape|" + "escape_once|strip_html|strip_newlines|newline_to_br|replace|replace_first|" + "truncate|truncatewords|prepend|append|minus|plus|times|divided_by|split" - ).split("|") ); - var keywords = lang.arrayToMap( + var keywords = ( // Standard Tags - ("capture|endcapture|case|endcase|when|comment|endcomment|" + + "capture|endcapture|case|endcase|when|comment|endcomment|" + "cycle|for|endfor|in|reversed|if|endif|else|elsif|include|endinclude|unless|endunless|" + - // Commonly used tags - "style|text|image|widget|plugin|marker|endmarker|tablerow|endtablerow").split("|") + // Commonly used tags + "style|text|image|widget|plugin|marker|endmarker|tablerow|endtablerow" ); - var builtinVariables = lang.arrayToMap( - ['forloop'] - // ("forloop\\.(length|index|index0|rindex|rindex0|first|last)|limit|offset|range" + + var builtinVariables = 'forloop|tablerowloop'; + // "forloop\\.(length|index|index0|rindex|rindex0|first|last)|limit|offset|range" + // "tablerowloop\\.(length|index|index0|rindex|rindex0|first|last|col|col0|"+ - // "col_first|col_last)").split("|") - ); + // "col_first|col_last)" - var definitions = lang.arrayToMap(("assign").split("|")); + var definitions = ("assign"); + + var keywordMapper = this.createKeywordMapper({ + "variable.language": builtinVariables, + "keyword": keywords, + "support.function": functions, + "keyword.definition": definitions + }, "identifier"); // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used this.$rules = { - start : [{ - token : "variable", - regex : "{%", - next : "liquid_start" - }, { - token : "variable", - regex : "{{", - next : "liquid_start" - }, { - token : "meta.tag", - merge : true, - regex : "<\\!\\[CDATA\\[", - next : "cdata" - }, { - token : "xml_pe", - regex : "<\\?.*?\\?>" - }, { - token : "comment", - merge : true, - regex : "<\\!--", - next : "comment" - }, { - token : "meta.tag", - regex : "<(?=\\s*script\\b)", - next : "script" - }, { - token : "meta.tag", - regex : "<(?=\\s*style\\b)", - next : "style" - }, { - token : "meta.tag", // opening tag - regex : "<\\/?", - next : "tag" - }, { - token : "text", - regex : "\\s+" - }, { - token : "text", - regex : "[^<]+" - } ], + start : [{ + token : "variable", + regex : "{%", + next : "liquid_start" + }, { + token : "variable", + regex : "{{", + next : "liquid_start" + }, { + token : "meta.tag", + merge : true, + regex : "<\\!\\[CDATA\\[", + next : "cdata" + }, { + token : "xml_pe", + regex : "<\\?.*?\\?>" + }, { + token : "comment", + merge : true, + regex : "<\\!--", + next : "comment" + }, { + token : "meta.tag", + regex : "<(?=\\s*script\\b)", + next : "script" + }, { + token : "meta.tag", + regex : "<(?=\\s*style\\b)", + next : "style" + }, { + token : "meta.tag", // opening tag + regex : "<\\/?", + next : "tag" + }, { + token : "text", + regex : "\\s+" + }, { + token : "text", + regex : "[^<]+" + } ], - cdata : [ { - token : "text", - regex : "\\]\\]>", - next : "start" - }, { - token : "text", - merge : true, - regex : "\\s+" - }, { - token : "text", - merge : true, - regex : ".+" - } ], + cdata : [ { + token : "text", + regex : "\\]\\]>", + next : "start" + }, { + token : "text", + merge : true, + regex : "\\s+" + }, { + token : "text", + merge : true, + regex : ".+" + } ], - comment : [ { - token : "comment", - regex : ".*?-->", - next : "start" - }, { - token : "comment", - merge : true, - regex : ".+" - } ] , + comment : [ { + token : "comment", + regex : ".*?-->", + next : "start" + }, { + token : "comment", + merge : true, + regex : ".+" + } ] , - liquid_start : [{ - token: "variable", - regex: "}}", - next: "start" - }, { - token: "variable", - regex: "%}", - next: "start" - }, { - token : "string", // single line - regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]' - }, { - token : "string", // single line - regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']" - }, { - token : "constant.numeric", // hex - regex : "0[xX][0-9a-fA-F]+\\b" - }, { - token : "constant.numeric", // float - regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" - }, { - token : "constant.language.boolean", - regex : "(?:true|false)\\b" - }, { - token : function(value) { - if (functions.hasOwnProperty(value)) - return "support.function"; - else if (keywords.hasOwnProperty(value)) - return "keyword"; - else if (builtinVariables.hasOwnProperty(value)) - return "variable.language"; - else if (definitions.hasOwnProperty(value)) - return "keyword.definition"; - else - return "identifier"; - }, - regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" - }, { - token : "keyword.operator", - regex : "\/|\\*|\\-|\\+|=|!=|\\?\\:" - }, { - token : "paren.lparen", - regex : /[\[\({]/ - }, { - token : "paren.rparen", - regex : /[\])}]/ - }, { - token : "text", - regex : "\\s+" - }] + liquid_start : [{ + token: "variable", + regex: "}}", + next: "start" + }, { + token: "variable", + regex: "%}", + next: "start" + }, { + token : "string", // single line + regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]' + }, { + token : "string", // single line + regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']" + }, { + token : "constant.numeric", // hex + regex : "0[xX][0-9a-fA-F]+\\b" + }, { + token : "constant.numeric", // float + regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" + }, { + token : "constant.language.boolean", + regex : "(?:true|false)\\b" + }, { + token : keywordMapper, + regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" + }, { + token : "keyword.operator", + regex : "\/|\\*|\\-|\\+|=|!=|\\?\\:" + }, { + token : "paren.lparen", + regex : /[\[\({]/ + }, { + token : "paren.rparen", + regex : /[\])}]/ + }, { + token : "text", + regex : "\\s+" + }] }; xmlUtil.tag(this.$rules, "tag", "start"); diff --git a/lib/ace/mode/lua_highlight_rules.js b/lib/ace/mode/lua_highlight_rules.js index 57e5fead..35dcc2d1 100644 --- a/lib/ace/mode/lua_highlight_rules.js +++ b/lib/ace/mode/lua_highlight_rules.js @@ -41,22 +41,20 @@ define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); -var lang = require("../lib/lang"); var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var LuaHighlightRules = function() { - var keywords = lang.arrayToMap( - ("break|do|else|elseif|end|for|function|if|in|local|repeat|"+ - "return|then|until|while|or|and|not").split("|") + var keywords = ( + "break|do|else|elseif|end|for|function|if|in|local|repeat|"+ + "return|then|until|while|or|and|not" ); - var builtinConstants = lang.arrayToMap( - ("true|false|nil|_G|_VERSION").split("|") - ); + var builtinConstants = ("true|false|nil|_G|_VERSION"); - var builtinFunctions = lang.arrayToMap( - ("string|xpcall|package|tostring|print|os|unpack|require|"+ + var functions = ( + // builtinFunctions + "string|xpcall|package|tostring|print|os|unpack|require|"+ "getfenv|setmetatable|next|assert|tonumber|io|rawequal|"+ "collectgarbage|getmetatable|module|rawset|math|debug|"+ "pcall|table|newproxy|type|coroutine|_G|select|gcinfo|"+ @@ -75,25 +73,27 @@ var LuaHighlightRules = function() { "gethook|setmetatable|setlocal|traceback|setfenv|getinfo|"+ "setupvalue|getlocal|getregistry|getfenv|setn|insert|getn|"+ "foreachi|maxn|foreach|concat|sort|remove|resume|yield|"+ - "status|wrap|create|running").split("|") - ); - - var stdLibaries = lang.arrayToMap( - ("string|package|os|io|math|debug|table|coroutine").split("|") - ); - - var metatableMethods = lang.arrayToMap( - ("__add|__sub|__mod|__unm|__concat|__lt|__index|__call|__gc|__metatable|"+ - "__mul|__div|__pow|__len|__eq|__le|__newindex|__tostring|__mode|__tonumber").split("|") + "status|wrap|create|running|"+ + // metatableMethods + "__add|__sub|__mod|__unm|__concat|__lt|__index|__call|__gc|__metatable|"+ + "__mul|__div|__pow|__len|__eq|__le|__newindex|__tostring|__mode|__tonumber" ); - var futureReserved = lang.arrayToMap( - ("").split("|") - ); - - var deprecatedIn5152 = lang.arrayToMap( - ("setn|foreach|foreachi|gcinfo|log10|maxn").split("|") - ); + var stdLibaries = ("string|package|os|io|math|debug|table|coroutine"); + + var futureReserved = ""; + + var deprecatedIn5152 = ("setn|foreach|foreachi|gcinfo|log10|maxn"); + + var keywordMapper = this.createKeywordMapper({ + "keyword": keywords, + "support.function": functions, + "invalid.deprecated": deprecatedIn5152, + "constant.library": stdLibaries, + "constant.language": builtinConstants, + "invalid.illegal": futureReserved, + "variable.language": "this" + }, "identifier"); var strPre = ""; @@ -105,13 +105,13 @@ var LuaHighlightRules = function() { var intPart = "(?:\\d+)"; var pointFloat = "(?:(?:" + intPart + "?" + fraction + ")|(?:" + intPart + "\\.))"; var floatNumber = "(?:" + pointFloat + ")"; - - var comment_stack = []; - - this.$rules = { - "start" : - + var comment_stack = []; + + this.$rules = { + "start" : + + // bracketed comments [{ token : "comment", // --[[ comment @@ -132,7 +132,7 @@ var LuaHighlightRules = function() { token : "comment", // --[====+[ comment regex : strPre + '\\-\\-\\[\\={5}\\=*\\[.*\\]\\={5}\\=*\\]' }, - + // multiline bracketed comments { token : "comment", // --[[ comment @@ -169,20 +169,20 @@ var LuaHighlightRules = function() { // you can never be too paranoid ;) if ((match = pattern.exec(value)) != null && (match = match[1]) != undefined) comment_stack.push(match.length); - + return "comment"; }, regex : strPre + '\\-\\-\\[\\={5}\\=*\\[.*$', merge : true, next : "qcomment5" }, - + // single line comments { token : "comment", regex : "\\-\\-.*$" - }, - + }, + // bracketed strings { token : "string", // [[ string @@ -203,7 +203,7 @@ var LuaHighlightRules = function() { token : "string", // [====+[ string regex : strPre + '\\[\\={5}\\=*\\[.*\\]\\={5}\\=*\\]' }, - + // multiline bracketed strings { token : "string", // [[ string @@ -236,14 +236,14 @@ var LuaHighlightRules = function() { var pattern = /\[(\=+)\[/, match; if ((match = pattern.exec(value)) != null && (match = match[1]) != undefined) comment_stack.push(match.length); - + return "string"; }, regex : strPre + '\\[\\={5}\\=*\\[.*$', merge : true, next : "qstring5" - }, - + }, + { token : "string", // " string regex : strPre + '"(?:[^\\\\]|\\\\.)*?"' @@ -257,24 +257,7 @@ var LuaHighlightRules = function() { token : "constant.numeric", // integer regex : integer + "\\b" }, { - token : function(value) { - if (keywords.hasOwnProperty(value)) - return "keyword"; - else if (builtinConstants.hasOwnProperty(value)) - return "constant.language"; - else if (futureReserved.hasOwnProperty(value)) - return "invalid.illegal"; - else if (stdLibaries.hasOwnProperty(value)) - return "constant.library"; - else if (deprecatedIn5152.hasOwnProperty(value)) - return "invalid.deprecated"; - else if (builtinFunctions.hasOwnProperty(value)) - return "support.function"; - else if (metatableMethods.hasOwnProperty(value)) - return "support.function"; - else - return "identifier"; - }, + token : keywordMapper, regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" }, { token : "keyword.operator", @@ -289,7 +272,7 @@ var LuaHighlightRules = function() { token : "text", regex : "\\s+" } ], - + "qcomment": [ { token : "comment", regex : "(?:[^\\\\]|\\\\.)*?\\]\\]", @@ -336,7 +319,7 @@ var LuaHighlightRules = function() { regex : '.+' } ], "qcomment5": [ { - token : function(value){ + token : function(value){ // very hackish, mutates the qcomment5 field on the fly. var pattern = /\](\=+)\]/, rule = this.rules.qcomment5[0], match; rule.next = "start"; @@ -347,7 +330,7 @@ var LuaHighlightRules = function() { rule.next = "qcomment5"; } } - + return "comment"; }, regex : "(?:[^\\\\]|\\\\.)*?\\]\\={5}\\=*\\]", @@ -357,7 +340,7 @@ var LuaHighlightRules = function() { merge : true, regex : '.+' } ], - + "qstring": [ { token : "string", regex : "(?:[^\\\\]|\\\\.)*?\\]\\]", @@ -404,7 +387,7 @@ var LuaHighlightRules = function() { regex : '.+' } ], "qstring5": [ { - token : function(value){ + token : function(value){ // very hackish, mutates the qstring5 field on the fly. var pattern = /\](\=+)\]/, rule = this.rules.qstring5[0], match; rule.next = "start"; @@ -415,7 +398,7 @@ var LuaHighlightRules = function() { rule.next = "qstring5"; } } - + return "string"; }, regex : "(?:[^\\\\]|\\\\.)*?\\]\\={5}\\=*\\]", @@ -425,7 +408,7 @@ var LuaHighlightRules = function() { merge : true, regex : '.+' } ] - + }; } diff --git a/lib/ace/mode/ocaml_highlight_rules.js b/lib/ace/mode/ocaml_highlight_rules.js index dca7b229..96ec9f15 100644 --- a/lib/ace/mode/ocaml_highlight_rules.js +++ b/lib/ace/mode/ocaml_highlight_rules.js @@ -41,24 +41,21 @@ define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); -var lang = require("../lib/lang"); var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var OcamlHighlightRules = function() { - var keywords = lang.arrayToMap(( + var keywords = ( "and|as|assert|begin|class|constraint|do|done|downto|else|end|" + "exception|external|for|fun|function|functor|if|in|include|" + "inherit|initializer|lazy|let|match|method|module|mutable|new|" + "object|of|open|or|private|rec|sig|struct|then|to|try|type|val|" + - "virtual|when|while|with").split("|") + "virtual|when|while|with" ); - var builtinConstants = lang.arrayToMap( - ("true|false").split("|") - ); + var builtinConstants = ("true|false"); - var builtinFunctions = lang.arrayToMap(( + var builtinFunctions = ( "abs|abs_big_int|abs_float|abs_num|abstract_tag|accept|access|acos|add|" + "add_available_units|add_big_int|add_buffer|add_channel|add_char|" + "add_initializer|add_int_big_int|add_interfaces|add_num|add_string|" + @@ -239,7 +236,14 @@ var OcamlHighlightRules = function() { "MoreLabels|Mutex|Nativeint|Num|Obj|Oo|Parsing|Pervasives|Printexc|" + "Printf|Queue|Random|Scanf|Scanning|Set|Sort|Stack|State|StdLabels|Str|" + "Stream|String|StringLabels|Sys|Thread|ThreadUnix|Tk|Unix|UnixLabels|Weak" - ).split("|")); + ); + + var keywordMapper = this.createKeywordMapper({ + "variable.language": "this", + "keyword": keywords, + "constant.language": builtinConstants, + "support.function": builtinFunctions + }, "identifier"); var decimalInteger = "(?:(?:[1-9]\\d*)|(?:0))"; var octInteger = "(?:0[oO]?[0-7]+)"; @@ -293,16 +297,7 @@ var OcamlHighlightRules = function() { regex : integer + "\\b" }, { - token : function(value) { - if (keywords.hasOwnProperty(value)) - return "keyword"; - else if (builtinConstants.hasOwnProperty(value)) - return "constant.language"; - else if (builtinFunctions.hasOwnProperty(value)) - return "support.function"; - else - return "identifier"; - }, + token : keywordMapper, regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" }, { diff --git a/lib/ace/mode/perl_highlight_rules.js b/lib/ace/mode/perl_highlight_rules.js index ed1e45c8..f79629fb 100644 --- a/lib/ace/mode/perl_highlight_rules.js +++ b/lib/ace/mode/perl_highlight_rules.js @@ -39,22 +39,19 @@ define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); -var lang = require("../lib/lang"); var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var PerlHighlightRules = function() { - var keywords = lang.arrayToMap( - ("base|constant|continue|else|elsif|for|foreach|format|goto|if|last|local|my|next|" + - "no|package|parent|redo|require|scalar|sub|unless|until|while|use|vars").split("|") + var keywords = ( + "base|constant|continue|else|elsif|for|foreach|format|goto|if|last|local|my|next|" + + "no|package|parent|redo|require|scalar|sub|unless|until|while|use|vars" ); - var buildinConstants = lang.arrayToMap( - ("ARGV|ENV|INC|SIG").split("|") - ); + var buildinConstants = ("ARGV|ENV|INC|SIG"); - var builtinFunctions = lang.arrayToMap( - ("getprotobynumber|getprotobyname|getservbyname|gethostbyaddr|" + + var builtinFunctions = ( + "getprotobynumber|getprotobyname|getservbyname|gethostbyaddr|" + "gethostbyname|getservbyport|getnetbyaddr|getnetbyname|getsockname|" + "getpeername|setpriority|getprotoent|setprotoent|getpriority|" + "endprotoent|getservent|setservent|endservent|sethostent|socketpair|" + @@ -75,9 +72,15 @@ var PerlHighlightRules = function() { "join|open|tell|pipe|exit|glob|warn|each|bind|sort|pack|eval|push|" + "keys|getc|kill|seek|sqrt|send|wait|rand|tied|read|time|exec|recv|" + "eof|chr|int|ord|exp|pos|pop|sin|log|abs|oct|hex|tie|cos|vec|END|ref|" + - "map|die|uc|lc|do").split("|") + "map|die|uc|lc|do" ); + var keywordMapper = this.createKeywordMapper({ + "keyword": keywords, + "constant.language": buildinConstants, + "support.function": builtinFunctions + }, "identifier"); + // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -112,16 +115,7 @@ var PerlHighlightRules = function() { token : "constant.numeric", // float regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" }, { - token : function(value) { - if (keywords.hasOwnProperty(value)) - return "keyword"; - else if (buildinConstants.hasOwnProperty(value)) - return "constant.language"; - else if (builtinFunctions.hasOwnProperty(value)) - return "support.function"; - else - return "identifier"; - }, + token : keywordMapper, regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" }, { token : "keyword.operator", diff --git a/lib/ace/mode/pgsql_highlight_rules.js b/lib/ace/mode/pgsql_highlight_rules.js index 688e9ac7..866b5ed5 100755 --- a/lib/ace/mode/pgsql_highlight_rules.js +++ b/lib/ace/mode/pgsql_highlight_rules.js @@ -32,10 +32,10 @@ var PerlHighlightRules = require("./perl_highlight_rules").PerlHighlightRules; var PythonHighlightRules = require("./python_highlight_rules").PythonHighlightRules; var PgsqlHighlightRules = function() { - + // Keywords, functions, operators last updated for pg 9.1. - var keywords = lang.arrayToMap( - ("abort|absolute|abstime|access|aclitem|action|add|admin|after|aggregate|all|also|alter|always|" + + var keywords = ( + "abort|absolute|abstime|access|aclitem|action|add|admin|after|aggregate|all|also|alter|always|" + "analyse|analyze|and|any|anyarray|anyelement|anyenum|anynonarray|array|as|asc|assertion|" + "assignment|asymmetric|at|attribute|authorization|backward|before|begin|between|bigint|" + "binary|bit|bool|boolean|both|box|bpchar|by|bytea|cache|called|cascade|cascaded|case|cast|" + @@ -74,12 +74,12 @@ var PgsqlHighlightRules = function() { "unlogged|until|update|user|using|uuid|vacuum|valid|validate|validator|value|values|varbit|" + "varchar|variadic|varying|verbose|version|view|void|volatile|when|where|whitespace|window|" + "with|without|work|wrapper|write|xid|xml|xmlattributes|xmlconcat|xmlelement|xmlexists|" + - "xmlforest|xmlparse|xmlpi|xmlroot|xmlserialize|year|yes|zone").split("|") + "xmlforest|xmlparse|xmlpi|xmlroot|xmlserialize|year|yes|zone" ); - - - var builtinFunctions = lang.arrayToMap( - ("RI_FKey_cascade_del|RI_FKey_cascade_upd|RI_FKey_check_ins|RI_FKey_check_upd|" + + + + var builtinFunctions = ( + "RI_FKey_cascade_del|RI_FKey_cascade_upd|RI_FKey_check_ins|RI_FKey_check_upd|" + "RI_FKey_noaction_del|RI_FKey_noaction_upd|RI_FKey_restrict_del|RI_FKey_restrict_upd|" + "RI_FKey_setdefault_del|RI_FKey_setdefault_upd|RI_FKey_setnull_del|" + "RI_FKey_setnull_upd|abbrev|abs|abstime|abstimeeq|abstimege|abstimegt|abstimein|abstimele|" + @@ -392,9 +392,15 @@ var PgsqlHighlightRules = function() { "win866_to_mic|win866_to_win1251|win_to_utf8|xideq|xideqint4|xidin|xidout|xidrecv|xidsend|" + "xml|xml_in|xml_is_well_formed|xml_is_well_formed_content|xml_is_well_formed_document|" + "xml_out|xml_recv|xml_send|xmlagg|xmlcomment|xmlconcat2|xmlexists|xmlvalidate|xpath|" + - "xpath_exists").split("|") + "xpath_exists" ); - + + var keywordMapper = this.createKeywordMapper({ + "support.function": builtinFunctions, + "keyword": keywords, + }, "identifier", true); + + var sqlRules = [ { token : "string", // single line string -- assume dollar strings if multi-line for now @@ -406,16 +412,7 @@ var PgsqlHighlightRules = function() { token : "constant.numeric", // float regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" }, { - token : function(value) { - value = value.toLowerCase(); - if (keywords.hasOwnProperty(value)) { - return "keyword"; - } else if (builtinFunctions.hasOwnProperty(value)) { - return "support.function"; - } else { - return "identifier"; - } - }, + token : keywordMapper, regex : "[a-zA-Z_][a-zA-Z0-9_$]*\\b" // TODO - Unicode in identifiers }, { token : "keyword.operator", @@ -434,14 +431,14 @@ var PgsqlHighlightRules = function() { regex : "\\s+" } ]; - + this.$rules = { "start" : [ { token : "comment", regex : "--.*$" - }, + }, DocCommentHighlightRules.getStartRule("doc-start"), { token : "comment", // multi-line comment @@ -457,7 +454,7 @@ var PgsqlHighlightRules = function() { regex : "^\\\\[\\S]+.*$" } ], - + "statement" : [ { token : "comment", @@ -489,7 +486,7 @@ var PgsqlHighlightRules = function() { next : "dollarStatementString" } ].concat(sqlRules), - + "dollarSql" : [ { token : "comment", @@ -509,7 +506,7 @@ var PgsqlHighlightRules = function() { next : "dollarSqlString" } ].concat(sqlRules), - + "comment" : [ { token : "comment", // closing comment @@ -521,7 +518,7 @@ var PgsqlHighlightRules = function() { regex : ".+" } ], - + "commentStatement" : [ { token : "comment", // closing comment @@ -533,7 +530,7 @@ var PgsqlHighlightRules = function() { regex : ".+" } ], - + "commentDollarSql" : [ { token : "comment", // closing comment @@ -545,7 +542,7 @@ var PgsqlHighlightRules = function() { regex : ".+" } ], - + "dollarStatementString" : [ { token : "string", // closing dollarstring @@ -557,7 +554,7 @@ var PgsqlHighlightRules = function() { regex : ".+" } ], - + "dollarSqlString" : [ { token : "string", // closing dollarstring @@ -570,7 +567,7 @@ var PgsqlHighlightRules = function() { } ] }; - + this.embedRules(DocCommentHighlightRules, "doc-", [ DocCommentHighlightRules.getEndRule("start") ]); this.embedRules(PerlHighlightRules, "perl-", [{token : "string", regex : "\\$perl\\$", next : "statement"}]); this.embedRules(PythonHighlightRules, "python-", [{token : "string", regex : "\\$python\\$", next : "statement"}]); diff --git a/lib/ace/mode/powershell_highlight_rules.js b/lib/ace/mode/powershell_highlight_rules.js index 68cd0684..29071a3b 100644 --- a/lib/ace/mode/powershell_highlight_rules.js +++ b/lib/ace/mode/powershell_highlight_rules.js @@ -2,18 +2,17 @@ define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); -var lang = require("../lib/lang"); var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var PowershellHighlightRules = function() { - - var keywords = lang.arrayToMap( - ("function|if|else|elseif|switch|while|default|for|do|until|break|continue|" + - "foreach|return|filter|in|trap|throw|param|begin|process|end").split("|") + + var keywords = ( + "function|if|else|elseif|switch|while|default|for|do|until|break|continue|" + + "foreach|return|filter|in|trap|throw|param|begin|process|end" ); - var builtinFunctions = lang.arrayToMap( - ("Get-Alias|Import-Alias|New-Alias|Set-Alias|Get-AuthenticodeSignature|Set-AuthenticodeSignature|" + + var builtinFunctions = ( + "Get-Alias|Import-Alias|New-Alias|Set-Alias|Get-AuthenticodeSignature|Set-AuthenticodeSignature|" + "Set-Location|Get-ChildItem|Clear-Item|Get-Command|Measure-Command|Trace-Command|" + "Add-Computer|Checkpoint-Computer|Remove-Computer|Restart-Computer|Restore-Computer|Stop-Computer|" + "Reset-ComputerMachinePassword|Test-ComputerSecureChannel|Add-Content|Get-Content|Set-Content|Clear-Content|" + @@ -53,12 +52,18 @@ var PowershellHighlightRules = function() { "Write-Output|Write-Progress|Write-Verbose|Write-Warning|Set-WmiInstance|Invoke-WmiMethod|" + "Get-WmiObject|Remove-WmiObject|Connect-WSMan|Disconnect-WSMan|Test-WSMan|Invoke-WSManAction|" + "Disable-WSManCredSSP|Enable-WSManCredSSP|Get-WSManCredSSP|New-WSManInstance|Get-WSManInstance|Set-WSManInstance|" + - "Remove-WSManInstance|Set-WSManQuickConfig|New-WSManSessionOption").split("|")); + "Remove-WSManInstance|Set-WSManQuickConfig|New-WSManSessionOption" + ); + + var keywordMapper = this.createKeywordMapper({ + "support.function": builtinFunctions, + "keyword": keywords + }, "identifier"); var binaryOperatorsRe = "eq|ne|ge|gt|lt|le|like|notlike|match|notmatch|replace|contains|notcontains|" + "ieq|ine|ige|igt|ile|ilt|ilike|inotlike|imatch|inotmatch|ireplace|icontains|inotcontains|" + "is|isnot|as|" + - "and|or|band|bor|not"; + "and|or|band|bor|not"; // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -90,14 +95,7 @@ var PowershellHighlightRules = function() { token : "variable.instance", regex : "[$][a-zA-Z][a-zA-Z0-9_]*\\b" }, { - token : function(value) { - if (keywords.hasOwnProperty(value)) - return "keyword"; - else if (builtinFunctions.hasOwnProperty(value)) - return "support.function"; - else - return "identifier"; - }, + token : keywordMapper, // TODO: Unicode escape sequences // TODO: Unicode identifiers regex : "[a-zA-Z_$][a-zA-Z0-9_$\\-]*\\b" diff --git a/lib/ace/mode/python_highlight_rules.js b/lib/ace/mode/python_highlight_rules.js index b9e5e48c..91d6d478 100644 --- a/lib/ace/mode/python_highlight_rules.js +++ b/lib/ace/mode/python_highlight_rules.js @@ -43,35 +43,39 @@ define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); -var lang = require("../lib/lang"); var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var PythonHighlightRules = function() { - var keywords = lang.arrayToMap( - ("and|as|assert|break|class|continue|def|del|elif|else|except|exec|" + + var keywords = ( + "and|as|assert|break|class|continue|def|del|elif|else|except|exec|" + "finally|for|from|global|if|import|in|is|lambda|not|or|pass|print|" + - "raise|return|try|while|with|yield").split("|") + "raise|return|try|while|with|yield" ); - var builtinConstants = lang.arrayToMap( - ("True|False|None|NotImplemented|Ellipsis|__debug__").split("|") + var builtinConstants = ( + "True|False|None|NotImplemented|Ellipsis|__debug__" ); - var builtinFunctions = lang.arrayToMap( - ("abs|divmod|input|open|staticmethod|all|enumerate|int|ord|str|any|" + + var builtinFunctions = ( + "abs|divmod|input|open|staticmethod|all|enumerate|int|ord|str|any|" + "eval|isinstance|pow|sum|basestring|execfile|issubclass|print|super|" + "binfile|iter|property|tuple|bool|filter|len|range|type|bytearray|" + "float|list|raw_input|unichr|callable|format|locals|reduce|unicode|" + "chr|frozenset|long|reload|vars|classmethod|getattr|map|repr|xrange|" + "cmp|globals|max|reversed|zip|compile|hasattr|memoryview|round|" + "__import__|complex|hash|min|set|apply|delattr|help|next|setattr|" + - "buffer|dict|hex|object|slice|coerce|dir|id|oct|sorted|intern").split("|") + "buffer|dict|hex|object|slice|coerce|dir|id|oct|sorted|intern" ); - var futureReserved = lang.arrayToMap( - ("").split("|") - ); + //var futureReserved = ""; + var keywordMapper = this.createKeywordMapper({ + "invalid.deprecated": "debugger", + "support.function": builtinFunctions, + //"invalid.illegal": futureReserved, + "constant.language": builtinConstants, + "keyword": keywords + }, "identifier"); var strPre = "(?:r|u|ur|R|U|UR|Ur|uR)?"; @@ -127,20 +131,7 @@ var PythonHighlightRules = function() { token : "constant.numeric", // integer regex : integer + "\\b" }, { - token : function(value) { - if (keywords.hasOwnProperty(value)) - return "keyword"; - else if (builtinConstants.hasOwnProperty(value)) - return "constant.language"; - else if (futureReserved.hasOwnProperty(value)) - return "invalid.illegal"; - else if (builtinFunctions.hasOwnProperty(value)) - return "support.function"; - else if (value == "debugger") - return "invalid.deprecated"; - else - return "identifier"; - }, + token : keywordMapper, regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" }, { token : "keyword.operator", diff --git a/lib/ace/mode/ruby_highlight_rules.js b/lib/ace/mode/ruby_highlight_rules.js index 67cbc672..5124f1aa 100644 --- a/lib/ace/mode/ruby_highlight_rules.js +++ b/lib/ace/mode/ruby_highlight_rules.js @@ -40,14 +40,13 @@ define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); -var lang = require("../lib/lang"); var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var RubyHighlightRules = function() { - var builtinFunctions = lang.arrayToMap( - ("abort|Array|assert|assert_equal|assert_not_equal|assert_same|assert_not_same|" + - "assert_nil|assert_not_nil|assert_match|assert_no_match|assert_in_delta|assert_throws|" + + var builtinFunctions = ( + "abort|Array|assert|assert_equal|assert_not_equal|assert_same|assert_not_same|" + + "assert_nil|assert_not_nil|assert_match|assert_no_match|assert_in_delta|assert_throws|" + "assert_raise|assert_nothing_raised|assert_instance_of|assert_kind_of|assert_respond_to|" + "assert_operator|assert_send|assert_difference|assert_no_difference|assert_recognizes|" + "assert_generates|assert_response|assert_redirected_to|assert_template|assert_select|" + @@ -75,25 +74,33 @@ var RubyHighlightRules = function() { "filter_parameter_logging|match|get|post|resources|redirect|scope|assert_routing|" + "translate|localize|extract_locale_from_tld|t|l|caches_page|expire_page|caches_action|expire_action|" + "cache|expire_fragment|expire_cache_for|observe|cache_sweeper|" + - "has_many|has_one|belongs_to|has_and_belongs_to_many").split("|") + "has_many|has_one|belongs_to|has_and_belongs_to_many" ); - var keywords = lang.arrayToMap( - ("alias|and|BEGIN|begin|break|case|class|def|defined|do|else|elsif|END|end|ensure|" + - "__FILE__|finally|for|gem|if|in|__LINE__|module|next|not|or|private|protected|public|" + - "redo|rescue|retry|return|super|then|undef|unless|until|when|while|yield").split("|") + var keywords = ( + "alias|and|BEGIN|begin|break|case|class|def|defined|do|else|elsif|END|end|ensure|" + + "__FILE__|finally|for|gem|if|in|__LINE__|module|next|not|or|private|protected|public|" + + "redo|rescue|retry|return|super|then|undef|unless|until|when|while|yield" ); - var buildinConstants = lang.arrayToMap( - ("true|TRUE|false|FALSE|nil|NIL|ARGF|ARGV|DATA|ENV|RUBY_PLATFORM|RUBY_RELEASE_DATE|" + - "RUBY_VERSION|STDERR|STDIN|STDOUT|TOPLEVEL_BINDING").split("|") + var buildinConstants = ( + "true|TRUE|false|FALSE|nil|NIL|ARGF|ARGV|DATA|ENV|RUBY_PLATFORM|RUBY_RELEASE_DATE|" + + "RUBY_VERSION|STDERR|STDIN|STDOUT|TOPLEVEL_BINDING" ); - var builtinVariables = lang.arrayToMap( - ("\$DEBUG|\$defout|\$FILENAME|\$LOAD_PATH|\$SAFE|\$stdin|\$stdout|\$stderr|\$VERBOSE|" + - "$!|root_url|flash|session|cookies|params|request|response|logger").split("|") + var builtinVariables = ( + "\$DEBUG|\$defout|\$FILENAME|\$LOAD_PATH|\$SAFE|\$stdin|\$stdout|\$stderr|\$VERBOSE|" + + "$!|root_url|flash|session|cookies|params|request|response|logger|self" ); + var keywordMapper = this.createKeywordMapper({ + "keyword": keywords, + "constant.language": buildinConstants, + "variable.language": builtinVariables, + "support.function": builtinFunctions, + "invalid.deprecated": "debugger" // TODO is this a remnant from js mode? + }, "identifier"); + // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -141,22 +148,7 @@ var RubyHighlightRules = function() { token : "constant.language.boolean", regex : "(?:true|false)\\b" }, { - token : function(value) { - if (value == "self") - return "variable.language"; - else if (keywords.hasOwnProperty(value)) - return "keyword"; - else if (buildinConstants.hasOwnProperty(value)) - return "constant.language"; - else if (builtinVariables.hasOwnProperty(value)) - return "variable.language"; - else if (builtinFunctions.hasOwnProperty(value)) - return "support.function"; - else if (value == "debugger") - return "invalid.deprecated"; - else - return "identifier"; - }, + token : keywordMapper, // TODO: Unicode escape sequences // TODO: Unicode identifiers regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" diff --git a/lib/ace/mode/scad_highlight_rules.js b/lib/ace/mode/scad_highlight_rules.js index 82234750..b2283122 100644 --- a/lib/ace/mode/scad_highlight_rules.js +++ b/lib/ace/mode/scad_highlight_rules.js @@ -47,14 +47,11 @@ var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocComme var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var scadHighlightRules = function() { - - var keywords = lang.arrayToMap( - ("module|if|else|for").split("|") - ); - - var buildinConstants = lang.arrayToMap( - ("NULL").split("|") - ); + var keywordMapper = this.createKeywordMapper({ + "variable.language": "this", + "keyword": "module|if|else|for", + "constant.language": "NULL", + }, "identifier"); // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -97,17 +94,8 @@ var scadHighlightRules = function() { }, { token : "keyword", // pre-compiler directivs regex : "(?:use|include)" - }, { - token : function(value) { - if (value == "this") - return "variable.language"; - else if (keywords.hasOwnProperty(value)) - return "keyword"; - else if (buildinConstants.hasOwnProperty(value)) - return "constant.language"; - else - return "identifier"; - }, + }, { + token : keywordMapper, regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" }, { token : "keyword.operator", diff --git a/lib/ace/mode/scala_highlight_rules.js b/lib/ace/mode/scala_highlight_rules.js index c39962db..2b905256 100644 --- a/lib/ace/mode/scala_highlight_rules.js +++ b/lib/ace/mode/scala_highlight_rules.js @@ -2,27 +2,22 @@ define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); -var lang = require("../lib/lang"); var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules; var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var ScalaHighlightRules = function() { // taken from http://download.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html - var keywords = lang.arrayToMap( - ( + var keywords = ( "case|default|do|else|for|if|match|while|throw|return|try|catch|finally|yield|" + "abstract|class|def|extends|final|forSome|implicit|implicits|import|lazy|new|object|" + "override|package|private|protected|sealed|super|this|trait|type|val|var|with" - ).split("|") ); - var buildinConstants = lang.arrayToMap( - ("true|false").split("|") - ); - - var langClasses = lang.arrayToMap( - ("AbstractMethodError|AssertionError|ClassCircularityError|"+ + var buildinConstants = ("true|false"); + + var langClasses = ( + "AbstractMethodError|AssertionError|ClassCircularityError|"+ "ClassFormatError|Deprecated|EnumConstantNotPresentException|"+ "ExceptionInInitializerError|IllegalAccessError|"+ "IllegalThreadStateException|InstantiationError|InternalError|"+ @@ -49,13 +44,17 @@ var ScalaHighlightRules = function() { "Cloneable|Class|CharSequence|Comparable|String|Object|" + "Unit|Any|AnyVal|AnyRef|Null|ScalaObject|Singleton|Seq|Iterable|List|" + "Option|Array|Char|Byte|Short|Int|Long|Nothing" - - ).split("|") - ); - - var importClasses = lang.arrayToMap( - ("").split("|") + + ); + + var keywordMapper = this.createKeywordMapper({ + "variable.language": "this", + "keyword": keywords, + "support.function": langClasses, + "constant.language": buildinConstants + }, "identifier"); + // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -95,20 +94,7 @@ var ScalaHighlightRules = function() { token : "constant.language.boolean", regex : "(?:true|false)\\b" }, { - token : function(value) { - if (value == "this") - return "variable.language"; - else if (keywords.hasOwnProperty(value)) - return "keyword"; - else if (langClasses.hasOwnProperty(value)) - return "support.function"; - else if (importClasses.hasOwnProperty(value)) - return "support.function"; - else if (buildinConstants.hasOwnProperty(value)) - return "constant.language"; - else - return "identifier"; - }, + token : keywordMapper, // TODO: Unicode escape sequences // TODO: Unicode identifiers regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" @@ -168,7 +154,7 @@ var ScalaHighlightRules = function() { } ] }; - + this.embedRules(DocCommentHighlightRules, "doc-", [ DocCommentHighlightRules.getEndRule("start") ]); }; diff --git a/lib/ace/mode/sh_highlight_rules.js b/lib/ace/mode/sh_highlight_rules.js index d416ab7a..64806372 100644 --- a/lib/ace/mode/sh_highlight_rules.js +++ b/lib/ace/mode/sh_highlight_rules.js @@ -41,21 +41,19 @@ define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); -var lang = require("../lib/lang"); var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var ShHighlightRules = function() { - var reservedKeywords = lang.arrayToMap( - ('!|{|}|case|do|done|elif|else|'+ + var reservedKeywords = ( + '!|{|}|case|do|done|elif|else|'+ 'esac|fi|for|if|in|then|until|while|'+ '&|;|export|local|read|typeset|unset|'+ 'elif|select|set' - ).split('|') ); - var languageConstructs = lang.arrayToMap( - ('[|]|alias|bg|bind|break|builtin|'+ + var languageConstructs = ( + '[|]|alias|bg|bind|break|builtin|'+ 'cd|command|compgen|complete|continue|'+ 'dirs|disown|echo|enable|eval|exec|'+ 'exit|fc|fg|getopts|hash|help|history|'+ @@ -63,9 +61,14 @@ var ShHighlightRules = function() { 'pwd|return|set|shift|shopt|source|'+ 'suspend|test|times|trap|type|ulimit|'+ 'umask|unalias|wait' - ).split('|') ); + var keywordMapper = this.createKeywordMapper({ + "keyword": reservedKeywords, + "constant.language": languageConstructs, + "invalid.deprecated": "debugger" + }, "identifier"); + var integer = "(?:(?:[1-9]\\d*)|(?:0))"; // var integer = "(?:" + decimalInteger + ")"; @@ -112,16 +115,7 @@ var ShHighlightRules = function() { token : "constant.numeric", // integer regex : integer + "\\b" }, { - token : function(value) { - if (reservedKeywords.hasOwnProperty(value)) - return "keyword"; - else if (languageConstructs.hasOwnProperty(value)) - return "constant.language"; - else if (value == "debugger") - return "invalid.deprecated"; - else - return "identifier"; - }, + token : keywordMapper, regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" }, { token : "keyword.operator", diff --git a/lib/ace/mode/sql_highlight_rules.js b/lib/ace/mode/sql_highlight_rules.js index dc099edc..70d91c60 100644 --- a/lib/ace/mode/sql_highlight_rules.js +++ b/lib/ace/mode/sql_highlight_rules.js @@ -22,24 +22,29 @@ define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); -var lang = require("../lib/lang"); var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var SqlHighlightRules = function() { - var keywords = lang.arrayToMap( - ("select|from|where|and|or|group|by|order|limit|offset|having|as|case|" + - "when|else|end|type|left|right|join|on|outer|desc|asc").split("|") + var keywords = ( + "select|from|where|and|or|group|by|order|limit|offset|having|as|case|" + + "when|else|end|type|left|right|join|on|outer|desc|asc" ); - var builtinConstants = lang.arrayToMap( - ("true|false|null").split("|") + var builtinConstants = ( + "true|false|null" ); - var builtinFunctions = lang.arrayToMap( - ("count|min|max|avg|sum|rank|now|coalesce").split("|") + var builtinFunctions = ( + "count|min|max|avg|sum|rank|now|coalesce" ); + var keywordMapper = this.createKeywordMapper({ + "support.function": builtinFunctions, + "keyword": keywords, + "constant.language": builtinConstants + }, "identifier", true); + this.$rules = { "start" : [ { token : "comment", @@ -54,17 +59,7 @@ var SqlHighlightRules = function() { token : "constant.numeric", // float regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" }, { - token : function(value) { - value = value.toLowerCase(); - if (keywords.hasOwnProperty(value)) - return "keyword"; - else if (builtinConstants.hasOwnProperty(value)) - return "constant.language"; - else if (builtinFunctions.hasOwnProperty(value)) - return "support.function"; - else - return "identifier"; - }, + token : keywordMapper, regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" }, { token : "keyword.operator", diff --git a/lib/ace/mode/tcl_highlight_rules.js b/lib/ace/mode/tcl_highlight_rules.js index bf352314..2a40e69a 100644 --- a/lib/ace/mode/tcl_highlight_rules.js +++ b/lib/ace/mode/tcl_highlight_rules.js @@ -39,15 +39,12 @@ define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); -var lang = require("../lib/lang"); var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var TclHighlightRules = function() { - var builtinFunctions = lang.arrayToMap( - ("").split("|") - - ); + //TODO var builtinFunctions = ""; + this.$rules = { "start" : [ { @@ -86,12 +83,7 @@ var TclHighlightRules = function() { token : "support.function", regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|{\\*}|;|::" }, { - token : function(value) { - if (builtinFunctions.hasOwnProperty(value)) - return "keyword"; - else - return "identifier"; - }, + token : "identifier", regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" }, { token : "paren.lparen", diff --git a/lib/ace/mode/xquery_highlight_rules.js b/lib/ace/mode/xquery_highlight_rules.js index fc14c2c5..a74ce205 100644 --- a/lib/ace/mode/xquery_highlight_rules.js +++ b/lib/ace/mode/xquery_highlight_rules.js @@ -38,15 +38,14 @@ define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); -var lang = require("../lib/lang"); var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var XQueryHighlightRules = function() { - var keywords = lang.arrayToMap( - ("after|ancestor|ancestor-or-self|and|as|ascending|attribute|before|case|cast|castable|child|collation|comment|copy|count|declare|default|delete|descendant|descendant-or-self|descending|div|document|document-node|element|else|empty|empty-sequence|end|eq|every|except|first|following|following-sibling|for|function|ge|group|gt|idiv|if|import|insert|instance|intersect|into|is|item|last|le|let|lt|mod|modify|module|namespace|namespace-node|ne|node|only|or|order|ordered|parent|preceding|preceding-sibling|processing-instruction|rename|replace|return|satisfies|schema-attribute|schema-element|self|some|stable|start|switch|text|to|treat|try|typeswitch|union|unordered|validate|where|with|xquery|contains|paragraphs|sentences|times|words|by|collectionreturn|variable|version|option|when|encoding|toswitch|catch|tumbling|sliding|window|at|using|stemming|collection|schema|while|on|nodes|index|external|then|in|updating|value|of|containsbreak|loop|continue|exit|returning").split("|") - ); - + var keywordMapper = this.createKeywordMapper({ + keyword: "after|ancestor|ancestor-or-self|and|as|ascending|attribute|before|case|cast|castable|child|collation|comment|copy|count|declare|default|delete|descendant|descendant-or-self|descending|div|document|document-node|element|else|empty|empty-sequence|end|eq|every|except|first|following|following-sibling|for|function|ge|group|gt|idiv|if|import|insert|instance|intersect|into|is|item|last|le|let|lt|mod|modify|module|namespace|namespace-node|ne|node|only|or|order|ordered|parent|preceding|preceding-sibling|processing-instruction|rename|replace|return|satisfies|schema-attribute|schema-element|self|some|stable|start|switch|text|to|treat|try|typeswitch|union|unordered|validate|where|with|xquery|contains|paragraphs|sentences|times|words|by|collectionreturn|variable|version|option|when|encoding|toswitch|catch|tumbling|sliding|window|at|using|stemming|collection|schema|while|on|nodes|index|external|then|in|updating|value|of|containsbreak|loop|continue|exit|returning" + }, "identifier"); + // regexp must not have capturing parentheses // regexps are ordered -> the first match is used @@ -89,12 +88,7 @@ var XQueryHighlightRules = function() { token: "support.function", regex: "\\w[\\w+_\\-:]+(?=\\()" }, { - token : function(value) { - if (keywords[value]) - return "keyword"; - else - return "identifier"; - }, + token : keywordMapper, regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" }, { token: "keyword.operator",