From f2e523b0b454a64a4c6236b56976baa0d4fb69ea Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Sun, 24 Feb 2013 12:46:32 -0800 Subject: [PATCH] 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