Merge pull request #1600 from ajaxorg/protobuf

Added a Google Protobuf mode
This commit is contained in:
Lennart Kats
2013-09-11 05:59:22 -07:00
6 changed files with 159 additions and 2 deletions

View File

@@ -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 = {

View File

@@ -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;
}

View File

@@ -108,6 +108,7 @@ var supportedModes = {
Powershell: ["ps1"],
Prolog: ["plg|prolog"],
Properties: ["properties"],
Protobuf: ["proto"],
Python: ["py"],
R: ["r"],
RDoc: ["Rd"],

66
lib/ace/mode/protobuf.js Normal file
View File

@@ -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;
});

View File

@@ -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;
});

View File

@@ -0,0 +1,7 @@
define(function(require, exports, module) {
"use strict";
exports.snippetText = "";
exports.scope = "protobuf";
});