From 258d00dcff17d326df0572f268861545c664d3e1 Mon Sep 17 00:00:00 2001 From: Nicolas Guillaumin Date: Sat, 13 Apr 2013 10:05:39 +1000 Subject: [PATCH 1/2] Added .properties files mode --- demo/kitchen-sink/doclist.js | 1 + demo/kitchen-sink/docs/properties.properties | 15 ++++ demo/kitchen-sink/modelist.js | 1 + lib/ace/mode/properties.js | 50 ++++++++++++ lib/ace/mode/properties_highlight_rules.js | 86 ++++++++++++++++++++ 5 files changed, 153 insertions(+) create mode 100644 demo/kitchen-sink/docs/properties.properties create mode 100644 lib/ace/mode/properties.js create mode 100644 lib/ace/mode/properties_highlight_rules.js diff --git a/demo/kitchen-sink/doclist.js b/demo/kitchen-sink/doclist.js index 7e3feb47..2da245ca 100644 --- a/demo/kitchen-sink/doclist.js +++ b/demo/kitchen-sink/doclist.js @@ -112,6 +112,7 @@ var docs = { "docs/php.php": "PHP", "docs/plaintext.txt": {name: "Plain Text", prepare: makeHuge, wrapped: true}, "docs/powershell.ps1": "Powershell", + "docs/properties.properties": "Properties", "docs/python.py": "Python", "docs/r.r": "R", "docs/rdoc.Rd": "RDoc", diff --git a/demo/kitchen-sink/docs/properties.properties b/demo/kitchen-sink/docs/properties.properties new file mode 100644 index 00000000..446b340d --- /dev/null +++ b/demo/kitchen-sink/docs/properties.properties @@ -0,0 +1,15 @@ +# You are reading the ".properties" entry. +! The exclamation mark can also mark text as comments. +# The key and element characters #, !, =, and : are written with a preceding backslash to ensure that they are properly loaded. +website = http\://en.wikipedia.org/ +language = English +# The backslash below tells the application to continue reading +# the value onto the next line. +message = Welcome to \ + Wikipedia! +# Add spaces to the key +key\ with\ spaces = This is the value that could be looked up with the key "key with spaces". +# Unicode +tab : \u0009 +empty-key= +last.line=value diff --git a/demo/kitchen-sink/modelist.js b/demo/kitchen-sink/modelist.js index 4611e406..5cf1ae1e 100644 --- a/demo/kitchen-sink/modelist.js +++ b/demo/kitchen-sink/modelist.js @@ -82,6 +82,7 @@ var modesByName = { pgsql: ["pgSQL" , "pgsql"], php: ["PHP" , "php|phtml"], powershell: ["Powershell" , "ps1"], + properties: ["Properties" , "properties"], python: ["Python" , "py"], r: ["R" , "r"], rdoc: ["RDoc" , "Rd"], diff --git a/lib/ace/mode/properties.js b/lib/ace/mode/properties.js new file mode 100644 index 00000000..68680656 --- /dev/null +++ b/lib/ace/mode/properties.js @@ -0,0 +1,50 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2010, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var TextMode = require("./text").Mode; +var Tokenizer = require("../tokenizer").Tokenizer; +var PropertiesHighlightRules = require("./properties_highlight_rules").PropertiesHighlightRules; + +var Mode = function() { + var highlighter = new PropertiesHighlightRules(); + this.$tokenizer = new Tokenizer(highlighter.getRules()); +}; +oop.inherits(Mode, TextMode); + +(function() { + +}).call(Mode.prototype); + +exports.Mode = Mode; +}); diff --git a/lib/ace/mode/properties_highlight_rules.js b/lib/ace/mode/properties_highlight_rules.js new file mode 100644 index 00000000..5a1c2843 --- /dev/null +++ b/lib/ace/mode/properties_highlight_rules.js @@ -0,0 +1,86 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2010, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; + +var PropertiesHighlightRules = function() { + + var escapeRe = /\\u[0-9a-fA-F]{4}|\\/; + + this.$rules = { + "start" : [ + { + token : "comment", + regex : /[!#].*$/ + }, { + // Empty value + token : "keyword", + regex : /[=:]$/ + }, { + token : "keyword", + regex : /[=:]/, + next : "value" + }, { + token : "constant.language.escape", + regex : escapeRe, + }, { + defaultToken: "variable" + } + ], + "value" : [ + { + // Multi-line string + regex : /\\$/, + token : "string", + next : "value" + }, { + regex : /$/, + token : "string", + next : "start" + }, { + token : "constant.language.escape", + regex : escapeRe + }, { + defaultToken: "string" + } + ] + }; + +}; + +oop.inherits(PropertiesHighlightRules, TextHighlightRules); + +exports.PropetiesHighlightRules = PropertiesHighlightRules; +}); + From 8f0b5abb3add52cc4c8f0488a67c9952c47c0e32 Mon Sep 17 00:00:00 2001 From: Nicolas Guillaumin Date: Sat, 13 Apr 2013 10:57:16 +1000 Subject: [PATCH 2/2] Cleanup + fix typo on export --- lib/ace/mode/properties.js | 4 ---- lib/ace/mode/properties_highlight_rules.js | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/ace/mode/properties.js b/lib/ace/mode/properties.js index 68680656..cd71a52c 100644 --- a/lib/ace/mode/properties.js +++ b/lib/ace/mode/properties.js @@ -42,9 +42,5 @@ var Mode = function() { }; oop.inherits(Mode, TextMode); -(function() { - -}).call(Mode.prototype); - exports.Mode = Mode; }); diff --git a/lib/ace/mode/properties_highlight_rules.js b/lib/ace/mode/properties_highlight_rules.js index 5a1c2843..36640175 100644 --- a/lib/ace/mode/properties_highlight_rules.js +++ b/lib/ace/mode/properties_highlight_rules.js @@ -81,6 +81,6 @@ var PropertiesHighlightRules = function() { oop.inherits(PropertiesHighlightRules, TextHighlightRules); -exports.PropetiesHighlightRules = PropertiesHighlightRules; +exports.PropertiesHighlightRules = PropertiesHighlightRules; });