views:

459

answers:

3

I am looking to get as close as I can to parsing out an AS3 file into objects or XML. For instance, imagine the following class:

package {
   class SomeClass extends AnotherClass {
      private var someVariable:Number

      public function someMethod(someParameter:Number = 4):void {
         var someLocalVariable:Number = someParameter * (2 + someVariable);
      }
   }
}

When parsed, it might be something like:

<package name="">
   <class id="783" name="SomeClass" extendsId="782">
      <variable id="784" visibility="private" type="Number"/>
      <function id="785" name="someMethod" returnType="void">
         <parameter id="786" name="someParameter" type="Number">
            <expression>
               <number value="4"/>
            </expression>
         </parameter>
         <variable id="787" name="someLocalVariable" type="Number"/>
         <code>
            <assign toId="787">
               <expression>
                  <variable id="786"/>
                  <operator type="*"/>
                  <expression>
                     <number value="2"/>
                     <operator type="+"/>
                     <variable id="786"/>
                  </expression>
               </expression>
            </assign>
         </code>
      </function>
   </class>
</package>

.. even if I don't get a nice, neat xml structure like this, even if it could just parse AS3 to some kind of capacity, it would be way beyond where I am now.

Any thoughts?

Thanks, Eric

A: 

Take a look at the flash.utils.describeType() documentation. http://livedocs.adobe.com/flex/gumbo/langref/flash/utils/package.html#describeType()

It's for describe actionscript items at runtime, but should have some use in this case.

ruyadorno
+2  A: 

FlexPMD has an as3 parser. (FlexPMD is a Java project by Adobe that does reporting of best practices violations in as3 source code.)

FlexPMD is hosted at http://opensource.adobe.com/wiki/display/flexpmd/FlexPMD

The code is on a subversion repo at http://opensource.adobe.com/svn/opensource/flexpmd/trunk

The down side is you would need to use Maven to build FlexPMD (me, I never managed to get it to work), but since you need just one or three projects, it might be possible to extract those by hand without too much cursing and shouting.

You may also want to wander further into the Flex SDK source code (also on opensource.adobe.com) to see if Adobe provides any other software for parsing as3,but I have not looked there.

Thomas Dufour
A: 

Hi,

I have actually ported the PMD parser to AS3.

You can check out http://github.com/teotigraphix/as3parser-framework

Mike

Michael Schmalle
The link does not work anymore, looks like it was moved to http://github.com/teotigraphix/asblocks
Simon Groenewolt