Home > Uncategorized > as3parser-framework :: Introducing the AS3FragmentParser

as3parser-framework :: Introducing the AS3FragmentParser

Hi,

Well the I figured the framework needed a static API to access the AS3Parsers internal parse methods. I finally got around to making this and unit testing it to the point of insanity. This was for a special purpose though, the TestAS3FragmentParser unit test is more like a guide on what you can pass each method. If you haven’t checked out that unit test, you should.

Wiki Docs;

The below link shows usage and XML AST information for every method listed below, you should check it out if your interested in the AST models.

AS3FragmentParser API

Source for the unit test;

AS3FragmentParser Unit test

Parse methods;

  • parseCompilationUnit()
  • parsePackage()
  • parsePackageContent()
  • parseClassContent()
  • parseInterfaceContent()
  • parseMetaData()
  • parseConstants()
  • parseVariables()
  • parseMethods()
  • parseStatement()
  • parsePrimaryExpression()
  • parseExpression()

An example of what you will find on the wiki page.

parseCompilationUnit()

Usage:

var ast:IParserNode = AS3FragmentParser.parseCompilationUnit(source);
// convoluted example but shows nesting
trace(ast.getChild(0).getChild(0).stringValue); // my.domain
trace(ast.getChild(0).getLastChild().getChild(0).getChild(0).stringValue); // Test
trace(ast.getChild(0).getLastChild().getChild(0).getKind("mod").stringValue); // public

Source:

package my.domain
{
	public class Test
	{
	}
}
class InternalClass
{
}

AST:

<compilation-unit>
	<package>
		<name>my.domain</name>
		<content>
			<class>
				<name>Test</name>
				<mod-list>
					<mod>public</mod>
				</mod-list>
				<content></content>
			</class>
		</content>
	</package>
	<content>
		<class>
			<name>InternalClass</name>
			<content></content>
		</class>
	</content>
</compilation-unit>

Why ?

This class was written because I’m getting into the BLOCK building, yes, you will be able to create expressions!

Mike

Categories: Uncategorized Tags:
  1. August 23rd, 2010 at 09:10 | #1

    Oh my word… it gets better and better! Good job!

*