halstead-metrics 0.0.0-stage → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,448 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * One classifier for every language. Keywords and the shared operator list
5
+ * are operators. Comments and C-family preprocessor lines are not tokens.
6
+ */
7
+
8
+ const OPERATORS = [
9
+ ">>>=", ">>=", "<<=", "...", "..=",
10
+ "||=", "&&=", "??=", "**=", "//=",
11
+ "===", "!==", "==", "!=", "<=", ">=",
12
+ "=>", "->", "<-", "::", "|>",
13
+ "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "~=",
14
+ "++", "--", "&&", "||", "??", "?.", "..",
15
+ "<<", ">>", "**", "//",
16
+ ":=", "=~", "!~",
17
+ "+", "-", "*", "/", "%", "&", "|", "^", "~", "!", "=",
18
+ "<", ">", "?", ":", ".", ",", ";", "@",
19
+ ];
20
+
21
+ const C_STYLE = { lineComments: ["//"], blockComments: [["/*", "*/"]] };
22
+ const HASH = { lineComments: ["#"], blockComments: [] };
23
+ const PHP_STYLE = { lineComments: ["//", "#"], blockComments: [["/*", "*/"]] };
24
+ const SQL_STYLE = { lineComments: ["--"], blockComments: [["/*", "*/"]] };
25
+ const LUA_STYLE = { lineComments: ["--"], blockComments: [["--[[", "]]"]] };
26
+ const HASKELL_STYLE = { lineComments: ["--"], blockComments: [["{-", "-}"]] };
27
+ const ML_STYLE = { lineComments: [], blockComments: [["(*", "*)"]] };
28
+ const POWERSHELL_STYLE = { lineComments: ["#"], blockComments: [["<#", "#>"]] };
29
+
30
+ /**
31
+ * @param {string} id
32
+ * @param {string[]} extensions
33
+ * @param {string[]} keywords
34
+ * @param {{lineComments: string[], blockComments: string[][]}} comments
35
+ * @param {object} [options]
36
+ */
37
+ function define(id, extensions, keywords, comments, options) {
38
+ const settings = options || {};
39
+ const folded = Boolean(settings.caseInsensitive);
40
+ const words = folded ? keywords.map((word) => word.toLowerCase()) : keywords;
41
+ return {
42
+ id: id,
43
+ extensions: extensions,
44
+ keywords: new Set(words),
45
+ lineComments: comments.lineComments,
46
+ blockComments: comments.blockComments,
47
+ caseInsensitive: folded,
48
+ prefixedStrings: Boolean(settings.prefixedStrings),
49
+ dollar: Boolean(settings.dollar),
50
+ atPrefix: Boolean(settings.atPrefix),
51
+ identSuffix: settings.identSuffix || "",
52
+ identPartExtra: settings.identPartExtra || "",
53
+ hyphenIdent: Boolean(settings.hyphenIdent),
54
+ lifetimes: Boolean(settings.lifetimes),
55
+ verbatimAt: Boolean(settings.verbatimAt),
56
+ rustRaw: id === "rust",
57
+ preprocessor: Boolean(settings.preprocessor),
58
+ operators: OPERATORS,
59
+ };
60
+ }
61
+
62
+ const JAVA_KEYWORDS = [
63
+ "abstract", "continue", "for", "new", "switch", "assert", "default", "goto",
64
+ "package", "synchronized", "boolean", "do", "if", "private", "this", "break",
65
+ "double", "implements", "protected", "throw", "byte", "else", "import", "public",
66
+ "throws", "case", "enum", "instanceof", "return", "transient", "catch", "extends",
67
+ "int", "short", "try", "char", "final", "interface", "static", "void", "class",
68
+ "finally", "long", "strictfp", "volatile", "const", "float", "native", "super",
69
+ "while",
70
+ ];
71
+
72
+ const C_KEYWORDS = [
73
+ "auto", "break", "case", "char", "const", "continue", "default", "do",
74
+ "double", "else", "enum", "extern", "float", "for", "goto", "if", "int",
75
+ "long", "register", "return", "short", "signed", "sizeof", "static", "struct",
76
+ "switch", "typedef", "union", "unsigned", "void", "volatile", "while",
77
+ ];
78
+
79
+ const CPP_KEYWORDS = [
80
+ "auto", "break", "case", "char", "const", "continue", "default", "do",
81
+ "double", "else", "enum", "extern", "float", "for", "goto", "if", "int",
82
+ "long", "register", "return", "short", "signed", "sizeof", "static", "struct",
83
+ "switch", "typedef", "union", "unsigned", "void", "volatile", "while", "asm",
84
+ "dynamic_cast", "namespace", "reinterpret_cast", "try", "bool", "explicit",
85
+ "new", "static_cast", "typeid", "catch", "false", "operator", "template",
86
+ "typename", "class", "friend", "private", "this", "using", "const_cast",
87
+ "inline", "public", "throw", "virtual", "delete", "mutable", "protected",
88
+ "true", "wchar_t", "and", "bitand", "compl", "not_eq", "or_eq", "xor_eq",
89
+ "and_eq", "bitor", "not", "or", "xor",
90
+ ];
91
+
92
+ const LANGUAGES = [
93
+ define("java", ["java"], JAVA_KEYWORDS, C_STYLE),
94
+ define("c", ["c", "h"], C_KEYWORDS, C_STYLE, { preprocessor: true }),
95
+ define("cpp", ["cpp", "cc", "cxx", "c++", "hpp", "hh", "hxx"], CPP_KEYWORDS, C_STYLE, { preprocessor: true }),
96
+ define("javascript", ["js", "mjs", "cjs", "jsx"], [
97
+ "break", "case", "catch", "class", "const", "continue", "debugger", "default",
98
+ "delete", "do", "else", "export", "extends", "false", "finally", "for", "function",
99
+ "if", "import", "in", "instanceof", "new", "null", "return", "super", "switch",
100
+ "this", "throw", "true", "try", "typeof", "var", "void", "while", "with", "yield",
101
+ "await", "let", "static", "enum", "of",
102
+ ], C_STYLE, { dollar: true }),
103
+ define("typescript", ["ts", "tsx", "mts", "cts"], [
104
+ "break", "case", "catch", "class", "const", "continue", "debugger", "default",
105
+ "delete", "do", "else", "export", "extends", "false", "finally", "for", "function",
106
+ "if", "import", "in", "instanceof", "new", "null", "return", "super", "switch",
107
+ "this", "throw", "true", "try", "typeof", "var", "void", "while", "with", "yield",
108
+ "await", "let", "static", "enum", "of", "type", "interface", "implements",
109
+ "namespace", "abstract", "readonly", "declare", "keyof", "unique", "is", "asserts",
110
+ "override", "public", "private", "protected", "as", "infer", "never", "unknown", "any",
111
+ ], C_STYLE, { dollar: true }),
112
+ define("python", ["py", "pyw", "pyi"], [
113
+ "False", "None", "True", "and", "as", "assert", "async", "await", "break", "class",
114
+ "continue", "def", "del", "elif", "else", "except", "finally", "for", "from",
115
+ "global", "if", "import", "in", "is", "lambda", "nonlocal", "not", "or", "pass",
116
+ "raise", "return", "try", "while", "with", "yield",
117
+ ], HASH, { prefixedStrings: true }),
118
+ define("csharp", ["cs"], [
119
+ "abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char", "checked",
120
+ "class", "const", "continue", "decimal", "default", "delegate", "do", "double", "else",
121
+ "enum", "event", "explicit", "extern", "false", "finally", "fixed", "float", "for",
122
+ "foreach", "goto", "if", "implicit", "in", "int", "interface", "internal", "is", "lock",
123
+ "long", "namespace", "new", "null", "object", "operator", "out", "override", "params",
124
+ "private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed",
125
+ "short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this", "throw",
126
+ "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using",
127
+ "virtual", "void", "volatile", "while", "add", "alias", "ascending", "async", "await",
128
+ "by", "descending", "dynamic", "equals", "from", "get", "global", "group", "init",
129
+ "into", "join", "let", "nameof", "notnull", "on", "orderby", "partial", "record",
130
+ "remove", "required", "select", "set", "unmanaged", "value", "var", "when", "where",
131
+ "with", "yield",
132
+ ], C_STYLE, { verbatimAt: true }),
133
+ define("go", ["go"], [
134
+ "break", "default", "func", "interface", "select", "case", "defer", "go", "map",
135
+ "struct", "chan", "else", "goto", "package", "switch", "const", "fallthrough", "if",
136
+ "range", "type", "continue", "for", "import", "return", "var",
137
+ ], C_STYLE),
138
+ define("rust", ["rs"], [
139
+ "as", "async", "await", "break", "const", "continue", "crate", "dyn", "else", "enum",
140
+ "extern", "false", "fn", "for", "if", "impl", "in", "let", "loop", "match", "mod",
141
+ "move", "mut", "pub", "ref", "return", "self", "Self", "static", "struct", "super",
142
+ "trait", "true", "type", "unsafe", "use", "where", "while",
143
+ ], C_STYLE, { lifetimes: true }),
144
+ define("php", ["php"], [
145
+ "abstract", "and", "array", "as", "break", "callable", "case", "catch", "class", "clone",
146
+ "const", "continue", "declare", "default", "die", "do", "echo", "else", "elseif", "empty",
147
+ "enddeclare", "endfor", "endforeach", "endif", "endswitch", "endwhile", "eval", "exit",
148
+ "extends", "final", "finally", "fn", "for", "foreach", "function", "global", "goto", "if",
149
+ "implements", "include", "include_once", "instanceof", "insteadof", "interface", "isset",
150
+ "list", "match", "namespace", "new", "or", "print", "private", "protected", "public",
151
+ "require", "require_once", "return", "static", "switch", "throw", "trait", "try", "unset",
152
+ "use", "var", "while", "xor", "yield", "true", "false", "null",
153
+ ], PHP_STYLE, { dollar: true, caseInsensitive: true }),
154
+ define("ruby", ["rb"], [
155
+ "BEGIN", "END", "alias", "and", "begin", "break", "case", "class", "def", "defined?",
156
+ "do", "else", "elsif", "end", "ensure", "false", "for", "if", "in", "module", "next",
157
+ "nil", "not", "or", "redo", "rescue", "retry", "return", "self", "super", "then", "true",
158
+ "undef", "unless", "until", "when", "while", "yield",
159
+ ], HASH, { atPrefix: true, identSuffix: "?!" }),
160
+ define("kotlin", ["kt", "kts"], [
161
+ "as", "break", "class", "continue", "do", "else", "false", "for", "fun", "if", "in",
162
+ "interface", "is", "null", "object", "package", "return", "super", "this", "throw",
163
+ "true", "try", "typealias", "typeof", "val", "var", "when", "while", "by", "catch",
164
+ "constructor", "delegate", "dynamic", "field", "file", "finally", "get", "import",
165
+ "init", "param", "property", "receiver", "set", "setparam", "where", "actual", "abstract",
166
+ "annotation", "companion", "const", "crossinline", "data", "enum", "expect", "external",
167
+ "final", "infix", "inline", "inner", "internal", "lateinit", "noinline", "open",
168
+ "operator", "out", "override", "private", "protected", "public", "reified", "sealed",
169
+ "suspend", "tailrec", "vararg",
170
+ ], C_STYLE),
171
+ define("swift", ["swift"], [
172
+ "associatedtype", "class", "deinit", "enum", "extension", "fileprivate", "func", "import",
173
+ "init", "inout", "internal", "let", "open", "operator", "private", "protocol", "public",
174
+ "rethrows", "static", "struct", "subscript", "typealias", "var", "break", "case",
175
+ "continue", "default", "defer", "do", "else", "fallthrough", "for", "guard", "if", "in",
176
+ "repeat", "return", "switch", "where", "while", "as", "catch", "false", "is", "nil",
177
+ "super", "self", "Self", "throw", "throws", "true", "try",
178
+ ], C_STYLE),
179
+ define("scala", ["scala", "sc"], [
180
+ "abstract", "case", "catch", "class", "def", "do", "else", "extends", "false", "final",
181
+ "finally", "for", "forSome", "if", "implicit", "import", "lazy", "match", "new", "null",
182
+ "object", "override", "package", "private", "protected", "return", "sealed", "super",
183
+ "this", "throw", "trait", "true", "try", "type", "val", "var", "while", "with", "yield",
184
+ ], C_STYLE, { dollar: true }),
185
+ define("dart", ["dart"], [
186
+ "assert", "break", "case", "catch", "class", "const", "continue", "default", "do",
187
+ "else", "enum", "extends", "false", "final", "finally", "for", "if", "in", "is", "new",
188
+ "null", "rethrow", "return", "super", "switch", "this", "throw", "true", "try", "var",
189
+ "void", "while", "with", "async", "await", "yield", "sync", "abstract", "as", "covariant",
190
+ "deferred", "dynamic", "export", "extension", "external", "factory", "get", "implements",
191
+ "import", "interface", "late", "library", "mixin", "on", "operator", "part", "required",
192
+ "set", "show", "static", "typedef",
193
+ ], C_STYLE, { dollar: true }),
194
+ define("sql", ["sql"], [
195
+ "select", "from", "where", "and", "or", "not", "insert", "into", "values", "update",
196
+ "set", "delete", "create", "table", "view", "index", "drop", "alter", "join", "inner",
197
+ "left", "right", "full", "outer", "on", "group", "by", "order", "having", "as",
198
+ "distinct", "union", "all", "limit", "offset", "case", "when", "then", "else", "end",
199
+ "null", "is", "like", "between", "exists", "in", "primary", "key", "foreign",
200
+ "references", "constraint", "default", "unique", "check", "begin", "commit", "rollback",
201
+ "transaction", "grant", "revoke", "with", "recursive", "over", "partition", "row",
202
+ "rows", "range", "fetch", "next", "only", "returning", "procedure", "function",
203
+ "trigger", "declare", "cursor", "open", "close", "loop", "while", "if", "elsif",
204
+ "return", "true", "false", "join",
205
+ ], SQL_STYLE, { caseInsensitive: true }),
206
+ define("shell", ["sh", "bash", "zsh"], [
207
+ "if", "then", "else", "elif", "fi", "case", "esac", "for", "while", "until", "do",
208
+ "done", "in", "function", "select", "time", "coproc",
209
+ ], HASH, { dollar: true }),
210
+ define("powershell", ["ps1", "psm1"], [
211
+ "begin", "break", "catch", "class", "continue", "data", "define", "do", "dynamicparam",
212
+ "else", "elseif", "end", "exit", "filter", "finally", "for", "foreach", "from",
213
+ "function", "if", "in", "param", "process", "return", "switch", "throw", "trap", "try",
214
+ "until", "using", "var", "while",
215
+ ], POWERSHELL_STYLE, { caseInsensitive: true, dollar: true }),
216
+ define("perl", ["pl", "pm"], [
217
+ "if", "elsif", "else", "unless", "while", "until", "for", "foreach", "do", "sub",
218
+ "package", "use", "require", "return", "my", "our", "local", "state", "next", "last",
219
+ "redo", "goto", "given", "when", "default", "and", "or", "not", "xor",
220
+ ], HASH, { dollar: true, atPrefix: true }),
221
+ define("lua", ["lua"], [
222
+ "and", "break", "do", "else", "elseif", "end", "false", "for", "function", "goto", "if",
223
+ "in", "local", "nil", "not", "or", "repeat", "return", "then", "true", "until", "while",
224
+ ], LUA_STYLE),
225
+ define("r", ["r"], [
226
+ "if", "else", "repeat", "while", "function", "for", "in", "next", "break", "TRUE",
227
+ "FALSE", "NULL", "Inf", "NaN", "NA",
228
+ ], HASH),
229
+ define("haskell", ["hs"], [
230
+ "case", "class", "data", "default", "deriving", "do", "else", "forall", "if", "import",
231
+ "in", "infix", "infixl", "infixr", "instance", "let", "module", "newtype", "of",
232
+ "qualified", "then", "type", "where",
233
+ ], HASKELL_STYLE),
234
+ define("elixir", ["ex", "exs"], [
235
+ "alias", "and", "after", "case", "catch", "cond", "def", "defp", "defmacro", "defmacrop",
236
+ "defmodule", "defstruct", "do", "else", "end", "false", "fn", "for", "if", "import",
237
+ "in", "nil", "not", "or", "quote", "raise", "receive", "require", "rescue", "super",
238
+ "throw", "true", "try", "unless", "unquote", "use", "when", "with",
239
+ ], HASH, { atPrefix: true, identSuffix: "?!" }),
240
+ define("erlang", ["erl", "hrl"], [
241
+ "after", "and", "andalso", "band", "begin", "bnot", "bor", "bsl", "bsr", "bxor", "case",
242
+ "catch", "cond", "div", "end", "fun", "if", "let", "not", "of", "or", "orelse",
243
+ "receive", "rem", "try", "when", "xor",
244
+ ], { lineComments: ["%"], blockComments: [] }),
245
+ define("objectivec", ["m", "mm"], [
246
+ "auto", "break", "case", "char", "const", "continue", "default", "do", "double", "else",
247
+ "enum", "extern", "float", "for", "goto", "if", "int", "long", "register", "return",
248
+ "short", "signed", "sizeof", "static", "struct", "switch", "typedef", "union",
249
+ "unsigned", "void", "volatile", "while", "@interface", "@implementation", "@end",
250
+ "@property", "@synthesize", "@dynamic", "@class", "@selector", "@protocol", "@public",
251
+ "@private", "@protected", "@optional", "@required", "@try", "@catch", "@throw",
252
+ "@finally", "@synchronized", "@autoreleasepool", "self", "super", "nil", "YES", "NO",
253
+ "in", "id",
254
+ ], C_STYLE, { atPrefix: true }),
255
+ define("groovy", ["groovy", "gvy"], [
256
+ "abstract", "assert", "break", "case", "catch", "class", "const", "continue", "def",
257
+ "default", "do", "else", "enum", "extends", "final", "finally", "for", "goto", "if",
258
+ "implements", "import", "in", "instanceof", "interface", "native", "new", "package",
259
+ "return", "static", "strictfp", "super", "switch", "synchronized", "this", "throw",
260
+ "throws", "trait", "transient", "try", "var", "volatile", "while", "as", "true", "false",
261
+ "null",
262
+ ], C_STYLE, { dollar: true }),
263
+ define("zig", ["zig"], [
264
+ "addrspace", "align", "allowzero", "and", "anyframe", "anytype", "asm", "async", "await",
265
+ "break", "callconv", "catch", "comptime", "const", "continue", "defer", "else", "enum",
266
+ "errdefer", "error", "export", "extern", "fn", "for", "if", "inline", "noalias",
267
+ "noinline", "nosuspend", "opaque", "or", "orelse", "packed", "pub", "resume", "return",
268
+ "linksection", "struct", "suspend", "switch", "test", "threadlocal", "try", "union",
269
+ "unreachable", "usingnamespace", "var", "volatile", "while",
270
+ ], C_STYLE),
271
+ define("julia", ["jl"], [
272
+ "baremodule", "begin", "break", "catch", "const", "continue", "do", "else", "elseif",
273
+ "end", "export", "false", "finally", "for", "function", "global", "if", "import",
274
+ "let", "local", "macro", "module", "quote", "return", "struct", "true", "try", "using",
275
+ "while", "in", "isa", "where",
276
+ ], HASH),
277
+ define("vb", ["vb"], [
278
+ "addhandler", "addressof", "alias", "and", "andalso", "as", "boolean", "byref", "byte",
279
+ "byval", "call", "case", "catch", "cbool", "cbyte", "cchar", "cdate", "cdbl", "cdec",
280
+ "cint", "class", "clng", "cobj", "const", "continue", "csbyte", "cshort", "csng",
281
+ "cstr", "ctype", "cuint", "culng", "cushort", "date", "decimal", "declare", "default",
282
+ "delegate", "dim", "directcast", "do", "double", "each", "else", "elseif", "end",
283
+ "endif", "enum", "erase", "error", "event", "exit", "false", "finally", "for", "friend",
284
+ "function", "get", "gettype", "getxmlnamespace", "global", "gosub", "goto", "handles",
285
+ "if", "implements", "imports", "in", "inherits", "integer", "interface", "is", "isnot",
286
+ "let", "lib", "like", "long", "loop", "me", "mod", "module", "mustinherit",
287
+ "mustoverride", "mybase", "myclass", "namespace", "narrowing", "new", "next", "not",
288
+ "nothing", "notinheritable", "notoverridable", "object", "of", "on", "operator",
289
+ "option", "optional", "or", "orelse", "overloads", "overridable", "overrides", "paramarray",
290
+ "partial", "private", "property", "protected", "public", "raiseevent", "readonly",
291
+ "redim", "removehandler", "resume", "return", "sbyte", "select", "set", "shadows",
292
+ "shared", "short", "single", "static", "step", "stop", "string", "structure", "sub",
293
+ "synclock", "then", "throw", "to", "true", "try", "trycast", "typeof", "uinteger",
294
+ "ulong", "ushort", "using", "variant", "wend", "when", "while", "widening", "with",
295
+ "withevents", "writeonly", "xor",
296
+ ], { lineComments: ["'"], blockComments: [] }, { caseInsensitive: true }),
297
+ define("fsharp", ["fs", "fsx"], [
298
+ "abstract", "and", "as", "assert", "base", "begin", "class", "default", "delegate", "do",
299
+ "done", "downcast", "downto", "elif", "else", "end", "exception", "extern", "false",
300
+ "finally", "for", "fun", "function", "global", "if", "in", "inherit", "inline",
301
+ "interface", "internal", "lazy", "let", "let!", "match", "member", "module", "mutable",
302
+ "namespace", "new", "null", "of", "open", "or", "override", "private", "public", "rec",
303
+ "return", "return!", "select", "static", "struct", "then", "to", "true", "try", "type",
304
+ "upcast", "use", "use!", "val", "void", "when", "while", "with", "yield", "yield!",
305
+ ], C_STYLE),
306
+ define("clojure", ["clj", "cljs", "cljc"], [
307
+ "def", "defn", "defmacro", "defonce", "ns", "fn", "let", "if", "if-let", "when",
308
+ "when-let", "cond", "case", "loop", "recur", "do", "quote", "var", "try", "catch",
309
+ "finally", "throw", "and", "or", "not", "true", "false", "nil", "deftype", "defrecord",
310
+ "defprotocol", "reify", "for", "doseq", "dotimes",
311
+ ], { lineComments: [";"], blockComments: [] }, { identPartExtra: "*!?+-/" }),
312
+ define("fortran", ["f90", "f95", "f03", "f08"], [
313
+ "program", "end", "subroutine", "function", "module", "use", "implicit", "integer",
314
+ "real", "complex", "character", "logical", "type", "dimension", "parameter", "data",
315
+ "common", "if", "then", "else", "elseif", "endif", "do", "while", "enddo", "continue",
316
+ "cycle", "exit", "goto", "return", "stop", "call", "read", "write", "open", "close",
317
+ "format", "print", "allocate", "deallocate", "nullify", "intent", "optional", "pointer",
318
+ "target", "allocatable", "save", "public", "private", "contains", "interface", "select",
319
+ "case", "where", "forall", "procedure", "result", "recursive", "elemental", "pure",
320
+ "associate", "block", "critical", "enum", "abstract", "import", "only", "none",
321
+ ], { lineComments: ["!"], blockComments: [] }, { caseInsensitive: true }),
322
+ define("solidity", ["sol"], [
323
+ "pragma", "solidity", "contract", "interface", "library", "function", "modifier", "event",
324
+ "error", "struct", "enum", "mapping", "address", "bool", "string", "bytes", "int", "uint",
325
+ "if", "else", "for", "while", "do", "break", "continue", "return", "returns", "emit",
326
+ "try", "catch", "throw", "new", "delete", "public", "private", "internal", "external",
327
+ "pure", "view", "payable", "constant", "immutable", "memory", "storage", "calldata",
328
+ "override", "virtual", "abstract", "is", "using", "assembly", "let", "switch", "case",
329
+ "default", "true", "false",
330
+ ], C_STYLE),
331
+ define("ocaml", ["ml", "mli"], [
332
+ "and", "as", "assert", "asr", "begin", "class", "constraint", "do", "done", "downto",
333
+ "else", "end", "exception", "external", "false", "for", "fun", "function", "functor",
334
+ "if", "in", "include", "inherit", "initializer", "land", "lazy", "let", "lor", "lsl",
335
+ "lsr", "lxor", "match", "method", "mod", "module", "mutable", "new", "nonrec", "object",
336
+ "of", "open", "or", "private", "rec", "sig", "struct", "then", "to", "true", "try",
337
+ "type", "val", "virtual", "when", "while", "with",
338
+ ], ML_STYLE),
339
+ define("pascal", ["pas", "dpr", "pp"], [
340
+ "program", "begin", "end", "if", "then", "else", "while", "do", "for", "to", "downto",
341
+ "repeat", "until", "procedure", "function", "var", "const", "type", "array", "of",
342
+ "record", "case", "with", "uses", "unit", "interface", "implementation", "and", "or",
343
+ "not", "div", "mod", "nil", "true", "false", "string", "integer", "real", "boolean",
344
+ "char", "file", "set", "packed", "goto", "label", "in",
345
+ ], C_STYLE, { caseInsensitive: true }),
346
+ define("ada", ["adb", "ads"], [
347
+ "procedure", "function", "is", "begin", "end", "if", "then", "else", "elsif", "while",
348
+ "loop", "for", "in", "return", "package", "type", "subtype", "record", "array", "of",
349
+ "range", "null", "and", "or", "not", "xor", "abs", "mod", "rem", "new", "with", "use",
350
+ "declare", "exception", "when", "others", "case", "exit", "goto", "raise", "constant",
351
+ "access", "all", "limited", "private", "abstract", "interface", "task", "entry", "accept",
352
+ "select", "delay", "protected", "generic", "body", "out", "reverse",
353
+ ], { lineComments: ["--"], blockComments: [] }, { caseInsensitive: true }),
354
+ define("cobol", ["cbl", "cob", "cobol"], [
355
+ "identification", "division", "program-id", "environment", "data", "procedure",
356
+ "section", "working-storage", "pic", "picture", "perform", "until", "varying", "if",
357
+ "else", "end-if", "evaluate", "when", "move", "to", "add", "subtract", "multiply",
358
+ "divide", "compute", "display", "accept", "stop", "run", "goback", "exit", "call",
359
+ "using", "into", "from", "by", "not", "and", "or", "true", "false",
360
+ ], { lineComments: ["*>"], blockComments: [] }, { caseInsensitive: true, hyphenIdent: true }),
361
+ define("lisp", ["lisp", "lsp", "cl"], [
362
+ "defun", "defmacro", "defvar", "defparameter", "defconstant", "let", "let*", "if",
363
+ "when", "unless", "cond", "case", "lambda", "progn", "setq", "setf", "quote", "function",
364
+ "loop", "do", "dolist", "dotimes", "return", "return-from", "block", "catch", "throw",
365
+ "declare", "and", "or", "not", "t", "nil",
366
+ ], { lineComments: [";"], blockComments: [] }, { identPartExtra: "*!?+-/" }),
367
+ define("scheme", ["scm", "ss"], [
368
+ "define", "lambda", "let", "let*", "letrec", "if", "cond", "case", "and", "or", "not",
369
+ "begin", "do", "delay", "quote", "set!", "define-syntax", "call/cc",
370
+ ], { lineComments: [";"], blockComments: [["#|", "|#"]] }, { identPartExtra: "*!?+-/" }),
371
+ define("awk", ["awk"], [
372
+ "BEGIN", "END", "if", "else", "while", "do", "for", "in", "break", "continue", "next",
373
+ "exit", "return", "function", "delete", "print", "printf",
374
+ ], HASH, { dollar: true }),
375
+ define("nim", ["nim"], [
376
+ "addr", "and", "as", "asm", "bind", "block", "break", "case", "cast", "concept", "const",
377
+ "continue", "converter", "defer", "discard", "distinct", "div", "do", "elif", "else",
378
+ "end", "enum", "except", "export", "finally", "for", "from", "func", "if", "import",
379
+ "in", "include", "interface", "is", "isnot", "iterator", "let", "macro", "method",
380
+ "mixin", "mod", "nil", "not", "notin", "object", "of", "or", "out", "proc", "ptr",
381
+ "raise", "ref", "return", "shl", "shr", "static", "template", "try", "tuple", "type",
382
+ "using", "var", "when", "while", "xor", "yield",
383
+ ], HASH),
384
+ define("d", ["d"], [
385
+ "abstract", "alias", "align", "asm", "assert", "auto", "body", "bool", "break", "byte",
386
+ "case", "cast", "catch", "cdouble", "cent", "cfloat", "char", "class", "const",
387
+ "continue", "creal", "dchar", "debug", "default", "delegate", "delete", "deprecated",
388
+ "do", "double", "else", "enum", "export", "extern", "false", "final", "finally", "float",
389
+ "for", "foreach", "foreach_reverse", "function", "goto", "idouble", "if", "ifloat",
390
+ "immutable", "import", "in", "inout", "int", "interface", "invariant", "ireal", "is",
391
+ "lazy", "long", "macro", "mixin", "module", "new", "nothrow", "null", "out", "override",
392
+ "package", "pragma", "private", "protected", "public", "pure", "real", "ref", "return",
393
+ "scope", "shared", "short", "static", "struct", "super", "switch", "synchronized",
394
+ "template", "this", "throw", "true", "try", "typeid", "typeof", "ubyte", "ucent", "uint",
395
+ "ulong", "union", "unittest", "ushort", "version", "void", "wchar", "while", "with",
396
+ ], C_STYLE),
397
+ define("elm", ["elm"], [
398
+ "if", "then", "else", "case", "of", "let", "in", "type", "alias", "module", "import",
399
+ "exposing", "as", "port", "where",
400
+ ], { lineComments: ["--"], blockComments: [["{-", "-}"]] }),
401
+ define("graphql", ["graphql", "gql"], [
402
+ "query", "mutation", "subscription", "fragment", "on", "type", "interface", "union",
403
+ "enum", "input", "scalar", "schema", "extend", "implements", "directive", "true",
404
+ "false", "null",
405
+ ], HASH),
406
+ ];
407
+
408
+ const BY_EXTENSION = new Map();
409
+ for (let i = 0; i < LANGUAGES.length; i += 1) {
410
+ const language = LANGUAGES[i];
411
+ for (let e = 0; e < language.extensions.length; e += 1) {
412
+ BY_EXTENSION.set(language.extensions[e], language);
413
+ }
414
+ }
415
+
416
+ /**
417
+ * @param {string} extension extension without the leading dot
418
+ * @returns {object|null}
419
+ */
420
+ function getModernLanguage(extension) {
421
+ return BY_EXTENSION.get(String(extension).toLowerCase()) || null;
422
+ }
423
+
424
+ /**
425
+ * Comment and preprocessor rules for the source viewer.
426
+ * @param {string} extension
427
+ */
428
+ function syntaxForExtension(extension) {
429
+ const language = getModernLanguage(extension);
430
+ if (!language) {
431
+ return { lineComments: [], blockComments: [], preprocessor: false };
432
+ }
433
+ return {
434
+ lineComments: language.lineComments,
435
+ blockComments: language.blockComments,
436
+ preprocessor: language.preprocessor,
437
+ };
438
+ }
439
+
440
+ module.exports = {
441
+ OPERATORS,
442
+ JAVA_KEYWORDS,
443
+ C_KEYWORDS,
444
+ CPP_KEYWORDS,
445
+ getModernLanguage,
446
+ syntaxForExtension,
447
+ modernExtensions: Array.from(BY_EXTENSION.keys()),
448
+ };