From 7c8d81333f90a6e161dea7970c889c685b82e241 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Wed, 11 Sep 2013 14:37:50 +0200 Subject: [PATCH] Added a Google Protobuf mode --- demo/kitchen-sink/doclist.js | 5 +- demo/kitchen-sink/docs/protobuf.proto | 16 ++++++ lib/ace/ext/modelist.js | 1 + lib/ace/mode/protobuf.js | 66 ++++++++++++++++++++++++ lib/ace/mode/protobuf_highlight_rules.js | 66 ++++++++++++++++++++++++ lib/ace/snippets/protobuf.js | 7 +++ 6 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 demo/kitchen-sink/docs/protobuf.proto create mode 100644 lib/ace/mode/protobuf.js create mode 100644 lib/ace/mode/protobuf_highlight_rules.js create mode 100644 lib/ace/snippets/protobuf.js diff --git a/demo/kitchen-sink/doclist.js b/demo/kitchen-sink/doclist.js index a5f92fd4..62b8a029 100644 --- a/demo/kitchen-sink/doclist.js +++ b/demo/kitchen-sink/doclist.js @@ -140,7 +140,7 @@ var docs = { "docs/xquery.xq": "XQuery", "docs/yaml.yaml": "YAML", "docs/c9search.c9search_results": "C9 Search Results", - + "docs/actionscript.as": "ActionScript", "docs/assembly_x86.asm": "Assembly_x86", "docs/autohotkey.ahk": "AutoHotKey", @@ -152,7 +152,8 @@ var docs = { "docs/prolog.plg": "Prolog", "docs/rust.rs": "Rust", "docs/twig.twig": "Twig", - "docs/Nix.nix": "Nix" + "docs/Nix.nix": "Nix", + "docs/protobuf.proto": "Protobuf" }; var ownSource = { diff --git a/demo/kitchen-sink/docs/protobuf.proto b/demo/kitchen-sink/docs/protobuf.proto new file mode 100644 index 00000000..4da95a75 --- /dev/null +++ b/demo/kitchen-sink/docs/protobuf.proto @@ -0,0 +1,16 @@ +message Point { + required int32 x = 1; + required int32 y = 2; + optional string label = 3; +} + +message Line { + required Point start = 1; + required Point end = 2; + optional string label = 3; +} + +message Polyline { + repeated Point point = 1; + optional string label = 2; +} \ No newline at end of file diff --git a/lib/ace/ext/modelist.js b/lib/ace/ext/modelist.js index 5e6551ba..77997b6c 100644 --- a/lib/ace/ext/modelist.js +++ b/lib/ace/ext/modelist.js @@ -108,6 +108,7 @@ var supportedModes = { Powershell: ["ps1"], Prolog: ["plg|prolog"], Properties: ["properties"], + Protobuf: ["proto"], Python: ["py"], R: ["r"], RDoc: ["Rd"], diff --git a/lib/ace/mode/protobuf.js b/lib/ace/mode/protobuf.js new file mode 100644 index 00000000..a3660bd0 --- /dev/null +++ b/lib/ace/mode/protobuf.js @@ -0,0 +1,66 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * 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 + * 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): + * + * Zef Hemel + * + * ***** END LICENSE BLOCK ***** */ + +/* + THIS FILE WAS AUTOGENERATED BY mode.tmpl.js +*/ + +define(function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var CMode = require("./c_cpp").Mode; +var Tokenizer = require("../tokenizer").Tokenizer; +var ProtobufHighlightRules = require("./protobuf_highlight_rules").ProtobufHighlightRules; +var CStyleFoldMode = require("./folding/cstyle").FoldMode; + +var Mode = function() { + CMode.call(this); + var highlighter = new ProtobufHighlightRules(); + this.foldingRules = new CStyleFoldMode(); + + this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$keywordList = highlighter.$keywordList; +}; +oop.inherits(Mode, CMode); + +(function() { + // Extra logic goes here. + this.lineCommentStart = "//"; + this.blockComment = {start: "/*", end: "*/"}; +}).call(Mode.prototype); + +exports.Mode = Mode; +}); \ No newline at end of file diff --git a/lib/ace/mode/protobuf_highlight_rules.js b/lib/ace/mode/protobuf_highlight_rules.js new file mode 100644 index 00000000..fd241549 --- /dev/null +++ b/lib/ace/mode/protobuf_highlight_rules.js @@ -0,0 +1,66 @@ +define(function(require, exports, module) { + "use strict"; + + var oop = require("../lib/oop"); + var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; + + var ProtobufHighlightRules = function() { + + var builtinTypes = "double|float|int32|int64|uint32|uint64|sint32|" + + "sint64|fixed32|fixed64|sfixed32|sfixed64|bool|" + + "string|bytes"; + var keywordDeclaration = "message|required|optional|repeated|package|" + + "import|option|enum"; + + var keywordMapper = this.createKeywordMapper({ + "keyword.declaration.protobuf": keywordDeclaration, + "support.type": builtinTypes + }, "identifier"); + + this.$rules = { + "start": [{ + token: "comment", + regex: /\/\/.*$/ + }, { + token: "comment", + regex: /\/\*/, + next: "comment" + }, { + token: "constant", + regex: "<[^>]+>" + }, { + regex: "=", + token: "keyword.operator.assignment.protobuf" + }, { + 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: keywordMapper, + regex: "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" + }], + "comment": [{ + token: "comment", // closing comment + regex: ".*?\\*\\/", + next: "start" + }, { + token: "comment", // comment spanning whole line + regex: ".+" + }] + }; + + this.normalizeRules(); + }; + + oop.inherits(ProtobufHighlightRules, TextHighlightRules); + + exports.ProtobufHighlightRules = ProtobufHighlightRules; +}); \ No newline at end of file diff --git a/lib/ace/snippets/protobuf.js b/lib/ace/snippets/protobuf.js new file mode 100644 index 00000000..24855545 --- /dev/null +++ b/lib/ace/snippets/protobuf.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = ""; +exports.scope = "protobuf"; + +}); \ No newline at end of file