Debian Codegraph @

codemirror-legacy-modes/mode/protobuf.js

raw
1 function wordRegexp(words) {
2 return new RegExp("^((" + words.join(")|(") + "))\\b", "i");
3 };
4
5 var keywordArray = [
6 "package", "message", "import", "syntax",
7 "required", "optional", "repeated", "reserved", "default", "extensions", "packed",
8 "bool", "bytes", "double", "enum", "float", "string",
9 "int32", "int64", "uint32", "uint64", "sint32", "sint64", "fixed32", "fixed64", "sfixed32", "sfixed64",
10 "option", "service", "rpc", "returns"
11 ];
12 var keywords = wordRegexp(keywordArray);
13
14 var identifiers = new RegExp("^[_A-Za-z\xa1-\uffff][_A-Za-z0-9\xa1-\uffff]*");
15
16 function tokenBase(stream) {
17 // whitespaces
18 if (stream.eatSpace()) return null;
19
20 // Handle one line Comments
21 if (stream.match("//")) {
22 stream.skipToEnd();
23 return "comment";
24 }
25
26 // Handle Number Literals
27 if (stream.match(/^[0-9\.+-]/, false)) {
28 if (stream.match(/^[+-]?0x[0-9a-fA-F]+/))
29 return "number";
30 if (stream.match(/^[+-]?\d*\.\d+([EeDd][+-]?\d+)?/))
31 return "number";
32 if (stream.match(/^[+-]?\d+([EeDd][+-]?\d+)?/))
33 return "number";
34 }
35
36 // Handle Strings
37 if (stream.match(/^"([^"]|(""))*"/)) { return "string"; }
38 if (stream.match(/^'([^']|(''))*'/)) { return "string"; }
39
40 // Handle words
41 if (stream.match(keywords)) { return "keyword"; }
42 if (stream.match(identifiers)) { return "variable"; } ;
43
44 // Handle non-detected items
45 stream.next();
46 return null;
47 };
48
49 export const protobuf = {
50 name: "protobuf",
51 token: tokenBase,
52 languageData: {
53 autocomplete: keywordArray
54 }
55 }