sas.js 8.1 KB

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