- Torquescript Plugin for Komodo Edit/IDE
- 06 Feb 2012 09:18:56 pm
- Last edited by elfprince13 on 05 Oct 2012 05:25:28 pm; edited 4 times in total
GarageGames Blog #1 wrote:
Anyone who's developed for Torque on OS X knows how limited our options have been as far as a good programmer's text-editor for composing Torque Script files. Komodo Edit is a fantastic (and free, though it's IDE cousin is not) editor based on Scintilla, Python, and Mozilla. It supports both extensible syntax highlighting, extensible linting (syntax checking) and extensible code-sense (autocomplete). After struggling to understand the User-Defined Language architecture - it's limited to Cascading Style Sheet, Client-Side Languages, Server-Side Languages, and Markup type languages, and the state machine for the lexer evidently begins in Markup mode, and to get the SDK working on both Lion (PPC only binaries) and Vista (VirtualStore is the worst thing I've ever encountered in what's supposed to be a useable operating system), I have produced a working plugin. At the moment it only supports the UDL/syntax-highlighting portion of the features mentioned above, but I plan to keep hacking away at it. Also, for whatever reason SSLs have one additional color available as compared to CSL.
If you just want to download it, click here and then drag-and-drop the downloaded file into the main editing window of Komodo Edit (or IDE), approve the installation, and restart. Then change the file associations and coloring to fit your needs and have fun.
Here we have examples of two different color schemes:
A couple things to note:
[edit]
The forum software breaks code with backslashes. Click here if you want to take a look at the lexer code.
If you just want to download it, click here and then drag-and-drop the downloaded file into the main editing window of Komodo Edit (or IDE), approve the installation, and restart. Then change the file associations and coloring to fit your needs and have fun.
Here we have examples of two different color schemes:
A couple things to note:
- Komodo Edit supports C# development, so you'll have to change the file-extension/language association for *.cs in the preferences. You can use this as an opportunity to add associations for *.gui and *.mis as well
- The default color-scheme doesn't do anything special for variables or named identifiers, but you can change this to suit your fancy
- I developed this under Komodo 6.1, but version 7 was released in the last couple days, so I'll be upgrading to that and testing it out there as soon as possible
- For whatever reason, variable names with only a single character aren't lexed as variable tokens. Also, the array[index] syntax can confuse the syntax highlighting in certain scenarios. If you want to take a look at, ponder, and comment on the regex/state-machine code which is used for the lexing, I've embedded it below. It's derived from the example code the Komodo developers provide for JS and PHP lexers, and incorporates TorqueScript specific features which I've extracted
- Tagged (single quoted) strings right now are color coded as regex tokens, since TS doesn't support regex syntax, by default. If you've added that somehow to your installation, let me know and it might motivate me to color it using the markup-tag colors instead.
- I've also added rudimentary auto-indent/dedent code.
[edit]
The forum software breaks code with backslashes. Click here if you want to take a look at the lexer code.
GarageGames Blog #2 wrote:
I've been hard at work on my Python based TorqueScript parser, which will soon be plugged into the code-intelligence portion of my plugin for Komodo Edit.
I made several changes to the Python code generation for the byacc variant I was using, and contacted (read: "stalked on Facebook") the maintainer of the Sourceforge project, which has been inactive for close to a decade, in the hopes of contributing my changes back into the wild. I also rewrote the Torquescript lexer using the Plex library.
Updates from the last blog post:
- I've uploaded a new version of the plugin which should be compatible with all Komodo versions between 4 and 7.
- The link to the Python code for the parser/code-intelligence portion of the project is still here.
- The UDL file for the Scintilla lexer used by Komodo for syntax highlighting is still here (and still has some weirdness).
Finally, for fun, I rendered the AST generated by my parser.
If you have GraphViz, you can check out the .dot file
Otherwise, I've rendered a PNG of it, and uploaded it here
You'll have to download it, because it's ~7MB and 45000x9000 pixels, which makes the Google Drive image preview sad. It may also make your computer sad if you don't have enough RAM to open a picture that large.
And I'll include this snippet that I previously posted as a comment on my last blog, in case anyone is interested and missed it the first time around:
Quote:
I never knew this, but with TorqueScript you can put a type specifier before the field declarations within an object, or datablock declaration. Weird, huh? Anyway, the parser needs to know what types are available to the console, in order to distinguish between them and a normal identifier, so here's some code to dump a python dictionary matching type names to their numeric IDs to the console. I put mine in console/dynamicTypes.cpp
Code:
ConsoleFunction(dumpConsoleTypes, void, 1, 1, "dumpConsoleTypes")
{
Con::printf("gConsoleTypeTable = {");
ConsoleBaseType *walk = ConsoleBaseType::getListHead();
while( walk != NULL )
{
Con::printf(" '%s' : %d,", walk->getTypeName(), walk->getTypeID());
walk = walk->getListNext();
}
Con::printf("}");
}