I’ve been writing some ACPI Source Language (ASL) code for a project recently, and so I went through the exercise of configuring syntax highlighting for my text editor.  I share my configuration below, for the SlickEdit and Notepad++ text editors, and offer a head-start in configuring any other text editor.

 

What is Syntax Highlighting?

From Wikipedia:

Syntax highlighting is a feature of text editors that are used for programming, scripting, or markup languages, such as HTML. The feature displays text, especially source code, in different colors and fonts according to the category of terms. This feature facilitates writing in a structured language such as a programming language or a markup language as both structures and syntax errors are visually distinct. Highlighting does not affect the meaning of the text itself; it is intended only for human readers.

I love syntax highlighting, and can’t live without it.  Here’s a before and after screenshot of the file Tpm.asl from the EDK:

Before:

image

After:

image

 

The color helps your eye to quickly pick apart the various tokens that make up ASL:  keywords, operators, library symbols, etc.  The coloring alerts you to possible errors before you commit your work because the code may not “look quite right.”

 

Spec Revision

I used ACPI Spec v6.1 to gather the various ASL tokens into meaningful categories in order to generate the syntax highlighting; mainly §19 of the Spec.  It is NOT an exact science—also, I find that SlickEdit has much better support for this type of thing than Notepad++ does.  If you can improve upon what I did, please do!  Everything’s on Github.  (see below)

 

Download

Unfortunately, every text editor has its own way of handling syntax highlighting.  I’ve included a .zip file for my text editor, SlickEdit.  If you use SlickEdit, (I use v20) you can simply click:

Tools/Options/Export-Import Options/Import Options

… and direct the dialog to the .zip file.

Realizing that Notepad++ is popular, I also configured it for ASL and saved the configuration as an .XML file.  If you use Notepad++, click:

Language/Define Your Language…/Import

… and direct the dialog to the .xml file.  Notepad++’s user defined language facility has some rough edges, but I did the best I could.

Lastly, if you use another text editor, you can download the text files I created to break down all the different keywords/reserved words into six different groupings.  Then, use your text editor’s facility for inputting these word tokens.

 

SlickEdit .zip:

https://github.com/WilliamLeara/BasicInputOutput/blob/master/SyntaxHighlight/SlickEditAcpiOptions20.zip

 

Notepad++ XML:

https://github.com/WilliamLeara/BasicInputOutput/blob/master/SyntaxHighlight/asl.xml

 

Token Files (Editor-Agnostic)

https://github.com/WilliamLeara/BasicInputOutput/tree/master/SyntaxHighlight/tokens/asl

 

Finally, awhile back I went through a similar exercise for all the various little languages that make up the EDK:  .dec, .dsc, .fdf, .inf, .uni, and .vfr.  You may find that post useful:

http://www.basicinputoutput.com/2015/05/syntax-highlighting-for-edkii-files-dec.html

 

Did you find syntax highlighting for ASL helpful?  Leave a comment, thanks!

Post a Comment

  1. Great article, William, and thanks for the downloadable tools. I appreciate syntax-highlighting as well, not so much as to separate out every nuance of the code (which I consider distracting if the color changes with each token), but at least to break out the major components (comments, literal strings, etc.) and do brace-matching. This helps me organize the information and focus on the blocks of data.

    ReplyDelete
  2. You've done an excellent job here, William! Working with ASL is same trouble for me, but I'm using Emacs and, unfortunately, your solution doesn't work here properly. In this very case I prefer more to save all codes as txt-files, but once I screwed something up and Emacs, as well as any other editor, stoped to read them. Wandering through forums trying to find any solution on this bug, I came across this tool that fix any error that doesn't let you to pen txt file https://wikiext.com/txt I guess it works well with editors like SlickEdit or Notepad as well. So I trust you'll give me some help with how to use your highliting in my editor too

    ReplyDelete
  3. Hello William, may I ask why you are not using VeB for this? It highlights the most important parts, of course not as good as the config you have presented above.

    ReplyDelete
    Replies
    1. Hi Cerber, thanks for the comment! Yes, VeB is a wonderful tool, however it is vendor-specific. (AMI) If your development organization has standardized on VeB, then you probably won't need to manually configure syntax highlighting. For anyone not using VeB, these lists of ASL language tokens can add syntax highlighting to any editor.

      Delete

Be sure to select an account profile (e.g. Google, OpenID, etc.) before typing your comment!