Thursday, January 12, 2006

TraverToy3: RB Code Indenter

Something that may be surprising is that the XML file for an RB Project contains no information on the indenting of the code. If you, for example, simply extract the source code information, everything is "flush" with the left margin, i.e., there is no indenting.

So if you want to have properly indented code from the information in the XML files, you'll have to add the formatting yourself, according to the rules that REALbasic itself uses. As far as I know, that information is nowhere documented, but it is not that difficult to figure out.

Here are the rules, discovered from observation. If a line begins with "Case," "Do," "Else," "ElseIf," "Exception," "For," "Select Case," or "While," the following line is indented one level. If a line begins with "Case," "Else," "ElseIf," "End Function," "End Select," "End Sub," "Loop," "Next," or "Wend," that line is outdented one level. If a line begins with "If" and ends with "Then," the following line is indented one level. And if the preceding line end with a "_" (a line continuation character), that linje is indented some extra spaces (but more than one level). That's about all there is to it.

TraverToy3 is able to do three things: (1) Open an XML file and show you the source code with no indents, (2) Open an XML file and show you the appropriate indents, or (3) Open an XML file and (for testing purposes) show you the appropriate indents with the indent level indicated by a number. Thus if you look at all the 1's or all the 2's or all the 3's, etc., you should see related lines (e.g., associated lines beginning with "If," "ElseIf, "Else," and "End If" belonging to the same If/ElseIf/Else/End If statement) having the same number at the beginning of each line.

TraverToy3 is also able to save the results to disk. In Windows, you can also use Copy and Paste to put the EditField text into a plain text editor (such as Notepad for Windows or its equivalent on the Mac) and save the text to disk from there (but I've had mixed reports as to whether that also works on the Mac).

TraverToy3 is a subset extracted from RB CodeHelper Lite, with an additional routine added (the testing routine). It is my hope that the code is "clean," not containing anything extraneous, but it's possible that I may have missed something, so please be tolerant of that.

TraverToy3 contains some useful Methods. For example, MyJoin (which is NOT "My" Join, but Walter Purvis's) is an improvement over the Join contained within REALbasic. You may also want to take a look at routines such as BetweenTags, ConvertHex, CutOffRight, HowMany, IsSource, Mid1, MinNonZero, OutsideQuotes, Rpt, StartsWith, CheckForXMLFile, GetSourceAndComment, GetWholeLine, and ResizeIt, most of which I hope to take a look at in future blog entries.

IMPORTANT: I make no claim that my code is the best way to perform these particular tasks, but simply that it is a way to accomplish certain goals. If you have improvements to sugest, please do so. Just as I hope that you will learn something from this blog, I'm hoping to learn something from this blog as well.

Barry Traver



Home Page for This Blog: http://traverrb.blogspot.com/

Programs and Files Discussed in the Blog: http://traver.org/traverrb/

2 Comments:

At 6:56 PM, Blogger asdf said...

Hello there,

I hear the term realbasic for the first time.. I'm a c++ programmer and new to your langugage. is it similar to VB or java ?

Check out my blog if you find anything interest..
Id like to subscribe to your blog . if you use blogrolling.

 
At 7:40 AM, Blogger Barry Traver said...

squire,

REALbasic is very similar to VB, with a number of important differences, including the following:

(1) REALbasic is cross-platform. The same code will run in Windows, on the Mac, and on Linux.

(2) With REALbasic, you don't have a
humongous runtime file or a complicated installation to worry about. You can put your executable program into a single file which can be run directly from a CD-ROM>

Try it; you'll like it!

Barry

 

Post a Comment

<< Home