Emacs mode for TrafficScriptIt's amazing how quickly you can build rich functionality with TrafficScript to perform all kinds of wonderful tasks. Sometimes these TrafficScript rules get so elaborate, you want to be able to edit them in a 'proper' editor such as Emacs, rather than just hacking away in a web page. Emacs brings with it a huge amount of power for editing programs; not least full syntax-highlighting which can greatly reduce the time it takes to go from initial idea to working TrafficScript rule. So with no further ado, I hereby present an emacs mode for TrafficScript, trafficscript.el. Here's an example of Owen's funky RSS embedder rule he recently posted, in full font-lock glory:
To install it, do the usual emacs thing; grab the file, put it somewhere, and either run 'M-x load-file', then 'M-x trafficscript-mode', or add it into your .emacs file. The current version is pretty basic - although it's amazing what just 7 lines of lisp will do. The next step is to build a whole compilation environment where you can compile rules from within emacs (say with C-c C-c), step through compilation warnings using the normal C-x ` etc. This is actually really easy to do, if you run $ZEUSHOME/zxtm/bin/zeus.zxtm --rulesyntaxcheck <filename> on your file you'll see what I mean. First person to post a better version of this trafficscript-mode which does that (or more!) wins a free Zeus T-shirt - how's that for an offer :)
Damian Reeves
[Zeus CTO] 12 January 2006
Comments:This public messageboard is not a forum for technical support. To report technical support problems, please contact our dedicated Support team using the instructions at the bottom of this page.
Comment from:
Crispin Flowerday [Zeus Dev Team]
Much as emacs is a fine editor, there are alternatives in this century. GEdit is a very simple editor that is perfect for this type of thing.
This is very simple to setup, just copy the following text into ~/.gnome2/gtksourceview-1.0/language-specs/trafficscript.lang.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE language SYSTEM "language.dtd"> <language _name="TrafficScript" version="1.0" _section="Scripts" mimetypes="text/x-trafficscript"> <escape-char>\</escape-char> <string _name = "String" style = "String" end-at-line-end = "FALSE"> <start-regex>"</start-regex> <end-regex>"</end-regex> </string> <line-comment _name = "Line Comment" style= "Comment"> <start-regex>#</start-regex> </line-comment> <pattern-item _name = "Variables" style = "Data Type"> <regex>[$][a-zA-Z0-9_]+</regex> </pattern-item> <keyword-list _name = "Keywords" style = "Keyword" case-sensitive="TRUE"> <keyword>while</keyword> <keyword>if</keyword> <keyword>else</keyword> <keyword>break</keyword> <keyword>continue</keyword> </keyword-list> </language>You can then load up a trafficscript rule, and select the 'TrafficScript' highlighting mode from the View menu.
Comment from:
Dec [Zeus Dev Team]
Not to be outdone by users of inferior text editors the following is a syntax highlighting scheme for TrafficScript for VIM. Save the following code to trafficscript.vim
" Vim syntax file " Language: TrafficScript " Maintainer: Declan Conlon " Last Change: 13 Jan 2006 " URL: http://knowledgehub.zeus.com syn keyword Conditional if else syn keyword Statement break continue syn keyword Repeat while syn match Comment "#.*" syn match Identifier "\$[A-Za-z0-9][A-Za-z0-9_]\+" syn match Function "[A-Za-z0-9]\+\(\.[A-Za-z0-9]\+\)\+" syn region String start="\"" end="\"" skip="\\\\\|\\\"" let b:current_syntax = "trafficscript"Then to use it, enter the command :so trafficscript.vim and enjoy :-)
Comment from:
Owen Garrett [Zeus Dev Team]
Of course, the discerning developer eschews RSI-inducing kitchen sinks, notepad clones and 1970's retro editors with command and insert modes. The wise and serene embrace Nirvana, in the shape and form of Nedit:
Note the use of a modern window manager ;-) You configure the syntax highlighting rules using a GUI (shock!), or you can add the following snippets to your .nedit/nedit.rc or .nedit config file:
In the nedit.highlightPatterns section:
TrafficScript:1:0{\n\
Quoted string:"""":""""::String::\n\
Escapes in strings:"\\\\.":::String2:Quoted string:\n\
Keywords:"(?<!\\Y)(if|else|while|break|continue)(?!\\Y)":::Keyword::\n\
Variable:"\\$([0-9a-zA-Z_]*)":::Identifier1::\n\
Function call:"<[\\l_]\\w.*>\\s*\\n?\\s*(?=\\()":::Subroutine::\n\
Comment:"#.*$":::Comment::\n\
}
In the nedit.languageModes section:
TrafficScript:.ts:::::::\nThe following macro lets you run the TrafficScript syntax checker, using 'Alt-T'. Add it to nedit.shellCommands:
TrafficScript Check:Alt+T::WS:\n\ $ZEUSHOME/zxtm/bin/zeus.zxtm --rulesyntaxcheck % && echo No syntax errors\n
Comment from:
Sambeau [Zeus Dev Team]
Or if you are a Old-Skool Mac saddo like me, you might prefer to pay to use BBEdit and get half as much syntax coloring as everyone else...
Just save the following text as /Applications/BBEdit.app/Contents/Language\ Modules/ZTSCodeless.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BBEditDocumentType</key>
<string>CodelessLanguageModule</string>
<key>BBLMColorsSyntax</key>
<true/>
<key>BBLMIsCaseSensitive</key>
<true/>
<key>BBLMKeywordList</key>
<array>
<string>while</string>
<string>if</string>
<string>else</string>
<string>break</string>
<string>continue</string>
</array>
<key>BBLMLanguageCode</key>
<string>ZTts</string>
<key>BBLMLanguageDisplayName</key>
<string>TrafficScript</string>
<key>BBLMScansFunctions</key>
<true/>
<key>Language Features</key>
<dict>
<key>Close Parameter Lists</key>
<string>)</string>
<key>Close Statement Blocks</key>
<string>}</string>
<key>Close Strings 1</key>
<string>'</string>
<key>Close Strings 2</key>
<string>"</string>
<key>End-of-line Ends Strings 1</key>
<false/>
<key>End-of-line Ends Strings 2</key>
<false/>
<key>Escape Char in Strings 1</key>
<string>\</string>
<key>Escape Char in Strings 2</key>
<string>\</string>
<key>Identifier and Keyword Characters</key>
<string>0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$.</string>
<key>Open Line Comments</key>
<string>#</string>
<key>Open Parameter Lists</key>
<string>(</string>
<key>Open Statement Blocks</key>
<string>{</string>
<key>Open Strings 1</key>
<string>'</string>
<key>Open Strings 2</key>
<string>"</string>
</dict>
</dict>
</plist>
And you should get something like this:![]() Note the use of a modern operating system and gorgeous display-pdf rendering!
Comment from:
Peter Payne [Visitor]
I am impressed. Emacs support is always very welcome to serious programmers. And vim support is nice too. Great stuff.
I've always been a fan of Microchip (www.microchip.com) and the reason why is not necessarily based on the actual chips they produce, but on the superior quality of their user manuals. OK, so that's an aside, but anyway the point is it's nice to have programmer support for products and editor highlighting contributes positively! |
Recent Articles
Other Resources
|



