Home > Uncategorized > as3parser-framework :: Facelift – asblocks & asbuilder

as3parser-framework :: Facelift – asblocks & asbuilder

Hi,

Well the last 2 weeks have been very productive. The as3nodes framework is retired, with the metaas DOM implemented. I talked with David Holroyd and have his very encouraging consent to use his API. The metaas Java framework was designed to parse and create AS3 code using antlr and a Document Object Model designed by David.

Davids quote to me;

“There is a lovely symmetry to being able to manipulate the source code of a language within the language itself!”

There have been significant changes in the project within the last 2 weeks;

  • The as3parser and DOM has their repository changed to asblocks
  • The as3builder-framework was changed to asbuilder and now lives at asbuilder
  • The majority of the parser and actionscript read/write DOM implementation is located in the asblocks repository.
  • The asbuilder repository will hold all classes key to the AIR desktop implementation of the IASProject.

For now, the asbook package is missing, that will be reimplemented using the new DOM.

As it stands the asblocks code right now can almost create any type, method, member, expression or statement in ActionScript3! :)

Check it out; This wiki got deprecated, that will be updated as well with a new sub domain asblocks.

The focus has shifted to read-write actionscript instead of the “parser”.

In the spirit of metaas, the following API;

Code:

var factory:ASFactory = new ASFactory();
var project:ASProject = factory.newEmptyASProject(".") as ASProject;
var unit:ICompilationUnit = project.newClass("Test");
var clazz:IClassType = unit.typeNode as IClassType;
var method:IMethod = clazz.newMethod("test", Visibility.PUBLIC, "void");
method.addStatement("trace('Hello world')");
project.writeAll();

Output:

package {
	public class Test {
		public function test():void {
			trace('Hello world');
		}
	}
}

Oh yeah here is another fun one;

Code:

var statement:IBlock = factory.newBlock();
var ifst:IIfStatement = statement.newIf(factory.newExpression("test()"));
ifst.addStatement("trace('test succeeded')");
ifst.elseBlock.addStatement("trace('test failed')");
var ifstSub:IIfStatement = ifst.newIf(factory.newExpression("test2()"));
ifstSub.addStatement("trace('sub test succeeded')");
ifstSub.elseBlock.addStatement("trace('sub test failed')");

Output:

{
	if (test()) {
		trace('test succeeded');
		if (test2()) {
			trace('sub test succeeded');
		} else {
			trace('sub test failed');
		}
	} else {
		trace('test failed');
	}
}

Mike

PS There is a lot more to come now, the was a BIG hurdle, but it’s implemented now!

Categories: Uncategorized Tags:
  1. No comments yet.
*