sas.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. Language: SAS
  3. Author: Mauricio Caceres <mauricio.caceres.bravo@gmail.com>
  4. Description: Syntax Highlighting for SAS
  5. */
  6. function sas(hljs) {
  7. // Data step and PROC SQL statements
  8. const SAS_KEYWORDS =
  9. 'do if then else end until while ' +
  10. '' +
  11. 'abort array attrib by call cards cards4 catname continue ' +
  12. 'datalines datalines4 delete delim delimiter display dm drop ' +
  13. 'endsas error file filename footnote format goto in infile ' +
  14. 'informat input keep label leave length libname link list ' +
  15. 'lostcard merge missing modify options output out page put ' +
  16. 'redirect remove rename replace retain return select set skip ' +
  17. 'startsas stop title update waitsas where window x systask ' +
  18. '' +
  19. 'add and alter as cascade check create delete describe ' +
  20. 'distinct drop foreign from group having index insert into in ' +
  21. 'key like message modify msgtype not null on or order primary ' +
  22. 'references reset restrict select set table unique update ' +
  23. 'validate view where';
  24. // Built-in SAS functions
  25. const SAS_FUN =
  26. 'abs|addr|airy|arcos|arsin|atan|attrc|attrn|band|' +
  27. 'betainv|blshift|bnot|bor|brshift|bxor|byte|cdf|ceil|' +
  28. 'cexist|cinv|close|cnonct|collate|compbl|compound|' +
  29. 'compress|cos|cosh|css|curobs|cv|daccdb|daccdbsl|' +
  30. 'daccsl|daccsyd|dacctab|dairy|date|datejul|datepart|' +
  31. 'datetime|day|dclose|depdb|depdbsl|depdbsl|depsl|' +
  32. 'depsl|depsyd|depsyd|deptab|deptab|dequote|dhms|dif|' +
  33. 'digamma|dim|dinfo|dnum|dopen|doptname|doptnum|dread|' +
  34. 'dropnote|dsname|erf|erfc|exist|exp|fappend|fclose|' +
  35. 'fcol|fdelete|fetch|fetchobs|fexist|fget|fileexist|' +
  36. 'filename|fileref|finfo|finv|fipname|fipnamel|' +
  37. 'fipstate|floor|fnonct|fnote|fopen|foptname|foptnum|' +
  38. 'fpoint|fpos|fput|fread|frewind|frlen|fsep|fuzz|' +
  39. 'fwrite|gaminv|gamma|getoption|getvarc|getvarn|hbound|' +
  40. 'hms|hosthelp|hour|ibessel|index|indexc|indexw|input|' +
  41. 'inputc|inputn|int|intck|intnx|intrr|irr|jbessel|' +
  42. 'juldate|kurtosis|lag|lbound|left|length|lgamma|' +
  43. 'libname|libref|log|log10|log2|logpdf|logpmf|logsdf|' +
  44. 'lowcase|max|mdy|mean|min|minute|mod|month|mopen|' +
  45. 'mort|n|netpv|nmiss|normal|note|npv|open|ordinal|' +
  46. 'pathname|pdf|peek|peekc|pmf|point|poisson|poke|' +
  47. 'probbeta|probbnml|probchi|probf|probgam|probhypr|' +
  48. 'probit|probnegb|probnorm|probt|put|putc|putn|qtr|' +
  49. 'quote|ranbin|rancau|ranexp|rangam|range|rank|rannor|' +
  50. 'ranpoi|rantbl|rantri|ranuni|repeat|resolve|reverse|' +
  51. 'rewind|right|round|saving|scan|sdf|second|sign|' +
  52. 'sin|sinh|skewness|soundex|spedis|sqrt|std|stderr|' +
  53. 'stfips|stname|stnamel|substr|sum|symget|sysget|' +
  54. 'sysmsg|sysprod|sysrc|system|tan|tanh|time|timepart|' +
  55. 'tinv|tnonct|today|translate|tranwrd|trigamma|' +
  56. 'trim|trimn|trunc|uniform|upcase|uss|var|varfmt|' +
  57. 'varinfmt|varlabel|varlen|varname|varnum|varray|' +
  58. 'varrayx|vartype|verify|vformat|vformatd|vformatdx|' +
  59. 'vformatn|vformatnx|vformatw|vformatwx|vformatx|' +
  60. 'vinarray|vinarrayx|vinformat|vinformatd|vinformatdx|' +
  61. 'vinformatn|vinformatnx|vinformatw|vinformatwx|' +
  62. 'vinformatx|vlabel|vlabelx|vlength|vlengthx|vname|' +
  63. 'vnamex|vtype|vtypex|weekday|year|yyq|zipfips|zipname|' +
  64. 'zipnamel|zipstate';
  65. // Built-in macro functions
  66. const SAS_MACRO_FUN =
  67. 'bquote|nrbquote|cmpres|qcmpres|compstor|' +
  68. 'datatyp|display|do|else|end|eval|global|goto|' +
  69. 'if|index|input|keydef|label|left|length|let|' +
  70. 'local|lowcase|macro|mend|nrbquote|nrquote|' +
  71. 'nrstr|put|qcmpres|qleft|qlowcase|qscan|' +
  72. 'qsubstr|qsysfunc|qtrim|quote|qupcase|scan|str|' +
  73. 'substr|superq|syscall|sysevalf|sysexec|sysfunc|' +
  74. 'sysget|syslput|sysprod|sysrc|sysrput|then|to|' +
  75. 'trim|unquote|until|upcase|verify|while|window';
  76. return {
  77. name: 'SAS',
  78. case_insensitive: true, // SAS is case-insensitive
  79. keywords: {
  80. literal:
  81. 'null missing _all_ _automatic_ _character_ _infile_ ' +
  82. '_n_ _name_ _null_ _numeric_ _user_ _webout_',
  83. meta:
  84. SAS_KEYWORDS
  85. },
  86. contains: [
  87. {
  88. // Distinct highlight for proc <proc>, data, run, quit
  89. className: 'keyword',
  90. begin: /^\s*(proc [\w\d_]+|data|run|quit)[\s;]/
  91. },
  92. {
  93. // Macro variables
  94. className: 'variable',
  95. begin: /&[a-zA-Z_&][a-zA-Z0-9_]*\.?/
  96. },
  97. {
  98. // Special emphasis for datalines|cards
  99. className: 'emphasis',
  100. begin: /^\s*datalines|cards.*;/,
  101. end: /^\s*;\s*$/
  102. },
  103. { // Built-in macro variables take precedence
  104. className: 'built_in',
  105. begin: '%(' + SAS_MACRO_FUN + ')'
  106. },
  107. {
  108. // User-defined macro functions highlighted after
  109. className: 'name',
  110. begin: /%[a-zA-Z_][a-zA-Z_0-9]*/
  111. },
  112. {
  113. className: 'meta',
  114. begin: '[^%](' + SAS_FUN + ')[\(]'
  115. },
  116. {
  117. className: 'string',
  118. variants: [
  119. hljs.APOS_STRING_MODE,
  120. hljs.QUOTE_STRING_MODE
  121. ]
  122. },
  123. hljs.COMMENT('\\*', ';'),
  124. hljs.C_BLOCK_COMMENT_MODE
  125. ]
  126. };
  127. }
  128. module.exports = sas;