protobuf.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. "use strict";
  2. /*!-----------------------------------------------------------------------------
  3. * Copyright (c) Microsoft Corporation. All rights reserved.
  4. * Version: 0.38.0(0e330ae453813de4e6cf272460fb79c7117073d0)
  5. * Released under the MIT license
  6. * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
  7. *-----------------------------------------------------------------------------*/
  8. define("vs/basic-languages/protobuf/protobuf", ["require"],(require)=>{
  9. var moduleExports = (() => {
  10. var __defProp = Object.defineProperty;
  11. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  12. var __getOwnPropNames = Object.getOwnPropertyNames;
  13. var __hasOwnProp = Object.prototype.hasOwnProperty;
  14. var __export = (target, all) => {
  15. for (var name in all)
  16. __defProp(target, name, { get: all[name], enumerable: true });
  17. };
  18. var __copyProps = (to, from, except, desc) => {
  19. if (from && typeof from === "object" || typeof from === "function") {
  20. for (let key of __getOwnPropNames(from))
  21. if (!__hasOwnProp.call(to, key) && key !== except)
  22. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  23. }
  24. return to;
  25. };
  26. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  27. // src/basic-languages/protobuf/protobuf.ts
  28. var protobuf_exports = {};
  29. __export(protobuf_exports, {
  30. conf: () => conf,
  31. language: () => language
  32. });
  33. var namedLiterals = ["true", "false"];
  34. var conf = {
  35. comments: {
  36. lineComment: "//",
  37. blockComment: ["/*", "*/"]
  38. },
  39. brackets: [
  40. ["{", "}"],
  41. ["[", "]"],
  42. ["(", ")"],
  43. ["<", ">"]
  44. ],
  45. surroundingPairs: [
  46. { open: "{", close: "}" },
  47. { open: "[", close: "]" },
  48. { open: "(", close: ")" },
  49. { open: "<", close: ">" },
  50. { open: '"', close: '"' },
  51. { open: "'", close: "'" }
  52. ],
  53. autoClosingPairs: [
  54. { open: "{", close: "}" },
  55. { open: "[", close: "]" },
  56. { open: "(", close: ")" },
  57. { open: "<", close: ">" },
  58. { open: '"', close: '"', notIn: ["string"] },
  59. { open: "'", close: "'", notIn: ["string"] }
  60. ],
  61. autoCloseBefore: ".,=}])>' \n ",
  62. indentationRules: {
  63. increaseIndentPattern: new RegExp("^((?!\\/\\/).)*(\\{[^}\"'`]*|\\([^)\"'`]*|\\[[^\\]\"'`]*)$"),
  64. decreaseIndentPattern: new RegExp("^((?!.*?\\/\\*).*\\*/)?\\s*[\\}\\]].*$")
  65. }
  66. };
  67. var language = {
  68. defaultToken: "",
  69. tokenPostfix: ".proto",
  70. brackets: [
  71. { open: "{", close: "}", token: "delimiter.curly" },
  72. { open: "[", close: "]", token: "delimiter.square" },
  73. { open: "(", close: ")", token: "delimiter.parenthesis" },
  74. { open: "<", close: ">", token: "delimiter.angle" }
  75. ],
  76. symbols: /[=><!~?:&|+\-*/^%]+/,
  77. keywords: [
  78. "syntax",
  79. "import",
  80. "weak",
  81. "public",
  82. "package",
  83. "option",
  84. "repeated",
  85. "oneof",
  86. "map",
  87. "reserved",
  88. "to",
  89. "max",
  90. "enum",
  91. "message",
  92. "service",
  93. "rpc",
  94. "stream",
  95. "returns",
  96. "package",
  97. "optional",
  98. "true",
  99. "false"
  100. ],
  101. builtinTypes: [
  102. "double",
  103. "float",
  104. "int32",
  105. "int64",
  106. "uint32",
  107. "uint64",
  108. "sint32",
  109. "sint64",
  110. "fixed32",
  111. "fixed64",
  112. "sfixed32",
  113. "sfixed64",
  114. "bool",
  115. "string",
  116. "bytes"
  117. ],
  118. operators: ["=", "+", "-"],
  119. namedLiterals,
  120. escapes: `\\\\(u{[0-9A-Fa-f]+}|n|r|t|\\\\|'|\\\${)`,
  121. identifier: /[a-zA-Z]\w*/,
  122. fullIdentifier: /@identifier(?:\s*\.\s*@identifier)*/,
  123. optionName: /(?:@identifier|\(\s*@fullIdentifier\s*\))(?:\s*\.\s*@identifier)*/,
  124. messageName: /@identifier/,
  125. enumName: /@identifier/,
  126. messageType: /\.?\s*(?:@identifier\s*\.\s*)*@messageName/,
  127. enumType: /\.?\s*(?:@identifier\s*\.\s*)*@enumName/,
  128. floatLit: /[0-9]+\s*\.\s*[0-9]*(?:@exponent)?|[0-9]+@exponent|\.[0-9]+(?:@exponent)?/,
  129. exponent: /[eE]\s*[+-]?\s*[0-9]+/,
  130. boolLit: /true\b|false\b/,
  131. decimalLit: /[1-9][0-9]*/,
  132. octalLit: /0[0-7]*/,
  133. hexLit: /0[xX][0-9a-fA-F]+/,
  134. type: /double|float|int32|int64|uint32|uint64|sint32|sint64|fixed32|fixed64|sfixed32|sfixed64|bool|string|bytes|@messageType|@enumType/,
  135. keyType: /int32|int64|uint32|uint64|sint32|sint64|fixed32|fixed64|sfixed32|sfixed64|bool|string/,
  136. tokenizer: {
  137. root: [
  138. { include: "@whitespace" },
  139. [/syntax/, "keyword"],
  140. [/=/, "operators"],
  141. [/;/, "delimiter"],
  142. [
  143. /(")(proto3)(")/,
  144. ["string.quote", "string", { token: "string.quote", switchTo: "@topLevel.proto3" }]
  145. ],
  146. [
  147. /(")(proto2)(")/,
  148. ["string.quote", "string", { token: "string.quote", switchTo: "@topLevel.proto2" }]
  149. ],
  150. [
  151. /.*?/,
  152. { token: "", switchTo: "@topLevel.proto2" }
  153. ]
  154. ],
  155. topLevel: [
  156. { include: "@whitespace" },
  157. { include: "@constant" },
  158. [/=/, "operators"],
  159. [/[;.]/, "delimiter"],
  160. [
  161. /@fullIdentifier/,
  162. {
  163. cases: {
  164. option: { token: "keyword", next: "@option.$S2" },
  165. enum: { token: "keyword", next: "@enumDecl.$S2" },
  166. message: { token: "keyword", next: "@messageDecl.$S2" },
  167. service: { token: "keyword", next: "@serviceDecl.$S2" },
  168. extend: {
  169. cases: {
  170. "$S2==proto2": { token: "keyword", next: "@extendDecl.$S2" }
  171. }
  172. },
  173. "@keywords": "keyword",
  174. "@default": "identifier"
  175. }
  176. }
  177. ]
  178. ],
  179. enumDecl: [
  180. { include: "@whitespace" },
  181. [/@identifier/, "type.identifier"],
  182. [/{/, { token: "@brackets", bracket: "@open", switchTo: "@enumBody.$S2" }]
  183. ],
  184. enumBody: [
  185. { include: "@whitespace" },
  186. { include: "@constant" },
  187. [/=/, "operators"],
  188. [/;/, "delimiter"],
  189. [/option\b/, "keyword", "@option.$S2"],
  190. [/@identifier/, "identifier"],
  191. [/\[/, { token: "@brackets", bracket: "@open", next: "@options.$S2" }],
  192. [/}/, { token: "@brackets", bracket: "@close", next: "@pop" }]
  193. ],
  194. messageDecl: [
  195. { include: "@whitespace" },
  196. [/@identifier/, "type.identifier"],
  197. [/{/, { token: "@brackets", bracket: "@open", switchTo: "@messageBody.$S2" }]
  198. ],
  199. messageBody: [
  200. { include: "@whitespace" },
  201. { include: "@constant" },
  202. [/=/, "operators"],
  203. [/;/, "delimiter"],
  204. [
  205. "(map)(s*)(<)",
  206. ["keyword", "white", { token: "@brackets", bracket: "@open", next: "@map.$S2" }]
  207. ],
  208. [
  209. /@identifier/,
  210. {
  211. cases: {
  212. option: { token: "keyword", next: "@option.$S2" },
  213. enum: { token: "keyword", next: "@enumDecl.$S2" },
  214. message: { token: "keyword", next: "@messageDecl.$S2" },
  215. oneof: { token: "keyword", next: "@oneofDecl.$S2" },
  216. extensions: {
  217. cases: {
  218. "$S2==proto2": { token: "keyword", next: "@reserved.$S2" }
  219. }
  220. },
  221. reserved: { token: "keyword", next: "@reserved.$S2" },
  222. "(?:repeated|optional)": { token: "keyword", next: "@field.$S2" },
  223. required: {
  224. cases: {
  225. "$S2==proto2": { token: "keyword", next: "@field.$S2" }
  226. }
  227. },
  228. "$S2==proto3": { token: "@rematch", next: "@field.$S2" }
  229. }
  230. }
  231. ],
  232. [/\[/, { token: "@brackets", bracket: "@open", next: "@options.$S2" }],
  233. [/}/, { token: "@brackets", bracket: "@close", next: "@pop" }]
  234. ],
  235. extendDecl: [
  236. { include: "@whitespace" },
  237. [/@identifier/, "type.identifier"],
  238. [/{/, { token: "@brackets", bracket: "@open", switchTo: "@extendBody.$S2" }]
  239. ],
  240. extendBody: [
  241. { include: "@whitespace" },
  242. { include: "@constant" },
  243. [/;/, "delimiter"],
  244. [/(?:repeated|optional|required)/, "keyword", "@field.$S2"],
  245. [/\[/, { token: "@brackets", bracket: "@open", next: "@options.$S2" }],
  246. [/}/, { token: "@brackets", bracket: "@close", next: "@pop" }]
  247. ],
  248. options: [
  249. { include: "@whitespace" },
  250. { include: "@constant" },
  251. [/;/, "delimiter"],
  252. [/@optionName/, "annotation"],
  253. [/[()]/, "annotation.brackets"],
  254. [/=/, "operator"],
  255. [/\]/, { token: "@brackets", bracket: "@close", next: "@pop" }]
  256. ],
  257. option: [
  258. { include: "@whitespace" },
  259. [/@optionName/, "annotation"],
  260. [/[()]/, "annotation.brackets"],
  261. [/=/, "operator", "@pop"]
  262. ],
  263. oneofDecl: [
  264. { include: "@whitespace" },
  265. [/@identifier/, "identifier"],
  266. [/{/, { token: "@brackets", bracket: "@open", switchTo: "@oneofBody.$S2" }]
  267. ],
  268. oneofBody: [
  269. { include: "@whitespace" },
  270. { include: "@constant" },
  271. [/;/, "delimiter"],
  272. [/(@identifier)(\s*)(=)/, ["identifier", "white", "delimiter"]],
  273. [
  274. /@fullIdentifier|\./,
  275. {
  276. cases: {
  277. "@builtinTypes": "keyword",
  278. "@default": "type.identifier"
  279. }
  280. }
  281. ],
  282. [/\[/, { token: "@brackets", bracket: "@open", next: "@options.$S2" }],
  283. [/}/, { token: "@brackets", bracket: "@close", next: "@pop" }]
  284. ],
  285. reserved: [
  286. { include: "@whitespace" },
  287. [/,/, "delimiter"],
  288. [/;/, "delimiter", "@pop"],
  289. { include: "@constant" },
  290. [/to\b|max\b/, "keyword"]
  291. ],
  292. map: [
  293. { include: "@whitespace" },
  294. [
  295. /@fullIdentifier|\./,
  296. {
  297. cases: {
  298. "@builtinTypes": "keyword",
  299. "@default": "type.identifier"
  300. }
  301. }
  302. ],
  303. [/,/, "delimiter"],
  304. [/>/, { token: "@brackets", bracket: "@close", switchTo: "identifier" }]
  305. ],
  306. field: [
  307. { include: "@whitespace" },
  308. [
  309. "group",
  310. {
  311. cases: {
  312. "$S2==proto2": { token: "keyword", switchTo: "@groupDecl.$S2" }
  313. }
  314. }
  315. ],
  316. [/(@identifier)(\s*)(=)/, ["identifier", "white", { token: "delimiter", next: "@pop" }]],
  317. [
  318. /@fullIdentifier|\./,
  319. {
  320. cases: {
  321. "@builtinTypes": "keyword",
  322. "@default": "type.identifier"
  323. }
  324. }
  325. ]
  326. ],
  327. groupDecl: [
  328. { include: "@whitespace" },
  329. [/@identifier/, "identifier"],
  330. ["=", "operator"],
  331. [/{/, { token: "@brackets", bracket: "@open", switchTo: "@messageBody.$S2" }],
  332. { include: "@constant" }
  333. ],
  334. type: [
  335. { include: "@whitespace" },
  336. [/@identifier/, "type.identifier", "@pop"],
  337. [/./, "delimiter"]
  338. ],
  339. identifier: [{ include: "@whitespace" }, [/@identifier/, "identifier", "@pop"]],
  340. serviceDecl: [
  341. { include: "@whitespace" },
  342. [/@identifier/, "identifier"],
  343. [/{/, { token: "@brackets", bracket: "@open", switchTo: "@serviceBody.$S2" }]
  344. ],
  345. serviceBody: [
  346. { include: "@whitespace" },
  347. { include: "@constant" },
  348. [/;/, "delimiter"],
  349. [/option\b/, "keyword", "@option.$S2"],
  350. [/rpc\b/, "keyword", "@rpc.$S2"],
  351. [/\[/, { token: "@brackets", bracket: "@open", next: "@options.$S2" }],
  352. [/}/, { token: "@brackets", bracket: "@close", next: "@pop" }]
  353. ],
  354. rpc: [
  355. { include: "@whitespace" },
  356. [/@identifier/, "identifier"],
  357. [/\(/, { token: "@brackets", bracket: "@open", switchTo: "@request.$S2" }],
  358. [/{/, { token: "@brackets", bracket: "@open", next: "@methodOptions.$S2" }],
  359. [/;/, "delimiter", "@pop"]
  360. ],
  361. request: [
  362. { include: "@whitespace" },
  363. [
  364. /@messageType/,
  365. {
  366. cases: {
  367. stream: { token: "keyword", next: "@type.$S2" },
  368. "@default": "type.identifier"
  369. }
  370. }
  371. ],
  372. [/\)/, { token: "@brackets", bracket: "@close", switchTo: "@returns.$S2" }]
  373. ],
  374. returns: [
  375. { include: "@whitespace" },
  376. [/returns\b/, "keyword"],
  377. [/\(/, { token: "@brackets", bracket: "@open", switchTo: "@response.$S2" }]
  378. ],
  379. response: [
  380. { include: "@whitespace" },
  381. [
  382. /@messageType/,
  383. {
  384. cases: {
  385. stream: { token: "keyword", next: "@type.$S2" },
  386. "@default": "type.identifier"
  387. }
  388. }
  389. ],
  390. [/\)/, { token: "@brackets", bracket: "@close", switchTo: "@rpc.$S2" }]
  391. ],
  392. methodOptions: [
  393. { include: "@whitespace" },
  394. { include: "@constant" },
  395. [/;/, "delimiter"],
  396. ["option", "keyword"],
  397. [/@optionName/, "annotation"],
  398. [/[()]/, "annotation.brackets"],
  399. [/=/, "operator"],
  400. [/}/, { token: "@brackets", bracket: "@close", next: "@pop" }]
  401. ],
  402. comment: [
  403. [/[^\/*]+/, "comment"],
  404. [/\/\*/, "comment", "@push"],
  405. ["\\*/", "comment", "@pop"],
  406. [/[\/*]/, "comment"]
  407. ],
  408. string: [
  409. [/[^\\"]+/, "string"],
  410. [/@escapes/, "string.escape"],
  411. [/\\./, "string.escape.invalid"],
  412. [/"/, { token: "string.quote", bracket: "@close", next: "@pop" }]
  413. ],
  414. stringSingle: [
  415. [/[^\\']+/, "string"],
  416. [/@escapes/, "string.escape"],
  417. [/\\./, "string.escape.invalid"],
  418. [/'/, { token: "string.quote", bracket: "@close", next: "@pop" }]
  419. ],
  420. constant: [
  421. ["@boolLit", "keyword.constant"],
  422. ["@hexLit", "number.hex"],
  423. ["@octalLit", "number.octal"],
  424. ["@decimalLit", "number"],
  425. ["@floatLit", "number.float"],
  426. [/("([^"\\]|\\.)*|'([^'\\]|\\.)*)$/, "string.invalid"],
  427. [/"/, { token: "string.quote", bracket: "@open", next: "@string" }],
  428. [/'/, { token: "string.quote", bracket: "@open", next: "@stringSingle" }],
  429. [/{/, { token: "@brackets", bracket: "@open", next: "@prototext" }],
  430. [/identifier/, "identifier"]
  431. ],
  432. whitespace: [
  433. [/[ \t\r\n]+/, "white"],
  434. [/\/\*/, "comment", "@comment"],
  435. [/\/\/.*$/, "comment"]
  436. ],
  437. prototext: [
  438. { include: "@whitespace" },
  439. { include: "@constant" },
  440. [/@identifier/, "identifier"],
  441. [/[:;]/, "delimiter"],
  442. [/}/, { token: "@brackets", bracket: "@close", next: "@pop" }]
  443. ]
  444. }
  445. };
  446. return __toCommonJS(protobuf_exports);
  447. })();
  448. return moduleExports;
  449. });