Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add SAS language syntax highlighting #199

Open
paulkaefer opened this issue Jul 26, 2016 · 5 comments
Open

add SAS language syntax highlighting #199

paulkaefer opened this issue Jul 26, 2016 · 5 comments

Comments

@paulkaefer
Copy link

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
Copy link
Author

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

@paulkaefer
Copy link
Author

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
Copy link
Author

I have started work on this.

@paulkaefer
Copy link
Author

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.

paulkaefer added a commit to paulkaefer/coderay that referenced this issue Aug 24, 2016
@blayz3r
Copy link

blayz3r commented Aug 14, 2018

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants