From f2e523b0b454a64a4c6236b56976baa0d4fb69ea Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Sun, 24 Feb 2013 12:46:32 -0800 Subject: [PATCH 1/4] Initial addition of toml files --- demo/kitchen-sink/doclist.js | 1 + demo/kitchen-sink/docs/toml.toml | 29 +++++++++ demo/kitchen-sink/modelist.js | 1 + lib/ace/mode/toml.js | 58 +++++++++++++++++ lib/ace/mode/toml_highlight_rules.js | 95 ++++++++++++++++++++++++++++ 5 files changed, 184 insertions(+) create mode 100644 demo/kitchen-sink/docs/toml.toml create mode 100644 lib/ace/mode/toml.js create mode 100644 lib/ace/mode/toml_highlight_rules.js diff --git a/demo/kitchen-sink/doclist.js b/demo/kitchen-sink/doclist.js index 5dc25b84..91bbefc3 100644 --- a/demo/kitchen-sink/doclist.js +++ b/demo/kitchen-sink/doclist.js @@ -123,6 +123,7 @@ var docs = { "docs/tex.tex": "Tex", "docs/textile.textile": {name: "Textile", wrapped: true}, "docs/tmSnippet.tmSnippet": "tmSnippet", + "docs/toml.toml": "TOML", "docs/typescript.ts": "Typescript", "docs/vbscript.vbs": "VBScript", "docs/xml.xml": "XML", diff --git a/demo/kitchen-sink/docs/toml.toml b/demo/kitchen-sink/docs/toml.toml new file mode 100644 index 00000000..46e5b9d1 --- /dev/null +++ b/demo/kitchen-sink/docs/toml.toml @@ -0,0 +1,29 @@ +# This is a TOML document. Boom. + +title = "TOML Example" + +[owner] +name = "Tom Preston-Werner" +organization = "GitHub" +bio = "GitHub Cofounder & CEO\nLikes tater tots and beer." +dob = 1979-05-27T07:32:00Z # First class dates? Why not? + +[database] +server = "192.168.1.1" +ports = [ 8001, 8001, 8002 ] +connection_max = 5000 +enabled = true + +[servers] + + # You can indent as you please. Tabs or spaces. TOML don't care. + [servers.alpha] + ip = "10.0.0.1" + dc = "eqdc10" + + [servers.beta] + ip = "10.0.0.2" + dc = "eqdc10" + +[clients] +data = [ ["gamma", "delta"], [1, 2] ] # just an update to make sure parsers support it \ No newline at end of file diff --git a/demo/kitchen-sink/modelist.js b/demo/kitchen-sink/modelist.js index d48edeaa..ac9a5b5d 100644 --- a/demo/kitchen-sink/modelist.js +++ b/demo/kitchen-sink/modelist.js @@ -95,6 +95,7 @@ var modesByName = { text: ["Text" , "txt"], textile: ["Textile" , "textile"], tm_snippet: ["tmSnippet" , "tmSnippet"], + toml: ["toml" , "toml"], typescript: ["Typescript" , "typescript|ts|str"], vbscript: ["VBScript" , "vbs"], xml: ["XML" , "xml|rdf|rss|wsdl|xslt|atom|mathml|mml|xul|xbl"], diff --git a/lib/ace/mode/toml.js b/lib/ace/mode/toml.js new file mode 100644 index 00000000..066f2304 --- /dev/null +++ b/lib/ace/mode/toml.js @@ -0,0 +1,58 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2013, 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. + * + * + * Contributor(s): + * + * Garen J. Torikian + * + * ***** 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 TomlHighlightRules = require("./toml_highlight_rules").TomlHighlightRules; +// TODO: pick appropriate fold mode +var FoldMode = require("./folding/cstyle").FoldMode; + +var Mode = function() { + var highlighter = new TomlHighlightRules(); + this.foldingRules = new FoldMode(); + this.$tokenizer = new Tokenizer(highlighter.getRules()); +}; +oop.inherits(Mode, TextMode); + +(function() { + // Extra logic goes here. +}).call(Mode.prototype); + +exports.Mode = Mode; +}); \ No newline at end of file diff --git a/lib/ace/mode/toml_highlight_rules.js b/lib/ace/mode/toml_highlight_rules.js new file mode 100644 index 00000000..92adb76f --- /dev/null +++ b/lib/ace/mode/toml_highlight_rules.js @@ -0,0 +1,95 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2013, 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. + * + * + * Contributor(s): + * + * Garen J. Torikian + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; + +var TomlHighlightRules = function() { + var keywordMapper = this.createKeywordMapper({ + "constant.language.boolean": "true|false" + }, "identifier"); + + var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\\d\\$_\u00a1-\uffff]*\\b"; + + this.$rules = + { + "start": [ + { + token: "comment.toml", + regex: /#.*$/ + }, + { + token : "string", + regex : '"(?=.)', + next : "qqstring" + }, + { + token: ["text", "variable.keygroup.toml"], + regex: /(?:^\\s*)(?:\\[([^\\]]+)\\])/ + }, + { + token : keywordMapper, + regex : identifierRe + }, + { + token : "support.date.toml", + regex: "\\d{4}-\\d{2}-\\d{2}(T)\\d{2}:\\d{2}:\\d{2}(Z)" + }, + { + token: "constant.numeric.toml", + regex: "-?\\d+(\\.?\\d+)?" + } + ], + "qqstring" : [ + { + token : "string", + regex : "\\\\$", + next : "qqstring", + }, + { + defaultToken: "string" + } + ] + } + +}; + +oop.inherits(TomlHighlightRules, TextHighlightRules); + +exports.TomlHighlightRules = TomlHighlightRules; +}); \ No newline at end of file From 068fee994b0775badb2afc97556e5e3578d316a3 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Sun, 24 Feb 2013 12:54:17 -0800 Subject: [PATCH 2/4] Fix up highlight rules --- lib/ace/mode/toml_highlight_rules.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/ace/mode/toml_highlight_rules.js b/lib/ace/mode/toml_highlight_rules.js index 92adb76f..6700c11a 100644 --- a/lib/ace/mode/toml_highlight_rules.js +++ b/lib/ace/mode/toml_highlight_rules.js @@ -59,8 +59,8 @@ var TomlHighlightRules = function() { next : "qqstring" }, { - token: ["text", "variable.keygroup.toml"], - regex: /(?:^\\s*)(?:\\[([^\\]]+)\\])/ + token: ["variable.keygroup.toml"], + regex: "(?:^\\s*)(\\[([^\\]]+)\\])" }, { token : keywordMapper, @@ -81,6 +81,11 @@ var TomlHighlightRules = function() { regex : "\\\\$", next : "qqstring", }, + { + token : "string", + regex : '"|$', + next : "start", + }, { defaultToken: "string" } From 7f90df40b273efd118eb5d87287d4a96a17a6a1e Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Sun, 24 Feb 2013 12:55:07 -0800 Subject: [PATCH 3/4] Add TOML JSON test --- lib/ace/mode/_test/tokens_toml.json | 129 ++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 lib/ace/mode/_test/tokens_toml.json diff --git a/lib/ace/mode/_test/tokens_toml.json b/lib/ace/mode/_test/tokens_toml.json new file mode 100644 index 00000000..accc0c49 --- /dev/null +++ b/lib/ace/mode/_test/tokens_toml.json @@ -0,0 +1,129 @@ +[[ + "start", + ["comment.toml","# This is a TOML document. Boom."] +],[ + "start" +],[ + "start", + ["identifier","title"], + ["text"," = "], + ["string","\"TOML Example\""] +],[ + "start" +],[ + "start", + ["variable.keygroup.toml","[owner]"] +],[ + "start", + ["identifier","name"], + ["text"," = "], + ["string","\"Tom Preston-Werner\""] +],[ + "start", + ["identifier","organization"], + ["text"," = "], + ["string","\"GitHub\""] +],[ + "start", + ["identifier","bio"], + ["text"," = "], + ["string","\"GitHub Cofounder & CEO\\nLikes tater tots and beer.\""] +],[ + "start", + ["identifier","dob"], + ["text"," = "], + ["support.date.toml","1979-05-27T07:32:00Z"], + ["text"," "], + ["comment.toml","# First class dates? Why not?"] +],[ + "start" +],[ + "start", + ["variable.keygroup.toml","[database]"] +],[ + "start", + ["identifier","server"], + ["text"," = "], + ["string","\"192.168.1.1\""] +],[ + "start", + ["identifier","ports"], + ["text"," = [ "], + ["constant.numeric.toml","8001"], + ["text",", "], + ["constant.numeric.toml","8001"], + ["text",", "], + ["constant.numeric.toml","8002"], + ["text"," ]"] +],[ + "start", + ["identifier","connection_max"], + ["text"," = "], + ["constant.numeric.toml","5000"] +],[ + "start", + ["identifier","enabled"], + ["text"," = "], + ["constant.language.boolean","true"] +],[ + "start" +],[ + "start", + ["variable.keygroup.toml","[servers]"] +],[ + "start" +],[ + "start", + ["text"," "], + ["comment.toml","# You can indent as you please. Tabs or spaces. TOML don't care."] +],[ + "start", + ["variable.keygroup.toml"," [servers.alpha]"] +],[ + "start", + ["text"," "], + ["identifier","ip"], + ["text"," = "], + ["string","\"10.0.0.1\""] +],[ + "start", + ["text"," "], + ["identifier","dc"], + ["text"," = "], + ["string","\"eqdc10\""] +],[ + "start" +],[ + "start", + ["variable.keygroup.toml"," [servers.beta]"] +],[ + "start", + ["text"," "], + ["identifier","ip"], + ["text"," = "], + ["string","\"10.0.0.2\""] +],[ + "start", + ["text"," "], + ["identifier","dc"], + ["text"," = "], + ["string","\"eqdc10\""] +],[ + "start" +],[ + "start", + ["variable.keygroup.toml","[clients]"] +],[ + "start", + ["identifier","data"], + ["text"," = [ ["], + ["string","\"gamma\""], + ["text",", "], + ["string","\"delta\""], + ["text","], ["], + ["constant.numeric.toml","1"], + ["text",", "], + ["constant.numeric.toml","2"], + ["text","] ] "], + ["comment.toml","# just an update to make sure parsers support it"] +]] \ No newline at end of file From 9bfdcd410412d1651fb8c74b8646644719a4d43f Mon Sep 17 00:00:00 2001 From: nightwing Date: Mon, 25 Feb 2013 01:52:49 +0400 Subject: [PATCH 4/4] highlight escaped characters in strings --- lib/ace/lib/dom.js | 3 +++ lib/ace/mode/_test/tokens_toml.json | 4 +++- lib/ace/mode/toml.js | 9 +++++---- lib/ace/mode/toml_highlight_rules.js | 17 ++++++++++------- tool/mode.tmpl.js | 10 ++++++---- 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/lib/ace/lib/dom.js b/lib/ace/lib/dom.js index 4df72736..b3724009 100644 --- a/lib/ace/lib/dom.js +++ b/lib/ace/lib/dom.js @@ -31,6 +31,9 @@ define(function(require, exports, module) { "use strict"; +if (typeof document == "undefined") + return; + var XHTML_NS = "http://www.w3.org/1999/xhtml"; exports.getDocumentHead = function(doc) { diff --git a/lib/ace/mode/_test/tokens_toml.json b/lib/ace/mode/_test/tokens_toml.json index accc0c49..ec471f74 100644 --- a/lib/ace/mode/_test/tokens_toml.json +++ b/lib/ace/mode/_test/tokens_toml.json @@ -27,7 +27,9 @@ "start", ["identifier","bio"], ["text"," = "], - ["string","\"GitHub Cofounder & CEO\\nLikes tater tots and beer.\""] + ["string","\"GitHub Cofounder & CEO"], + ["constant.language.escape","\\n"], + ["string","Likes tater tots and beer.\""] ],[ "start", ["identifier","dob"], diff --git a/lib/ace/mode/toml.js b/lib/ace/mode/toml.js index 066f2304..bd47182f 100644 --- a/lib/ace/mode/toml.js +++ b/lib/ace/mode/toml.js @@ -3,7 +3,7 @@ * * Copyright (c) 2013, 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 @@ -14,7 +14,7 @@ * * 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 @@ -28,7 +28,7 @@ * * * Contributor(s): - * + * * Garen J. Torikian * * ***** END LICENSE BLOCK ***** */ @@ -51,7 +51,8 @@ var Mode = function() { oop.inherits(Mode, TextMode); (function() { - // Extra logic goes here. + this.lineCommentStart = "#"; + // Extra logic goes here. }).call(Mode.prototype); exports.Mode = Mode; diff --git a/lib/ace/mode/toml_highlight_rules.js b/lib/ace/mode/toml_highlight_rules.js index 6700c11a..a448923d 100644 --- a/lib/ace/mode/toml_highlight_rules.js +++ b/lib/ace/mode/toml_highlight_rules.js @@ -28,7 +28,7 @@ * * * Contributor(s): - * + * * Garen J. Torikian * * ***** END LICENSE BLOCK ***** */ @@ -46,10 +46,9 @@ var TomlHighlightRules = function() { var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\\d\\$_\u00a1-\uffff]*\\b"; - this.$rules = - { + this.$rules = { "start": [ - { + { token: "comment.toml", regex: /#.*$/ }, @@ -65,7 +64,7 @@ var TomlHighlightRules = function() { { token : keywordMapper, regex : identifierRe - }, + }, { token : "support.date.toml", regex: "\\d{4}-\\d{2}-\\d{2}(T)\\d{2}:\\d{2}:\\d{2}(Z)" @@ -80,12 +79,16 @@ var TomlHighlightRules = function() { token : "string", regex : "\\\\$", next : "qqstring", - }, + }, + { + token : "constant.language.escape", + regex : '\\\\[0tnr"\\\\]' + }, { token : "string", regex : '"|$', next : "start", - }, + }, { defaultToken: "string" } diff --git a/tool/mode.tmpl.js b/tool/mode.tmpl.js index a3da521e..054cb7e6 100644 --- a/tool/mode.tmpl.js +++ b/tool/mode.tmpl.js @@ -3,7 +3,7 @@ * * Copyright (c) 2012, 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 @@ -14,7 +14,7 @@ * * 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 @@ -28,7 +28,7 @@ * * * Contributor(s): - * + * * * * ***** END LICENSE BLOCK ***** */ @@ -55,7 +55,9 @@ var Mode = function() { oop.inherits(Mode, TextMode); (function() { - // Extra logic goes here. + this.lineCommentStart = "//"; + this.blockComment = {start: "/*", end: "*/"}; + // Extra logic goes here. }).call(Mode.prototype); exports.Mode = Mode;