1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | function sas(hljs) {
|
9 | const regex = hljs.regex;
|
10 |
|
11 | const SAS_KEYWORDS = [
|
12 | "do",
|
13 | "if",
|
14 | "then",
|
15 | "else",
|
16 | "end",
|
17 | "until",
|
18 | "while",
|
19 | "abort",
|
20 | "array",
|
21 | "attrib",
|
22 | "by",
|
23 | "call",
|
24 | "cards",
|
25 | "cards4",
|
26 | "catname",
|
27 | "continue",
|
28 | "datalines",
|
29 | "datalines4",
|
30 | "delete",
|
31 | "delim",
|
32 | "delimiter",
|
33 | "display",
|
34 | "dm",
|
35 | "drop",
|
36 | "endsas",
|
37 | "error",
|
38 | "file",
|
39 | "filename",
|
40 | "footnote",
|
41 | "format",
|
42 | "goto",
|
43 | "in",
|
44 | "infile",
|
45 | "informat",
|
46 | "input",
|
47 | "keep",
|
48 | "label",
|
49 | "leave",
|
50 | "length",
|
51 | "libname",
|
52 | "link",
|
53 | "list",
|
54 | "lostcard",
|
55 | "merge",
|
56 | "missing",
|
57 | "modify",
|
58 | "options",
|
59 | "output",
|
60 | "out",
|
61 | "page",
|
62 | "put",
|
63 | "redirect",
|
64 | "remove",
|
65 | "rename",
|
66 | "replace",
|
67 | "retain",
|
68 | "return",
|
69 | "select",
|
70 | "set",
|
71 | "skip",
|
72 | "startsas",
|
73 | "stop",
|
74 | "title",
|
75 | "update",
|
76 | "waitsas",
|
77 | "where",
|
78 | "window",
|
79 | "x|0",
|
80 | "systask",
|
81 | "add",
|
82 | "and",
|
83 | "alter",
|
84 | "as",
|
85 | "cascade",
|
86 | "check",
|
87 | "create",
|
88 | "delete",
|
89 | "describe",
|
90 | "distinct",
|
91 | "drop",
|
92 | "foreign",
|
93 | "from",
|
94 | "group",
|
95 | "having",
|
96 | "index",
|
97 | "insert",
|
98 | "into",
|
99 | "in",
|
100 | "key",
|
101 | "like",
|
102 | "message",
|
103 | "modify",
|
104 | "msgtype",
|
105 | "not",
|
106 | "null",
|
107 | "on",
|
108 | "or",
|
109 | "order",
|
110 | "primary",
|
111 | "references",
|
112 | "reset",
|
113 | "restrict",
|
114 | "select",
|
115 | "set",
|
116 | "table",
|
117 | "unique",
|
118 | "update",
|
119 | "validate",
|
120 | "view",
|
121 | "where"
|
122 | ];
|
123 |
|
124 |
|
125 | const FUNCTIONS = [
|
126 | "abs",
|
127 | "addr",
|
128 | "airy",
|
129 | "arcos",
|
130 | "arsin",
|
131 | "atan",
|
132 | "attrc",
|
133 | "attrn",
|
134 | "band",
|
135 | "betainv",
|
136 | "blshift",
|
137 | "bnot",
|
138 | "bor",
|
139 | "brshift",
|
140 | "bxor",
|
141 | "byte",
|
142 | "cdf",
|
143 | "ceil",
|
144 | "cexist",
|
145 | "cinv",
|
146 | "close",
|
147 | "cnonct",
|
148 | "collate",
|
149 | "compbl",
|
150 | "compound",
|
151 | "compress",
|
152 | "cos",
|
153 | "cosh",
|
154 | "css",
|
155 | "curobs",
|
156 | "cv",
|
157 | "daccdb",
|
158 | "daccdbsl",
|
159 | "daccsl",
|
160 | "daccsyd",
|
161 | "dacctab",
|
162 | "dairy",
|
163 | "date",
|
164 | "datejul",
|
165 | "datepart",
|
166 | "datetime",
|
167 | "day",
|
168 | "dclose",
|
169 | "depdb",
|
170 | "depdbsl",
|
171 | "depdbsl",
|
172 | "depsl",
|
173 | "depsl",
|
174 | "depsyd",
|
175 | "depsyd",
|
176 | "deptab",
|
177 | "deptab",
|
178 | "dequote",
|
179 | "dhms",
|
180 | "dif",
|
181 | "digamma",
|
182 | "dim",
|
183 | "dinfo",
|
184 | "dnum",
|
185 | "dopen",
|
186 | "doptname",
|
187 | "doptnum",
|
188 | "dread",
|
189 | "dropnote",
|
190 | "dsname",
|
191 | "erf",
|
192 | "erfc",
|
193 | "exist",
|
194 | "exp",
|
195 | "fappend",
|
196 | "fclose",
|
197 | "fcol",
|
198 | "fdelete",
|
199 | "fetch",
|
200 | "fetchobs",
|
201 | "fexist",
|
202 | "fget",
|
203 | "fileexist",
|
204 | "filename",
|
205 | "fileref",
|
206 | "finfo",
|
207 | "finv",
|
208 | "fipname",
|
209 | "fipnamel",
|
210 | "fipstate",
|
211 | "floor",
|
212 | "fnonct",
|
213 | "fnote",
|
214 | "fopen",
|
215 | "foptname",
|
216 | "foptnum",
|
217 | "fpoint",
|
218 | "fpos",
|
219 | "fput",
|
220 | "fread",
|
221 | "frewind",
|
222 | "frlen",
|
223 | "fsep",
|
224 | "fuzz",
|
225 | "fwrite",
|
226 | "gaminv",
|
227 | "gamma",
|
228 | "getoption",
|
229 | "getvarc",
|
230 | "getvarn",
|
231 | "hbound",
|
232 | "hms",
|
233 | "hosthelp",
|
234 | "hour",
|
235 | "ibessel",
|
236 | "index",
|
237 | "indexc",
|
238 | "indexw",
|
239 | "input",
|
240 | "inputc",
|
241 | "inputn",
|
242 | "int",
|
243 | "intck",
|
244 | "intnx",
|
245 | "intrr",
|
246 | "irr",
|
247 | "jbessel",
|
248 | "juldate",
|
249 | "kurtosis",
|
250 | "lag",
|
251 | "lbound",
|
252 | "left",
|
253 | "length",
|
254 | "lgamma",
|
255 | "libname",
|
256 | "libref",
|
257 | "log",
|
258 | "log10",
|
259 | "log2",
|
260 | "logpdf",
|
261 | "logpmf",
|
262 | "logsdf",
|
263 | "lowcase",
|
264 | "max",
|
265 | "mdy",
|
266 | "mean",
|
267 | "min",
|
268 | "minute",
|
269 | "mod",
|
270 | "month",
|
271 | "mopen",
|
272 | "mort",
|
273 | "n",
|
274 | "netpv",
|
275 | "nmiss",
|
276 | "normal",
|
277 | "note",
|
278 | "npv",
|
279 | "open",
|
280 | "ordinal",
|
281 | "pathname",
|
282 | "pdf",
|
283 | "peek",
|
284 | "peekc",
|
285 | "pmf",
|
286 | "point",
|
287 | "poisson",
|
288 | "poke",
|
289 | "probbeta",
|
290 | "probbnml",
|
291 | "probchi",
|
292 | "probf",
|
293 | "probgam",
|
294 | "probhypr",
|
295 | "probit",
|
296 | "probnegb",
|
297 | "probnorm",
|
298 | "probt",
|
299 | "put",
|
300 | "putc",
|
301 | "putn",
|
302 | "qtr",
|
303 | "quote",
|
304 | "ranbin",
|
305 | "rancau",
|
306 | "ranexp",
|
307 | "rangam",
|
308 | "range",
|
309 | "rank",
|
310 | "rannor",
|
311 | "ranpoi",
|
312 | "rantbl",
|
313 | "rantri",
|
314 | "ranuni",
|
315 | "repeat",
|
316 | "resolve",
|
317 | "reverse",
|
318 | "rewind",
|
319 | "right",
|
320 | "round",
|
321 | "saving",
|
322 | "scan",
|
323 | "sdf",
|
324 | "second",
|
325 | "sign",
|
326 | "sin",
|
327 | "sinh",
|
328 | "skewness",
|
329 | "soundex",
|
330 | "spedis",
|
331 | "sqrt",
|
332 | "std",
|
333 | "stderr",
|
334 | "stfips",
|
335 | "stname",
|
336 | "stnamel",
|
337 | "substr",
|
338 | "sum",
|
339 | "symget",
|
340 | "sysget",
|
341 | "sysmsg",
|
342 | "sysprod",
|
343 | "sysrc",
|
344 | "system",
|
345 | "tan",
|
346 | "tanh",
|
347 | "time",
|
348 | "timepart",
|
349 | "tinv",
|
350 | "tnonct",
|
351 | "today",
|
352 | "translate",
|
353 | "tranwrd",
|
354 | "trigamma",
|
355 | "trim",
|
356 | "trimn",
|
357 | "trunc",
|
358 | "uniform",
|
359 | "upcase",
|
360 | "uss",
|
361 | "var",
|
362 | "varfmt",
|
363 | "varinfmt",
|
364 | "varlabel",
|
365 | "varlen",
|
366 | "varname",
|
367 | "varnum",
|
368 | "varray",
|
369 | "varrayx",
|
370 | "vartype",
|
371 | "verify",
|
372 | "vformat",
|
373 | "vformatd",
|
374 | "vformatdx",
|
375 | "vformatn",
|
376 | "vformatnx",
|
377 | "vformatw",
|
378 | "vformatwx",
|
379 | "vformatx",
|
380 | "vinarray",
|
381 | "vinarrayx",
|
382 | "vinformat",
|
383 | "vinformatd",
|
384 | "vinformatdx",
|
385 | "vinformatn",
|
386 | "vinformatnx",
|
387 | "vinformatw",
|
388 | "vinformatwx",
|
389 | "vinformatx",
|
390 | "vlabel",
|
391 | "vlabelx",
|
392 | "vlength",
|
393 | "vlengthx",
|
394 | "vname",
|
395 | "vnamex",
|
396 | "vtype",
|
397 | "vtypex",
|
398 | "weekday",
|
399 | "year",
|
400 | "yyq",
|
401 | "zipfips",
|
402 | "zipname",
|
403 | "zipnamel",
|
404 | "zipstate"
|
405 | ];
|
406 |
|
407 |
|
408 | const MACRO_FUNCTIONS = [
|
409 | "bquote",
|
410 | "nrbquote",
|
411 | "cmpres",
|
412 | "qcmpres",
|
413 | "compstor",
|
414 | "datatyp",
|
415 | "display",
|
416 | "do",
|
417 | "else",
|
418 | "end",
|
419 | "eval",
|
420 | "global",
|
421 | "goto",
|
422 | "if",
|
423 | "index",
|
424 | "input",
|
425 | "keydef",
|
426 | "label",
|
427 | "left",
|
428 | "length",
|
429 | "let",
|
430 | "local",
|
431 | "lowcase",
|
432 | "macro",
|
433 | "mend",
|
434 | "nrbquote",
|
435 | "nrquote",
|
436 | "nrstr",
|
437 | "put",
|
438 | "qcmpres",
|
439 | "qleft",
|
440 | "qlowcase",
|
441 | "qscan",
|
442 | "qsubstr",
|
443 | "qsysfunc",
|
444 | "qtrim",
|
445 | "quote",
|
446 | "qupcase",
|
447 | "scan",
|
448 | "str",
|
449 | "substr",
|
450 | "superq",
|
451 | "syscall",
|
452 | "sysevalf",
|
453 | "sysexec",
|
454 | "sysfunc",
|
455 | "sysget",
|
456 | "syslput",
|
457 | "sysprod",
|
458 | "sysrc",
|
459 | "sysrput",
|
460 | "then",
|
461 | "to",
|
462 | "trim",
|
463 | "unquote",
|
464 | "until",
|
465 | "upcase",
|
466 | "verify",
|
467 | "while",
|
468 | "window"
|
469 | ];
|
470 |
|
471 | const LITERALS = [
|
472 | "null",
|
473 | "missing",
|
474 | "_all_",
|
475 | "_automatic_",
|
476 | "_character_",
|
477 | "_infile_",
|
478 | "_n_",
|
479 | "_name_",
|
480 | "_null_",
|
481 | "_numeric_",
|
482 | "_user_",
|
483 | "_webout_"
|
484 | ];
|
485 |
|
486 | return {
|
487 | name: 'SAS',
|
488 | case_insensitive: true,
|
489 | keywords: {
|
490 | literal: LITERALS,
|
491 | keyword: SAS_KEYWORDS
|
492 | },
|
493 | contains: [
|
494 | {
|
495 |
|
496 | className: 'keyword',
|
497 | begin: /^\s*(proc [\w\d_]+|data|run|quit)[\s;]/
|
498 | },
|
499 | {
|
500 |
|
501 | className: 'variable',
|
502 | begin: /&[a-zA-Z_&][a-zA-Z0-9_]*\.?/
|
503 | },
|
504 | {
|
505 | begin: [
|
506 | /^\s*/,
|
507 | /datalines;|cards;/,
|
508 | /(?:.*\n)+/,
|
509 | /^\s*;\s*$/
|
510 | ],
|
511 | className: {
|
512 | 2: "keyword",
|
513 | 3: "string"
|
514 | }
|
515 | },
|
516 | {
|
517 | begin: [
|
518 | /%mend|%macro/,
|
519 | /\s+/,
|
520 | /[a-zA-Z_&][a-zA-Z0-9_]*/
|
521 | ],
|
522 | className: {
|
523 | 1: "built_in",
|
524 | 3: "title.function"
|
525 | }
|
526 | },
|
527 | {
|
528 | className: 'built_in',
|
529 | begin: '%' + regex.either(...MACRO_FUNCTIONS)
|
530 | },
|
531 | {
|
532 |
|
533 | className: 'title.function',
|
534 | begin: /%[a-zA-Z_][a-zA-Z_0-9]*/
|
535 | },
|
536 | {
|
537 |
|
538 |
|
539 |
|
540 | className: 'meta',
|
541 | begin: regex.either(...FUNCTIONS) + '(?=\\()'
|
542 | },
|
543 | {
|
544 | className: 'string',
|
545 | variants: [
|
546 | hljs.APOS_STRING_MODE,
|
547 | hljs.QUOTE_STRING_MODE
|
548 | ]
|
549 | },
|
550 | hljs.COMMENT('\\*', ';'),
|
551 | hljs.C_BLOCK_COMMENT_MODE
|
552 | ]
|
553 | };
|
554 | }
|
555 |
|
556 | export { sas as default };
|