Skip to content

Commit 278316c

Browse files
authoredJul 6, 2020
SAS: Improved macro string functions (#2463)
1 parent 537a9e8 commit 278316c

File tree

4 files changed

+200
-208
lines changed

4 files changed

+200
-208
lines changed
 

‎components/prism-sas.js

+18-13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88
alias: 'number'
99
};
1010

11+
var macroVariable = {
12+
pattern: /&[a-z_][a-z_0-9]*/i
13+
};
14+
15+
var macroKeyword = {
16+
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|SYMGLOBL|SYMLOCAL|SYMEXIST|SYSCALL|SYSEVALF|SYSEXEC|SYSFUNC|SYSGET|SYSRPUT|THEN|TO|TSO|UNQUOTE|UNTIL|UPCASE|WHILE|WINDOW)\b/i,
17+
lookbehind: true,
18+
alias: 'keyword'
19+
};
20+
1121
var step = {
1222
pattern: /(^|\s+)(?:proc\s+\w+|quit|run|data(?!\=))\b/i,
1323
alias: 'keyword',
@@ -41,10 +51,7 @@
4151
lookbehind: true
4252
},
4353
'operator': /=/,
44-
'macro-variable': {
45-
pattern: /&[^\.]*\./i,
46-
alias: 'string'
47-
},
54+
'macro-variable': macroVariable,
4855
'arg': {
4956
pattern: /[A-Z]+/i,
5057
alias: 'keyword'
@@ -237,6 +244,9 @@
237244
lookbehind: true,
238245
inside: args
239246
},
247+
/*Special keywords within macros*/
248+
'macro-keyword': macroKeyword,
249+
'macro-variable': macroVariable,
240250
'macro-string-functions': {
241251
pattern: /((?:^|\s|=))%(?:NRBQUOTE|NRQUOTE|NRSTR|BQUOTE|QUOTE|STR)\(.*?(?:[^%]\))/i,
242252
lookbehind: true,
@@ -245,19 +255,14 @@
245255
pattern: /%(?:NRBQUOTE|NRQUOTE|NRSTR|BQUOTE|QUOTE|STR)/i,
246256
alias: 'keyword'
247257
},
248-
'string': {
249-
pattern: /(\()[^)]+/,
250-
lookbehind: true
258+
'macro-keyword': macroKeyword,
259+
'macro-variable': macroVariable,
260+
'escaped-char': {
261+
pattern: /%['"()<>=¬^~;,#]/i,
251262
},
252263
'punctuation': punctuation
253264
}
254265
},
255-
/*Special keywords within macros*/
256-
'macro-keyword': {
257-
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,
258-
lookbehind: true,
259-
alias: 'keyword'
260-
},
261266
'macro-declaration': {
262267
pattern: /^%macro[^;]+(?=;)/im,
263268
inside: {

‎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
@@ -1,88 +1,95 @@
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.
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+
%let char1 = %bquote(%substr(&infile,1,1));
8+
9+
----------------------------------------------------
10+
11+
[
12+
["macro-keyword", "%let"],
13+
" a",
14+
["operator", "="],
15+
["macro-string-functions", [
16+
["function", "%bquote"],
17+
["punctuation", "("],
18+
"' \"",
19+
["punctuation", ")"]
20+
]],
21+
["punctuation", ";"],
22+
["macro-keyword", "%let"],
23+
" b",
24+
["operator", "="],
25+
["macro-string-functions", [
26+
["function", "%nrbquote"],
27+
["punctuation", "("],
28+
"' \"",
29+
["punctuation", ")"]
30+
]],
31+
["punctuation", ";"],
32+
["macro-keyword", "%let"],
33+
" c",
34+
["operator", "="],
35+
["macro-string-functions", [
36+
["function", "%nrquote"],
37+
["punctuation", "("],
38+
["escaped-char", "%'"],
39+
["escaped-char", "%\""],
40+
["punctuation", ")"]
41+
]],
42+
["punctuation", ";"],
43+
["macro-keyword", "%let"],
44+
" d",
45+
["operator", "="],
46+
["macro-string-functions", [
47+
["function", "%nrstr"],
48+
["punctuation", "("],
49+
["escaped-char", "%'"],
50+
["escaped-char", "%\""],
51+
["punctuation", ")"]
52+
]],
53+
["punctuation", ";"],
54+
["macro-keyword", "%let"],
55+
" e",
56+
["operator", "="],
57+
["macro-string-functions", [
58+
["function", "%quote"],
59+
["punctuation", "("],
60+
["escaped-char", "%'"],
61+
["escaped-char", "%\""],
62+
["punctuation", ")"]
63+
]],
64+
["punctuation", ";"],
65+
["macro-keyword", "%let"],
66+
" f",
67+
["operator", "="],
68+
["macro-string-functions", [
69+
["function", "%str"],
70+
["punctuation", "("],
71+
["escaped-char", "%'"],
72+
["escaped-char", "%\""],
73+
["punctuation", ")"]
74+
]],
75+
["punctuation", ";"],
76+
["macro-keyword", "%let"],
77+
" char1 ",
78+
["operator", "="],
79+
["function", "%bquote"],
80+
["punctuation", "("],
81+
["macro-keyword", "%substr"],
82+
["punctuation", "("],
83+
["macro-variable", "&infile"],
84+
["punctuation", ","],
85+
["number", "1"],
86+
["punctuation", ","],
87+
["number", "1"],
88+
["punctuation", ")"],
89+
["punctuation", ")"],
90+
["punctuation", ";"]
91+
]
92+
93+
----------------------------------------------------
94+
95+
Checks for all macro string functions.

‎tests/languages/sas/macrodefinition_feature.test

+86-106
Original file line numberDiff line numberDiff line change
@@ -19,113 +19,93 @@
1919
----------------------------------------------------
2020

2121
[
22-
[
23-
"macro-declaration",
24-
[
25-
["keyword", "%macro"],
26-
" prnt(var,sum)"
27-
]
28-
],
29-
["punctuation", ";"],
30-
["step", "proc print"],
31-
["keyword", "data"],
32-
["operator", "="],
33-
"srhigh",
34-
["punctuation", ";"],
35-
["keyword", "var"],
36-
["operator", "&"],
37-
"var",
38-
["punctuation", ";"],
39-
["keyword", "sum"],
40-
["operator", "&"],
41-
"sum",
42-
["punctuation", ";"],
43-
["step", "run"],
44-
["punctuation", ";"],
45-
[
46-
"macro-end",
47-
[
48-
["keyword", "%mend"],
49-
" prnt"
50-
]
51-
],
52-
["punctuation", ";"],
53-
[
54-
"macro-declaration",
55-
[
56-
["keyword", "%macro"],
57-
" printz/parmbuff"
58-
]
59-
],
60-
["punctuation", ";"],
61-
["macro-keyword", "%let"],
62-
" num",
63-
["operator", "="],
64-
["number", "1"],
65-
["punctuation", ";"],
66-
["macro-keyword", "%let"],
67-
" dsname",
68-
["operator", "="],
69-
["function", "%scan"],
70-
["punctuation", "("],
71-
["operator", "&"],
72-
"syspbuff",
73-
["punctuation", ","],
74-
["operator", "&"],
75-
"num",
76-
["punctuation", ")"],
77-
["punctuation", ";"],
78-
["macro-keyword", "%do"],
79-
["macro-keyword", "%while"],
80-
["punctuation", "("],
81-
["operator", "&"],
82-
"dsname ",
83-
["operator-keyword", "ne"],
84-
["punctuation", ")"],
85-
["punctuation", ";"],
86-
["step", "proc print"],
87-
["keyword", "data"],
88-
["operator", "="],
89-
["operator", "&"],
90-
"dsname",
91-
["punctuation", ";"],
92-
["step", "run"],
93-
["punctuation", ";"],
94-
["macro-keyword", "%let"],
95-
" num",
96-
["operator", "="],
97-
["function", "%eval"],
98-
["punctuation", "("],
99-
["operator", "&"],
100-
"num",
101-
["operator", "+"],
102-
["number", "1"],
103-
["punctuation", ")"],
104-
["punctuation", ";"],
105-
["macro-keyword", "%let"],
106-
" dsname",
107-
["operator", "="],
108-
["function", "%scan"],
109-
["punctuation", "("],
110-
["operator", "&"],
111-
"syspbuff",
112-
["punctuation", ","],
113-
["operator", "&"],
114-
"num",
115-
["punctuation", ")"],
116-
["punctuation", ";"],
117-
["macro-keyword", "%end"],
118-
["punctuation", ";"],
119-
[
120-
"macro-end",
121-
[
122-
["keyword", "%mend"],
123-
" printz"
124-
]
125-
],
126-
["punctuation", ";"]
22+
["macro-declaration", [
23+
["keyword", "%macro"],
24+
" prnt(var,sum)"
25+
]],
26+
["punctuation", ";"],
27+
["step", "proc print"],
28+
["keyword", "data"],
29+
["operator", "="],
30+
"srhigh",
31+
["punctuation", ";"],
32+
["keyword", "var"],
33+
["macro-variable", "&var"],
34+
["punctuation", ";"],
35+
["keyword", "sum"],
36+
["macro-variable", "&sum"],
37+
["punctuation", ";"],
38+
["step", "run"],
39+
["punctuation", ";"],
40+
["macro-end", [
41+
["keyword", "%mend"],
42+
" prnt"
43+
]],
44+
["punctuation", ";"],
45+
46+
["macro-declaration", [
47+
["keyword", "%macro"],
48+
" printz/parmbuff"
49+
]],
50+
["punctuation", ";"],
51+
["macro-keyword", "%let"],
52+
" num",
53+
["operator", "="],
54+
["number", "1"],
55+
["punctuation", ";"],
56+
["macro-keyword", "%let"],
57+
" dsname",
58+
["operator", "="],
59+
["macro-keyword", "%scan"],
60+
["punctuation", "("],
61+
["macro-variable", "&syspbuff"],
62+
["punctuation", ","],
63+
["macro-variable", "&num"],
64+
["punctuation", ")"],
65+
["punctuation", ";"],
66+
["macro-keyword", "%do"],
67+
["macro-keyword", "%while"],
68+
["punctuation", "("],
69+
["macro-variable", "&dsname"],
70+
["operator-keyword", "ne"],
71+
["punctuation", ")"],
72+
["punctuation", ";"],
73+
["step", "proc print"],
74+
["keyword", "data"],
75+
["operator", "="],
76+
["macro-variable", "&dsname"],
77+
["punctuation", ";"],
78+
["step", "run"],
79+
["punctuation", ";"],
80+
["macro-keyword", "%let"],
81+
" num",
82+
["operator", "="],
83+
["macro-keyword", "%eval"],
84+
["punctuation", "("],
85+
["macro-variable", "&num"],
86+
["operator", "+"],
87+
["number", "1"],
88+
["punctuation", ")"],
89+
["punctuation", ";"],
90+
["macro-keyword", "%let"],
91+
" dsname",
92+
["operator", "="],
93+
["macro-keyword", "%scan"],
94+
["punctuation", "("],
95+
["macro-variable", "&syspbuff"],
96+
["punctuation", ","],
97+
["macro-variable", "&num"],
98+
["punctuation", ")"],
99+
["punctuation", ";"],
100+
["macro-keyword", "%end"],
101+
["punctuation", ";"],
102+
["macro-end", [
103+
["keyword", "%mend"],
104+
" printz"
105+
]],
106+
["punctuation", ";"]
127107
]
128108

129109
----------------------------------------------------
130110

131-
Checks that options captures "options" and correctly tags following text.
111+
Check that macro definition correctly recognizes %macro and %mend.

0 commit comments

Comments
 (0)
Please sign in to comment.