Skip to content

Commit

Permalink
SAS: Minor improvements (#2085)
Browse files Browse the repository at this point in the history
* Reorder comment array to fix edge case added to comment_feature.test
* Adjust datalines to allow for possible preceding spaces before the closing semicolon
* Move comment in SAS object for correct syntax matching precedence
* Add several more keywords
  • Loading branch information
cedporter authored and RunDevelopment committed Oct 7, 2019
1 parent 5d07aa7 commit 07020c7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
10 changes: 5 additions & 5 deletions components/prism-sas.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
};

var comment = [
/\/\*[\s\S]*?\*\//,
{
pattern: /(^\s*|;\s*)\*[^;]*;/m,
lookbehind: true
},
/\/\*[\s\S]+?\*\//
}
];

var string = {
Expand Down Expand Up @@ -53,7 +53,7 @@

Prism.languages.sas = {
'datalines': {
pattern: /^(\s*)(?:(?:data)?lines|cards);[\s\S]+?^;/im,
pattern: /^(\s*)(?:(?:data)?lines|cards);[\s\S]+?^\s*;/im,
lookbehind: true,
alias: 'string',
inside: {
Expand Down Expand Up @@ -127,7 +127,6 @@
'numeric-constant': numericConstant
}
},
'comment': comment,
'options-args': {
pattern: /(^options)[-'"|/\\<>*+=:()\w\s]*(?=;)/im,
lookbehind: true,
Expand Down Expand Up @@ -159,6 +158,7 @@
}
},
'numeric-constant': numericConstant,
'comment': comment,
'datetime': {
// '1jan2013'd, '9:25:19pm't, '18jan2003:9:27:05am'dt
pattern: RegExp(stringPattern + '(?:dt?|t)'),
Expand All @@ -167,7 +167,7 @@
'string': string,
'step': step,
'keyword': {
pattern: /((?:^|\s)=?)(?:action|after|analysis|and|array|barchart|barwidth|begingraph|by|cas|cbarline|cfill|close|column|computed?|contains|data(?=\=)|define|document|do\s+over|do|dol|drop|dul|end|entryTitle|else|endcomp|fill(?:attrs)?|filename|group(?:by)?|headline|headskip|histogram|if|infile|keep|label|layout|legendlabel|length|libname|merge|midpoints|name|noobs|nowd|ods|options|or|out(?:put)?|overlay|plot|ranexp|rannor|rbreak|retain|set|session|sessref|statgraph|sum|summarize|table|temp|then\sdo|then|title\d?|to|var|where|xaxisopts|yaxisopts|y2axisopts)\b/i,
pattern: /((?:^|\s)=?)(?:action|after|analysis|and|array|barchart|barwidth|begingraph|by|cas|cbarline|cfill|class(?:lev)?|close|column|computed?|contains|data(?=\=)|define|document|do\s+over|do|dol|drop|dul|end|entryTitle|else|endcomp|fill(?:attrs)?|filename|group(?:by)?|headline|headskip|histogram|if|infile|keep|keylabel|keyword|label|layout|legendlabel|length|libname|merge|midpoints|name|noobs|nowd|ods|options|or|out(?:put)?|overlay|plot|ranexp|rannor|rbreak|retain|set|session|sessref|statgraph|sum|summarize|table|temp|then\s+do|then|title\d?|to|var|where|xaxisopts|yaxisopts|y2axisopts)\b/i,
lookbehind: true,
},
// In SAS Studio syntax highlighting, these operators are styled like keywords
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.

7 changes: 5 additions & 2 deletions tests/languages/sas/comment_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ foo; * foobar;
/* foo
bar */

/*options cashost="cloud.example.com" casport=5570;*/

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

[
["comment", "* foobar;"],
"\r\nfoo", ["punctuation", ";"],
["comment", "* foobar;"],
["comment", "/* foo\r\nbar */"]
["comment", "/* foo\r\nbar */"],
["comment", "/*options cashost=\"cloud.example.com\" casport=5570;*/"]
]

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

Checks for comments.
Checks for comments.
16 changes: 9 additions & 7 deletions tests/languages/sas/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
action after analysis and array barchart barwidth begingraph by
cas cbarline cfill close column compute computed contains data= define
cas cbarline cfill class classlev close column compute computed contains data= define
document do do over dol drop dul end entryTitle else endcomp fill fillattrs
filename group groupby headline headskip histogram if infile keep label layout
legendlabel length libname merge midpoints name noobs nowd ods or out output
overlay plot ranexp rannor rbreak retain set session sessref statgraph
sum summarize table temp then then do title to var where xaxisopts yaxisopts
y2axisopts
filename group groupby headline headskip histogram if infile keep keylabel
keyword label layout legendlabel length libname merge midpoints name noobs nowd
ods or out output overlay plot ranexp rannor rbreak retain set session sessref
statgraph sum summarize table temp then then do title to var where xaxisopts
yaxisopts y2axisopts

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

Expand All @@ -14,6 +14,7 @@ y2axisopts
["keyword", "and"], ["keyword", "array"], ["keyword", "barchart"],
["keyword", "barwidth"], ["keyword", "begingraph"], ["keyword", "by"],
["keyword", "cas"], ["keyword", "cbarline"], ["keyword", "cfill"],
["keyword", "class"], ["keyword", "classlev"],
["keyword", "close"], ["keyword", "column"], ["keyword", "compute"],
["keyword", "computed"], ["keyword", "contains"], ["keyword", "data"],
["operator", "="], ["keyword", "define"], ["keyword", "document"], ["keyword", "do"],
Expand All @@ -22,7 +23,8 @@ y2axisopts
["keyword", "endcomp"], ["keyword", "fill"], ["keyword", "fillattrs"],
["keyword", "filename"], ["keyword", "group"], ["keyword", "groupby"],
["keyword", "headline"], ["keyword", "headskip"], ["keyword", "histogram"],
["keyword", "if"], ["keyword", "infile"], ["keyword", "keep"], ["keyword", "label"],
["keyword", "if"], ["keyword", "infile"], ["keyword", "keep"],
["keyword", "keylabel"], ["keyword", "keyword"], ["keyword", "label"],
["keyword", "layout"], ["keyword", "legendlabel"], ["keyword", "length"],
["keyword", "libname"], ["keyword", "merge"], ["keyword", "midpoints"],
["keyword", "name"], ["keyword", "noobs"], ["keyword", "nowd"], ["keyword", "ods"],
Expand Down

0 comments on commit 07020c7

Please sign in to comment.