protobuf.js 14 KB

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