ActionScript Expression Evaluation in Cylon for Amethyst
The current beta version of the Amethyst Cylon debugger has most of what is needed to for a first class Flash debugger. It’s got breakpoints (naturally), conditional breakpoints, a console for tracing, call stack and hierarchical property expansion in the Watch Window - and many other things beside. But what it is missing is an Expression Evaluator that lets you type arbitrary expressions like ‘a.b(d, e)’ . Until now, that is.
In Visual Studio, there are two places you can type expressions for evaluation – the Watch Window and the Immediate Window. The former, the Watch Window, is usually used for variables and has a nice hierarchical expansion system whereby you can ‘drill-down’ into the interior of an object.
But you can also use the Watch Window for more complicated expressions. Take for example, a humble Boolean variable, zz. If you just type it into the watch window, you will see this:
You can also (now in the latest Cylon) call a function like this:
The first example evaluates to a Boolean value, true, while the second gives the string representation of the Boolean “true”.
But the Watch Window has its limitations. You can’t recall a line that you typed in – and you are also limited in space. Enter the Immediate Window!
The Immediate Window is a full text window. It has command recall, you can move around in it using the cursor, and in general, it’s much more like a highly versatile scratch pad rather than the structured Watch Window.
In the Immediate Window, I can type arithmetic expressions like
(v + 3) * 4
and get the correct answer:
I can also do much more complicated things as well. To illustrate this, I’ve used an example from the book “Essential ActionScript 3.0” by Colin Moock. On p362, there’s a simple example of some XML code:
Now, I’m not an ActionScript programmer (I use C# mostly with excursions into various Assembly languages when required). One of the things about ActionScript that’s puzzled me was the use of the XML operators @ and .. and their various permutations. So I used the example to explore XML (and to check that the Cylon Expression Evaluator was doing its stuff).
OK – that’s as expected. But there’s an ActionScript optimization: if there’s only one XML node in an XMLList, you can leave out the indexer:
Yes, that works too (with a bit of internal Cylon magic, I might add).
So, how about some attributes?
also behaves as expected:
Lastly, here’s how descendant’s work. The example is slightly more complex - an XML structure have two books inside it:
Using the descendent operator, I can obtain this:
But there’s one thing I really like about ActionScript (and I wish C# would adopt something like this) – Regular Expressions are first class objects. My problem with Regular Expressions is that I can never, ever, remember the syntax sufficiently well to get the things to work first (or even second time...). With the Immediate Window, I can experiment using Regular Expression literals. For example, here’s one from Adobe’s web site (note the IntelliSense completion list generated when I typed the dot):
I want to use the test function to see if the string "Class-A" matches:
and I get the result:
Internally, the Cylon Expression Evaluator uses the same ANTLR LL(*) parser that generates the information for Amethyst’s coloring and IntelliSense system. It’s very satisfying when the IntelliSense system (which is generated in the Visual Studio IDE) meshes perfectly with the Cylon Expression Evaluator, which is linked to the IDE, but is actually independent. That’s one very odd feature of Visual Studio: the debugging system is by design a completely separate entity from the core IDE. I’m not sure why this is, and it certainly leads to some difficult problems in implementation. But when it all works, you really do get a truly great debugging system.
You mentioned that you can enter expressions in Visual Studio in the Watch and the Immediate windows. There is another window in which expressions can be entered, the Quick Watch window (Ctrl-Alt-Q or Ctrl-D, Q).
Thanks for the reminder. I’ve just had a word with Dermot and told him to get working on it! :-)