Game Development Community

Making Torquescript a VS 2005 Language

by Jody Byrd · in Torque Game Engine · 08/31/2006 (10:30 am) · 9 replies

Well, I couldn't take it anymore, I went into that dragon's lair.

Now that I got TGE recognizing .ts files, I just had to get VS2005 recognizing them too. So, I re-opened my VS 2005 SDk, and re-started reading the help files. Turns out, the Visual Studio Language Package wizard does all the work for us. It builds a complete project with all our tokens, turns on/off color syntaxing, and a few other options. Though, to really tweak it, you have to build a lot of the functionality by hand. As in, the hard part of the help files that I thought I had to do. I knew the SDK had a simple C language example called MyC, and since Torquescript is C-like, so I figured that I could get something "simple" working for .ts files.

Here's what I used:

1) VS2005 Pro
2) VS2005 SDK (April 2006)
3) bison/flexx from TGE 1.4 (no updates from the HEAD)

#1
08/31/2006 (10:30 am)
Step 1: Install VS 2005 SDK

If you don't already have it loaded :),

goto msdn.microsoft.com

on the menu, click on "Visual Studio", that should take you to the "Visual Studio Development Center"

on that menu, click on "Extensibility Center"

On that page, you'll see a "Download the SDK" button

You'll have to register with Microsoft in order to download the sdk. Its big, and takes awhile to install.
#2
08/31/2006 (10:31 am)
Step 2: Copy Bison and Flex

Before we get to far, you need to install flex and bison for the default wizards. Microsoft does not provide bison or flex, if they do, I dont know where they are. But GG does :) in the torque \Bin directory.

The help file said the install directory is one thing, written in generic path format, but the wizard points (on my machine) "C:\Program Files\Visual Studio 2005 SDK\2006.04\VisualStudioIntegration\Archive\Babel\tools\"
which I had to make. then I copied bison.exe, bison.hairy, bison.simple, and flex.exe to there.
#3
08/31/2006 (10:32 am)
Step 3: Create a new language package

1) from the menu, click File->New->Project

2) in the "New Project" window, under "Other Project Types","Extensibility", select
"Visual Studio Language Package"

set the solution path location.

I called my solution "TorqueScriptLangPackage"

3) click "Ok"

The "Visual Studio Language Service Wizard" opens

4) Click "Next" to begin

5) on "Page 1 of 4"
Enter the language name, I call mine "TorqueScript"
for a file extension, i used ".ts"
Click "Next"

6) on "Page 2 of 4"

This is where we can define custom lex and yacc files, along with custom bison and flex apps. Remember earlier, I had you copy them. I'm not a expert with lex and yacc, so I used the defaults, that will build a MyC project.

Click "Next"

7) on "Page 3 of 4"

I enabled Syntax coloring, since thats my goal.

I disabled syntax checking, cause I think I have to create custom classes. Well, at least that should get rid of the sqiggly lines.

I enabled block commenting

I could not get brace matching to work, I need more research. But I left it on.

I disabled statement completion, cause I not looking for that feature yet.

I not sure in quick info will work yet, so I disabled it.

Click "Next"

8) on "Page 4 of 4"

Now, here's where you define what a token is to the vs editor.

You have to click the "Load button", and that loads all the tokens defined in your grammer files, In this case, the example MyC tokens.

Select a token, like KWIF (the If Keyword), notice the ColorClass is set to "ClassDefault". Well, all the tokens are set to that. We have to change them. Some wizard. However, later we can change them in the code. So for now, just change KWIF to ClassKeyword, and set the Char Class to CharKeyword. Make sure you click "Apply" or it wont save it.

Click "Finish" to build the solution.
#4
08/31/2006 (10:33 am)
Step 4: Testing what we got

1) Go ahead and build the solution.

2) Right now, it only registers with the Experimental version of Vs2005. Thats a special version that you can test things with and not destroy your main copy. To load the EXP version:

a) start the VS command prompt:
from Start->All Programs-Microsoft Visual Studio 2005->Visual Studio Tools->Visual Studio 2005 Command Prompt

b) type in:

devenv /rootsuffix EXP

3) Once loaded, open a torquescript file (make sure the extension is change to .ts)

Look for a if statement, and see if the colors are working. Mine are blue.

Close out of the EXP version.
#5
08/31/2006 (10:34 am)
Step 5: Hacking the Solution.

1) Look in the service.cpp file. The tokenInfoTable is where we make changes to the colors. Notice KWIF, we had set that to ClassKeyword. You can change the other tokens from here.

2) I switched the solution to Release mode.

3) The default dll is named "bservice.dll". You need to change this. I called mine "TorqueScriptService.dll". That's under the project properties, "Configuration Properties", "linker", "general", "Output File"

4) Look under "Build Events", "Post Build Event", "Command Line". Notice the path to regit.exe. We'll need that shortly.

5) rebuild the solution
#6
08/31/2006 (10:34 am)
Step 6: Installing the dll

1) make a directory to put your dll file.

2) Copy the dll file from the release directory, and I copied the manifest file just in case. For me, that was TorqueScriptService.dll and TorqueScriptService.dll.intermediate.manifest

3) Copy regit.exe.

C:\Program Files\Visual Studio 2005 SDK\2006.04\VisualStudioIntegration\tools\bin\

4) I made a batch file , or you can manual exec it, either way, run this command from your dll directory:

RegIt /root:Software\Microsoft\VisualStudio.0 TorqueScriptService.dll

Notice I'm using \8.0 instead of \8.0exp like the post build event was. You guessed it, \8.0exp is for the Experimental version. \8.0 is the real thing.

5) If you want to uninstall it

RegIt /u TorqueScriptService.dll

6) On my machine, I had already set .ts file to be loaded by Vs2005. So I cant say if you need to associate them. Now, VS2005 will color syntax a .ts file when opened.
#7
08/31/2006 (10:37 am)
Step 7: Now just to go back and transfer the BASgram.y, BASscan.l, CMDgram.y, and CMDscan.l info from \engine\console

Thanks for reading,
Jody
#8
08/31/2006 (10:44 am)
Do you have a link on tutorials for having torquescript read .ts instead of .cs? Great article btw.
#9
08/31/2006 (10:49 am)
I was referring to my last post:

www.garagegames.com/mg/forums/result.thread.php?qt=49813