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