Skip to content

Commit a0a9f1e

Browse files
authored
SAS: Handle edge case of string macro functions (#2451)
1 parent 7c66cfc commit a0a9f1e

File tree

4 files changed

+111
-10
lines changed

4 files changed

+111
-10
lines changed

components/prism-sas.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,21 @@
237237
lookbehind: true,
238238
inside: args
239239
},
240-
240+
'macro-string-functions': {
241+
pattern: /((?:^|\s|=))%(?:NRBQUOTE|NRQUOTE|NRSTR|BQUOTE|QUOTE|STR)\(.*?(?:[^%]\))/i,
242+
lookbehind: true,
243+
inside: {
244+
'function': {
245+
pattern: /%(?:NRBQUOTE|NRQUOTE|NRSTR|BQUOTE|QUOTE|STR)/i,
246+
alias: 'keyword'
247+
},
248+
'string': {
249+
pattern: /(\()[^)]+/,
250+
lookbehind: true
251+
},
252+
'punctuation': punctuation
253+
}
254+
},
241255
/*Special keywords within macros*/
242256
'macro-keyword': {
243257
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,

components/prism-sas.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
%let a=%bquote(' ");
2+
%let b=%nrbquote(' ");
3+
%let c=%nrquote(%' %");
4+
%let d=%nrstr(%' %");
5+
%let e=%quote(%' %");
6+
%let f=%str(%' %");
7+
8+
----------------------------------------------------
9+
10+
[
11+
["macro-keyword", "%let"],
12+
" a",
13+
["operator", "="],
14+
["macro-string-functions",
15+
[
16+
["function", "%bquote"],
17+
["punctuation", "("],
18+
["string", "' \""],
19+
["punctuation", ")"]
20+
]
21+
],
22+
["punctuation", ";"],
23+
["macro-keyword", "%let"],
24+
" b",
25+
["operator", "="],
26+
["macro-string-functions",
27+
[
28+
["function", "%nrbquote"],
29+
["punctuation", "("],
30+
["string", "' \""],
31+
["punctuation", ")"]
32+
]
33+
],
34+
["punctuation", ";"],
35+
["macro-keyword", "%let"],
36+
" c",
37+
["operator", "="],
38+
["macro-string-functions",
39+
[
40+
["function", "%nrquote"],
41+
["punctuation", "("],
42+
["string", "%' %\""],
43+
["punctuation", ")"]
44+
]
45+
],
46+
["punctuation", ";"],
47+
["macro-keyword", "%let"],
48+
" d",
49+
["operator", "="],
50+
["macro-string-functions",
51+
[
52+
["function", "%nrstr"],
53+
["punctuation", "("],
54+
["string", "%' %\""],
55+
["punctuation", ")"]
56+
]
57+
],
58+
["punctuation", ";"],
59+
["macro-keyword", "%let"],
60+
" e",
61+
["operator", "="],
62+
["macro-string-functions",
63+
[
64+
["function", "%quote"],
65+
["punctuation", "("],
66+
["string", "%' %\""],
67+
["punctuation", ")"]
68+
]
69+
],
70+
["punctuation", ";"],
71+
["macro-keyword", "%let"],
72+
" f",
73+
["operator", "="],
74+
["macro-string-functions",
75+
[
76+
["function", "%str"],
77+
["punctuation", "("],
78+
["string", "%' %\""],
79+
["punctuation", ")"]
80+
]
81+
],
82+
["punctuation", ";"
83+
]
84+
]
85+
86+
----------------------------------------------------
87+
88+
Checks for all macro string functions.

tests/languages/sas/macrokeyword_feature.test

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
%ABORT %BQUOTE %BY %CMS %COPY %DISPLAY %DO %ELSE %END %EVAL %GLOBAL %GO %GOTO %IF %INC %INCLUDE
2-
%INDEX %INPUT %KTRIM %LENGTH %LET %LIST %LOCAL %NRBQUOTE %NRQUOTE %NRSTR %PUT %QKTRIM %QSCAN
3-
%QSUBSTR %QSYSFUNC %QUOTE %QUPCASE %RETURN %RUN %SCAN %STR %SUBSTR %SUPERQ %SYMDEL %SYMGLOBL
1+
%ABORT %BY %CMS %COPY %DISPLAY %DO %ELSE %END %EVAL %GLOBAL %GO %GOTO %IF %INC %INCLUDE
2+
%INDEX %INPUT %KTRIM %LENGTH %LET %LIST %LOCAL %PUT %QKTRIM %QSCAN
3+
%QSUBSTR %QSYSFUNC %QUPCASE %RETURN %RUN %SCAN %SUBSTR %SUPERQ %SYMDEL %SYMGLOBL
44
%SYMLOCAL %SYMEXIST %SYSCALL %SYSEVALF %SYSEXEC %SYSFUNC %SYSGET %SYSRPUT %THEN %TO %TSO
55
%UNQUOTE %UNTIL %UPCASE %WHILE %WINDOW
66

77
----------------------------------------------------
88

99
[
10-
["macro-keyword", "%ABORT"], ["macro-keyword", "%BQUOTE"], ["macro-keyword", "%BY"],
10+
["macro-keyword", "%ABORT"], ["macro-keyword", "%BY"],
1111
["macro-keyword", "%CMS"], ["macro-keyword", "%COPY"], ["macro-keyword", "%DISPLAY"],
1212
["macro-keyword", "%DO"], ["macro-keyword", "%ELSE"], ["macro-keyword", "%END"],
1313
["macro-keyword", "%EVAL"], ["macro-keyword", "%GLOBAL"], ["macro-keyword", "%GO"],
1414
["macro-keyword", "%GOTO"], ["macro-keyword", "%IF"], ["macro-keyword", "%INC"],
1515
["macro-keyword", "%INCLUDE"], ["macro-keyword", "%INDEX"],
1616
["macro-keyword", "%INPUT"], ["macro-keyword", "%KTRIM"],
1717
["macro-keyword", "%LENGTH"], ["macro-keyword", "%LET"], ["macro-keyword", "%LIST"],
18-
["macro-keyword", "%LOCAL"], ["macro-keyword", "%NRBQUOTE"],
19-
["macro-keyword", "%NRQUOTE"], ["macro-keyword", "%NRSTR"],
18+
["macro-keyword", "%LOCAL"],
2019
["macro-keyword", "%PUT"], ["macro-keyword", "%QKTRIM"],
2120
["macro-keyword", "%QSCAN"], ["macro-keyword", "%QSUBSTR"],
22-
["macro-keyword", "%QSYSFUNC"], ["macro-keyword", "%QUOTE"],
21+
["macro-keyword", "%QSYSFUNC"],
2322
["macro-keyword", "%QUPCASE"], ["macro-keyword", "%RETURN"],
24-
["macro-keyword", "%RUN"], ["macro-keyword", "%SCAN"], ["macro-keyword", "%STR"],
23+
["macro-keyword", "%RUN"], ["macro-keyword", "%SCAN"],
2524
["macro-keyword", "%SUBSTR"], ["macro-keyword", "%SUPERQ"],
2625
["macro-keyword", "%SYMDEL"], ["macro-keyword", "%SYMGLOBL"],
2726
["macro-keyword", "%SYMLOCAL"], ["macro-keyword", "%SYMEXIST"],

0 commit comments

Comments
 (0)