Skip to content

Commit

Permalink
SAS: Handle edge case of string macro functions (#2451)
Browse files Browse the repository at this point in the history
  • Loading branch information
cedporter authored Jul 2, 2020
1 parent 7c66cfc commit a0a9f1e
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 10 deletions.
16 changes: 15 additions & 1 deletion components/prism-sas.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,21 @@
lookbehind: true,
inside: args
},

'macro-string-functions': {
pattern: /((?:^|\s|=))%(?:NRBQUOTE|NRQUOTE|NRSTR|BQUOTE|QUOTE|STR)\(.*?(?:[^%]\))/i,
lookbehind: true,
inside: {
'function': {
pattern: /%(?:NRBQUOTE|NRQUOTE|NRSTR|BQUOTE|QUOTE|STR)/i,
alias: 'keyword'
},
'string': {
pattern: /(\()[^)]+/,
lookbehind: true
},
'punctuation': punctuation
}
},
/*Special keywords within macros*/
'macro-keyword': {
pattern: /((?:^|\s)=?)%(?:ABORT|BQUOTE|BY|CMS|COPY|DISPLAY|DO|ELSE|END|EVAL|GLOBAL|GO|GOTO|IF|INC|INCLUDE|INDEX|INPUT|KTRIM|LENGTH|LET|LIST|LOCAL|NRBQUOTE|NRQUOTE|NRSTR|PUT|QKTRIM|QSCAN|QSUBSTR|QSYSFUNC|QUOTE|QUPCASE|RETURN|RUN|SCAN|STR|SUBSTR|SUPERQ|SYMDEL|SYMGLOBL|SYMLOCAL|SYMEXIST|SYSCALL|SYSEVALF|SYSEXEC|SYSFUNC|SYSGET|SYSRPUT|THEN|TO|TSO|UNQUOTE|UNTIL|UPCASE|WHILE|WINDOW)\b/i,
Expand Down
2 changes: 1 addition & 1 deletion components/prism-sas.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 88 additions & 0 deletions tests/languages/sas/macro_string_function_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
%let a=%bquote(' ");
%let b=%nrbquote(' ");
%let c=%nrquote(%' %");
%let d=%nrstr(%' %");
%let e=%quote(%' %");
%let f=%str(%' %");

----------------------------------------------------

[
["macro-keyword", "%let"],
" a",
["operator", "="],
["macro-string-functions",
[
["function", "%bquote"],
["punctuation", "("],
["string", "' \""],
["punctuation", ")"]
]
],
["punctuation", ";"],
["macro-keyword", "%let"],
" b",
["operator", "="],
["macro-string-functions",
[
["function", "%nrbquote"],
["punctuation", "("],
["string", "' \""],
["punctuation", ")"]
]
],
["punctuation", ";"],
["macro-keyword", "%let"],
" c",
["operator", "="],
["macro-string-functions",
[
["function", "%nrquote"],
["punctuation", "("],
["string", "%' %\""],
["punctuation", ")"]
]
],
["punctuation", ";"],
["macro-keyword", "%let"],
" d",
["operator", "="],
["macro-string-functions",
[
["function", "%nrstr"],
["punctuation", "("],
["string", "%' %\""],
["punctuation", ")"]
]
],
["punctuation", ";"],
["macro-keyword", "%let"],
" e",
["operator", "="],
["macro-string-functions",
[
["function", "%quote"],
["punctuation", "("],
["string", "%' %\""],
["punctuation", ")"]
]
],
["punctuation", ";"],
["macro-keyword", "%let"],
" f",
["operator", "="],
["macro-string-functions",
[
["function", "%str"],
["punctuation", "("],
["string", "%' %\""],
["punctuation", ")"]
]
],
["punctuation", ";"
]
]

----------------------------------------------------

Checks for all macro string functions.
15 changes: 7 additions & 8 deletions tests/languages/sas/macrokeyword_feature.test
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
%ABORT %BQUOTE %BY %CMS %COPY %DISPLAY %DO %ELSE %END %EVAL %GLOBAL %GO %GOTO %IF %INC %INCLUDE
%INDEX %INPUT %KTRIM %LENGTH %LET %LIST %LOCAL %NRBQUOTE %NRQUOTE %NRSTR %PUT %QKTRIM %QSCAN
%QSUBSTR %QSYSFUNC %QUOTE %QUPCASE %RETURN %RUN %SCAN %STR %SUBSTR %SUPERQ %SYMDEL %SYMGLOBL
%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 %SYMGLOBL
%SYMLOCAL %SYMEXIST %SYSCALL %SYSEVALF %SYSEXEC %SYSFUNC %SYSGET %SYSRPUT %THEN %TO %TSO
%UNQUOTE %UNTIL %UPCASE %WHILE %WINDOW

----------------------------------------------------

[
["macro-keyword", "%ABORT"], ["macro-keyword", "%BQUOTE"], ["macro-keyword", "%BY"],
["macro-keyword", "%ABORT"], ["macro-keyword", "%BY"],
["macro-keyword", "%CMS"], ["macro-keyword", "%COPY"], ["macro-keyword", "%DISPLAY"],
["macro-keyword", "%DO"], ["macro-keyword", "%ELSE"], ["macro-keyword", "%END"],
["macro-keyword", "%EVAL"], ["macro-keyword", "%GLOBAL"], ["macro-keyword", "%GO"],
["macro-keyword", "%GOTO"], ["macro-keyword", "%IF"], ["macro-keyword", "%INC"],
["macro-keyword", "%INCLUDE"], ["macro-keyword", "%INDEX"],
["macro-keyword", "%INPUT"], ["macro-keyword", "%KTRIM"],
["macro-keyword", "%LENGTH"], ["macro-keyword", "%LET"], ["macro-keyword", "%LIST"],
["macro-keyword", "%LOCAL"], ["macro-keyword", "%NRBQUOTE"],
["macro-keyword", "%NRQUOTE"], ["macro-keyword", "%NRSTR"],
["macro-keyword", "%LOCAL"],
["macro-keyword", "%PUT"], ["macro-keyword", "%QKTRIM"],
["macro-keyword", "%QSCAN"], ["macro-keyword", "%QSUBSTR"],
["macro-keyword", "%QSYSFUNC"], ["macro-keyword", "%QUOTE"],
["macro-keyword", "%QSYSFUNC"],
["macro-keyword", "%QUPCASE"], ["macro-keyword", "%RETURN"],
["macro-keyword", "%RUN"], ["macro-keyword", "%SCAN"], ["macro-keyword", "%STR"],
["macro-keyword", "%RUN"], ["macro-keyword", "%SCAN"],
["macro-keyword", "%SUBSTR"], ["macro-keyword", "%SUPERQ"],
["macro-keyword", "%SYMDEL"], ["macro-keyword", "%SYMGLOBL"],
["macro-keyword", "%SYMLOCAL"], ["macro-keyword", "%SYMEXIST"],
Expand Down

0 comments on commit a0a9f1e

Please sign in to comment.