sas.js 5.5 KB

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