rubychan / coderay

Fast and easy syntax highlighting for selected languages, written in Ruby.
http://coderay.rubychan.de/
Other
846 stars 115 forks source link

add SAS language syntax highlighting #199

Open paulkaefer opened 8 years ago

paulkaefer commented 8 years ago

Add syntax highlighting for the SAS language

These are my collected notes on resources that should aid in writing this scanner. I'm interested and plan to contribute, but am not sure when I will get to it (see note at the end of this issue).

This page has an intro to SAS grammar/syntax, good for someone new to the language or as a good description for a veteran. In general, SAS procedures follow a similar syntax (see also here). Here is a list of all(?) SAS procedures. Note that you can follow the links and get to code examples.

Example code

SAS code files are stored with a .sas extension.

some typical examples

There are plenty of SAS code examples at sasCommunity.org. See Category:SAS Code and Category:Macro functions. This paper has a long example in the Appendix of how SAS code can look in a .pdf, probably from copying out of SAS Enterprise Guide.

There is a huge list of .sas files here (utilities section, notably). Many, if not all, are macro functions. Code inside macro functions isn't necessarily syntax highlighted (see below).

Rosetta Code has quite a few SAS code examples.

weird and strange SAS code

I've been searching for obfuscated or otherwise weird SAS code. This paper has a couple of examples of difficult-for-humans-to-read code, including a sample (on page 4) that is in the shape of a company's logo.

This piece of code is rather unusual, if somewhat boring as far as syntax highlighting goes.

information about the language

For reserved words/tokens/operators, see the UltraEdit wordfile.

A single- or double-quoted string CAN contain a new line.

If a line begins with an asterisk (*) and ends with a semicolon (;), it is commented-out. Likewise, single- or multi-line comments begin with /* and end with */.

SAS macro functions begin with %macro nameGoesHere; and end with %mend [optional nameGoesHere];.

Syntax is NOT highlighted inside the macro, with the exception of strings in purple; date strings "ddMONyyyy"d in green & bold and &rlib. --> rlib. (or whatever the macro name is) is green. That said, it's probably fine with most people (some discussion here) if the inner code is sytax highlighted. Here's an example of syntax highlighing within a macro function, using GitHub's syntax highlighter for SAS code.

Sample highlighters/syntax definitions

Probably the best (other than the software itself) is the syntax highlighter used on the SAS blogs. Here is a recent example. This and this have good examples for PROC SQL, which is SAS' method of handling SQL queries. They're handled a little differently than other versions of SQL; this paper sheds some light on that.

See the UltraEdit wordfile mentioned above. It contains reserved words, tokens, etc. I'm happy with UltraEdit's SAS coloring, though it could better match SAS'.

GitHub is good at highlighting SAS code. See this repository, for example (.sas files).

MediaWiki seems to do a good job. Example on sasCommunity.org. I'm struggling to find where the syntax highlighter is defined in the MediaWiki source (apparently here).

It looks like Sublime Text 2 does it. Reference and repository.

Atom's syntax coloring looks reasonable, but the color scheme is off. SAS Enterprise Guide is what I use; SAS University Edition is free, and is likely what I would use if I write this scanner.

I'm not a big fan of the color scheme used in SAS examples on Rosetta Code.

Writing this scanner

I am interested in writing this scanner. I'm not sure how soon I will get around to it, so in the meantime, others are welcome to start. If you get around to it (and let me know you are working on it) before I do, I will happily contribute/advise/test with you.

As I mentioned, SAS University Edition is free, and is what I would use if I work on this scanner, as SAS is typically very expensive.

paulkaefer commented 8 years ago

Another resource that might be useful is sas.php from the GeSHi - Generic Syntax Highlighter.

paulkaefer commented 8 years ago

In this thread on communities.sas.com, @cjdinger shares this .js file and this corresponding .css file for syntax highlighting using @PrismJS (improved from the PrismJS repo).

This is a good highlighter, as it is what is used on the communities.sas.com forums.

paulkaefer commented 8 years ago

I have started work on this.

paulkaefer commented 8 years ago

For reference, this is a syntax highlighter for Notepad++. I haven't used it enough to judge how good it is. It does have an extensive list of keywords.

blayz3r commented 6 years ago

+1