prism-sas.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. (function (Prism) {
  2. var stringPattern = /(?:"(?:""|[^"])*"(?!")|'(?:''|[^'])*'(?!'))/.source;
  3. var number = /\b(?:\d[\da-f]*x|\d+(?:\.\d+)?(?:e[+-]?\d+)?)\b/i;
  4. var numericConstant = {
  5. pattern: RegExp(stringPattern + '[bx]'),
  6. alias: 'number'
  7. };
  8. var macroVariable = {
  9. pattern: /&[a-z_]\w*/i
  10. };
  11. var macroKeyword = {
  12. pattern: /((?:^|\s|=|\())%(?:ABORT|BY|CMS|COPY|DISPLAY|DO|ELSE|END|EVAL|GLOBAL|GO|GOTO|IF|INC|INCLUDE|INDEX|INPUT|KTRIM|LENGTH|LET|LIST|LOCAL|PUT|QKTRIM|QSCAN|QSUBSTR|QSYSFUNC|QUPCASE|RETURN|RUN|SCAN|SUBSTR|SUPERQ|SYMDEL|SYMEXIST|SYMGLOBL|SYMLOCAL|SYSCALL|SYSEVALF|SYSEXEC|SYSFUNC|SYSGET|SYSRPUT|THEN|TO|TSO|UNQUOTE|UNTIL|UPCASE|WHILE|WINDOW)\b/i,
  13. lookbehind: true,
  14. alias: 'keyword'
  15. };
  16. var step = {
  17. pattern: /(^|\s)(?:proc\s+\w+|data(?!=)|quit|run)\b/i,
  18. alias: 'keyword',
  19. lookbehind: true
  20. };
  21. var comment = [
  22. /\/\*[\s\S]*?\*\//,
  23. {
  24. pattern: /(^[ \t]*|;\s*)\*[^;]*;/m,
  25. lookbehind: true
  26. }
  27. ];
  28. var string = {
  29. pattern: RegExp(stringPattern),
  30. greedy: true
  31. };
  32. var punctuation = /[$%@.(){}\[\];,\\]/;
  33. var func = {
  34. pattern: /%?\b\w+(?=\()/,
  35. alias: 'keyword'
  36. };
  37. var args = {
  38. 'function': func,
  39. 'arg-value': {
  40. pattern: /(=\s*)[A-Z\.]+/i,
  41. lookbehind: true
  42. },
  43. 'operator': /=/,
  44. 'macro-variable': macroVariable,
  45. 'arg': {
  46. pattern: /[A-Z]+/i,
  47. alias: 'keyword'
  48. },
  49. 'number': number,
  50. 'numeric-constant': numericConstant,
  51. 'punctuation': punctuation,
  52. 'string': string
  53. };
  54. var format = {
  55. pattern: /\b(?:format|put)\b=?[\w'$.]+/i,
  56. inside: {
  57. 'keyword': /^(?:format|put)(?==)/i,
  58. 'equals': /=/,
  59. 'format': {
  60. pattern: /(?:\w|\$\d)+\.\d?/,
  61. alias: 'number'
  62. }
  63. }
  64. };
  65. var altformat = {
  66. pattern: /\b(?:format|put)\s+[\w']+(?:\s+[$.\w]+)+(?=;)/i,
  67. inside: {
  68. 'keyword': /^(?:format|put)/i,
  69. 'format': {
  70. pattern: /[\w$]+\.\d?/,
  71. alias: 'number'
  72. }
  73. }
  74. };
  75. var globalStatements = {
  76. pattern: /((?:^|\s)=?)(?:catname|checkpoint execute_always|dm|endsas|filename|footnote|%include|libname|%list|lock|missing|options|page|resetline|%run|sasfile|skip|sysecho|title\d?)\b/i,
  77. lookbehind: true,
  78. alias: 'keyword'
  79. };
  80. var submitStatement = {
  81. pattern: /(^|\s)(?:submit(?:\s+(?:load|norun|parseonly))?|endsubmit)\b/i,
  82. lookbehind: true,
  83. alias: 'keyword'
  84. };
  85. var actionSets = /aStore|accessControl|aggregation|audio|autotune|bayesianNetClassifier|bioMedImage|boolRule|builtins|cardinality|cdm|clustering|conditionalRandomFields|configuration|copula|countreg|dataDiscovery|dataPreprocess|dataSciencePilot|dataStep|decisionTree|deduplication|deepLearn|deepNeural|deepRnn|ds2|ecm|entityRes|espCluster|explainModel|factmac|fastKnn|fcmpact|fedSql|freqTab|gVarCluster|gam|gleam|graphSemiSupLearn|hiddenMarkovModel|hyperGroup|ica|image|iml|kernalPca|langModel|ldaTopic|loadStreams|mbc|mixed|mlTools|modelPublishing|network|neuralNet|nmf|nonParametricBayes|nonlinear|optNetwork|optimization|panel|pca|percentile|phreg|pls|qkb|qlim|quantreg|recommend|regression|reinforcementLearn|robustPca|ruleMining|sampling|sandwich|sccasl|search(?:Analytics)?|sentimentAnalysis|sequence|session(?:Prop)?|severity|simSystem|simple|smartData|sparkEmbeddedProcess|sparseML|spatialreg|spc|stabilityMonitoring|svDataDescription|svm|table|text(?:Filters|Frequency|Mining|Parse|Rule(?:Develop|Score)|Topic|Util)|timeData|transpose|tsInfo|tsReconcile|uniTimeSeries|varReduce/.source;
  86. var casActions = {
  87. pattern: RegExp(/(^|\s)(?:action\s+)?(?:<act>)\.[a-z]+\b[^;]+/.source.replace(/<act>/g, function () { return actionSets; }), 'i'),
  88. lookbehind: true,
  89. inside: {
  90. 'keyword': RegExp(/(?:<act>)\.[a-z]+\b/.source.replace(/<act>/g, function () { return actionSets; }), 'i'),
  91. 'action': {
  92. pattern: /(?:action)/i,
  93. alias: 'keyword'
  94. },
  95. 'comment': comment,
  96. 'function': func,
  97. 'arg-value': args['arg-value'],
  98. 'operator': args.operator,
  99. 'argument': args.arg,
  100. 'number': number,
  101. 'numeric-constant': numericConstant,
  102. 'punctuation': punctuation,
  103. 'string': string
  104. }
  105. };
  106. var keywords = {
  107. pattern: /((?:^|\s)=?)(?:after|analysis|and|array|barchart|barwidth|begingraph|by|call|cas|cbarline|cfill|class(?:lev)?|close|column|computed?|contains|continue|data(?==)|define|delete|describe|document|do\s+over|do|dol|drop|dul|else|end(?:comp|source)?|entryTitle|eval(?:uate)?|exec(?:ute)?|exit|file(?:name)?|fill(?:attrs)?|flist|fnc|function(?:list)?|global|goto|group(?:by)?|headline|headskip|histogram|if|infile|keep|keylabel|keyword|label|layout|leave|legendlabel|length|libname|loadactionset|merge|midpoints|_?null_|name|noobs|nowd|ods|options|or|otherwise|out(?:put)?|over(?:lay)?|plot|print|put|raise|ranexp|rannor|rbreak|retain|return|select|session|sessref|set|source|statgraph|sum|summarize|table|temp|terminate|then\s+do|then|title\d?|to|var|when|where|xaxisopts|y2axisopts|yaxisopts)\b/i,
  108. lookbehind: true,
  109. };
  110. Prism.languages.sas = {
  111. 'datalines': {
  112. pattern: /^([ \t]*)(?:cards|(?:data)?lines);[\s\S]+?^[ \t]*;/im,
  113. lookbehind: true,
  114. alias: 'string',
  115. inside: {
  116. 'keyword': {
  117. pattern: /^(?:cards|(?:data)?lines)/i
  118. },
  119. 'punctuation': /;/
  120. }
  121. },
  122. 'proc-sql': {
  123. pattern: /(^proc\s+(?:fed)?sql(?:\s+[\w|=]+)?;)[\s\S]+?(?=^(?:proc\s+\w+|data|quit|run);|(?![\s\S]))/im,
  124. lookbehind: true,
  125. inside: {
  126. 'sql': {
  127. pattern: RegExp(/^[ \t]*(?:select|alter\s+table|(?:create|describe|drop)\s+(?:index|table(?:\s+constraints)?|view)|create\s+unique\s+index|insert\s+into|update)(?:<str>|[^;"'])+;/.source.replace(/<str>/g, function () { return stringPattern; }), 'im'),
  128. alias: 'language-sql',
  129. inside: Prism.languages.sql
  130. },
  131. 'global-statements': globalStatements,
  132. 'sql-statements': {
  133. pattern: /(^|\s)(?:disconnect\s+from|begin|commit|exec(?:ute)?|reset|rollback|validate)\b/i,
  134. lookbehind: true,
  135. alias: 'keyword'
  136. },
  137. 'number': number,
  138. 'numeric-constant': numericConstant,
  139. 'punctuation': punctuation,
  140. 'string': string
  141. }
  142. },
  143. 'proc-groovy': {
  144. pattern: /(^proc\s+groovy(?:\s+[\w|=]+)?;)[\s\S]+?(?=^(?:proc\s+\w+|data|quit|run);|(?![\s\S]))/im,
  145. lookbehind: true,
  146. inside: {
  147. 'comment': comment,
  148. 'groovy': {
  149. pattern: RegExp(/(^[ \t]*submit(?:\s+(?:load|norun|parseonly))?)(?:<str>|[^"'])+?(?=endsubmit;)/.source.replace(/<str>/g, function () { return stringPattern; }), 'im'),
  150. lookbehind: true,
  151. alias: 'language-groovy',
  152. inside: Prism.languages.groovy
  153. },
  154. 'keyword': keywords,
  155. 'submit-statement': submitStatement,
  156. 'global-statements': globalStatements,
  157. 'number': number,
  158. 'numeric-constant': numericConstant,
  159. 'punctuation': punctuation,
  160. 'string': string
  161. }
  162. },
  163. 'proc-lua': {
  164. pattern: /(^proc\s+lua(?:\s+[\w|=]+)?;)[\s\S]+?(?=^(?:proc\s+\w+|data|quit|run);|(?![\s\S]))/im,
  165. lookbehind: true,
  166. inside: {
  167. 'comment': comment,
  168. 'lua': {
  169. pattern: RegExp(/(^[ \t]*submit(?:\s+(?:load|norun|parseonly))?)(?:<str>|[^"'])+?(?=endsubmit;)/.source.replace(/<str>/g, function () { return stringPattern; }), 'im'),
  170. lookbehind: true,
  171. alias: 'language-lua',
  172. inside: Prism.languages.lua
  173. },
  174. 'keyword': keywords,
  175. 'submit-statement': submitStatement,
  176. 'global-statements': globalStatements,
  177. 'number': number,
  178. 'numeric-constant': numericConstant,
  179. 'punctuation': punctuation,
  180. 'string': string
  181. }
  182. },
  183. 'proc-cas': {
  184. pattern: /(^proc\s+cas(?:\s+[\w|=]+)?;)[\s\S]+?(?=^(?:proc\s+\w+|quit|data);|(?![\s\S]))/im,
  185. lookbehind: true,
  186. inside: {
  187. 'comment': comment,
  188. 'statement-var': {
  189. pattern: /((?:^|\s)=?)saveresult\s[^;]+/im,
  190. lookbehind: true,
  191. inside: {
  192. 'statement': {
  193. pattern: /^saveresult\s+\S+/i,
  194. inside: {
  195. keyword: /^(?:saveresult)/i
  196. }
  197. },
  198. rest: args
  199. }
  200. },
  201. 'cas-actions': casActions,
  202. 'statement': {
  203. pattern: /((?:^|\s)=?)(?:default|(?:un)?set|on|output|upload)[^;]+/im,
  204. lookbehind: true,
  205. inside: args
  206. },
  207. 'step': step,
  208. 'keyword': keywords,
  209. 'function': func,
  210. 'format': format,
  211. 'altformat': altformat,
  212. 'global-statements': globalStatements,
  213. 'number': number,
  214. 'numeric-constant': numericConstant,
  215. 'punctuation': punctuation,
  216. 'string': string
  217. }
  218. },
  219. 'proc-args': {
  220. pattern: RegExp(/(^proc\s+\w+\s+)(?!\s)(?:[^;"']|<str>)+;/.source.replace(/<str>/g, function () { return stringPattern; }), 'im'),
  221. lookbehind: true,
  222. inside: args
  223. },
  224. /*Special keywords within macros*/
  225. 'macro-keyword': macroKeyword,
  226. 'macro-variable': macroVariable,
  227. 'macro-string-functions': {
  228. pattern: /((?:^|\s|=))%(?:BQUOTE|NRBQUOTE|NRQUOTE|NRSTR|QUOTE|STR)\(.*?(?:[^%]\))/i,
  229. lookbehind: true,
  230. inside: {
  231. 'function': {
  232. pattern: /%(?:BQUOTE|NRBQUOTE|NRQUOTE|NRSTR|QUOTE|STR)/i,
  233. alias: 'keyword'
  234. },
  235. 'macro-keyword': macroKeyword,
  236. 'macro-variable': macroVariable,
  237. 'escaped-char': {
  238. pattern: /%['"()<>=¬^~;,#]/,
  239. },
  240. 'punctuation': punctuation
  241. }
  242. },
  243. 'macro-declaration': {
  244. pattern: /^%macro[^;]+(?=;)/im,
  245. inside: {
  246. 'keyword': /%macro/i,
  247. }
  248. },
  249. 'macro-end': {
  250. pattern: /^%mend[^;]+(?=;)/im,
  251. inside: {
  252. 'keyword': /%mend/i,
  253. }
  254. },
  255. /*%_zscore(headcir, _lhc, _mhc, _shc, headcz, headcpct, _Fheadcz); */
  256. 'macro': {
  257. pattern: /%_\w+(?=\()/,
  258. alias: 'keyword'
  259. },
  260. 'input': {
  261. pattern: /\binput\s[-\w\s/*.$&]+;/i,
  262. inside: {
  263. 'input': {
  264. alias: 'keyword',
  265. pattern: /^input/i,
  266. },
  267. 'comment': comment,
  268. 'number': number,
  269. 'numeric-constant': numericConstant
  270. }
  271. },
  272. 'options-args': {
  273. pattern: /(^options)[-'"|/\\<>*+=:()\w\s]*(?=;)/im,
  274. lookbehind: true,
  275. inside: args
  276. },
  277. 'cas-actions': casActions,
  278. 'comment': comment,
  279. 'function': func,
  280. 'format': format,
  281. 'altformat': altformat,
  282. 'numeric-constant': numericConstant,
  283. 'datetime': {
  284. // '1jan2013'd, '9:25:19pm't, '18jan2003:9:27:05am'dt
  285. pattern: RegExp(stringPattern + '(?:dt?|t)'),
  286. alias: 'number'
  287. },
  288. 'string': string,
  289. 'step': step,
  290. 'keyword': keywords,
  291. // In SAS Studio syntax highlighting, these operators are styled like keywords
  292. 'operator-keyword': {
  293. pattern: /\b(?:eq|ge|gt|in|le|lt|ne|not)\b/i,
  294. alias: 'operator'
  295. },
  296. // Decimal (1.2e23), hexadecimal (0c1x)
  297. 'number': number,
  298. 'operator': /\*\*?|\|\|?|!!?|¦¦?|<[>=]?|>[<=]?|[-+\/=&]|[~¬^]=?/,
  299. 'punctuation': punctuation
  300. };
  301. }(Prism));