LaravelTest
72 строки · 2.1 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14function wordRegexp(words) {15return new RegExp("^((" + words.join(")|(") + "))\\b", "i");16};17
18var keywordArray = [19"package", "message", "import", "syntax",20"required", "optional", "repeated", "reserved", "default", "extensions", "packed",21"bool", "bytes", "double", "enum", "float", "string",22"int32", "int64", "uint32", "uint64", "sint32", "sint64", "fixed32", "fixed64", "sfixed32", "sfixed64",23"option", "service", "rpc", "returns"24];25var keywords = wordRegexp(keywordArray);26
27CodeMirror.registerHelper("hintWords", "protobuf", keywordArray);28
29var identifiers = new RegExp("^[_A-Za-z\xa1-\uffff][_A-Za-z0-9\xa1-\uffff]*");30
31function tokenBase(stream) {32// whitespaces33if (stream.eatSpace()) return null;34
35// Handle one line Comments36if (stream.match("//")) {37stream.skipToEnd();38return "comment";39}40
41// Handle Number Literals42if (stream.match(/^[0-9\.+-]/, false)) {43if (stream.match(/^[+-]?0x[0-9a-fA-F]+/))44return "number";45if (stream.match(/^[+-]?\d*\.\d+([EeDd][+-]?\d+)?/))46return "number";47if (stream.match(/^[+-]?\d+([EeDd][+-]?\d+)?/))48return "number";49}50
51// Handle Strings52if (stream.match(/^"([^"]|(""))*"/)) { return "string"; }53if (stream.match(/^'([^']|(''))*'/)) { return "string"; }54
55// Handle words56if (stream.match(keywords)) { return "keyword"; }57if (stream.match(identifiers)) { return "variable"; } ;58
59// Handle non-detected items60stream.next();61return null;62};63
64CodeMirror.defineMode("protobuf", function() {65return {66token: tokenBase,67fold: "brace"68};69});70
71CodeMirror.defineMIME("text/x-protobuf", "protobuf");72});73