MethodParser

Reverse engineering parser for generated AS3 script methods

Summary
MethodParserReverse engineering parser for generated AS3 script methods
Private constants
multiLineCommentBeginRegex token for begin of a comment block.
multiLineCommentEndRegex token for end of a comment block.
singleLineCommentRegex token for a comment to end of line.
actionKeywordsRegex tokens for recognized graphics actions.
propertyKeywordsRegex tokens for recognized graphics properties.
Parsed general properties
assetNameName of the graphical asset.
classTypeAsset class type.
xMinMinumum X in the asset’s local reference coordinate system
yMinMinumum Y in the asset’s local reference coordinate system
xMaxMaximum X in the asset’s local reference coordinate system
yMaxMaximum Y in the asset’s local reference coordinate system
Parsed stroke properties
alphaAsset alpha transparency level
rotationRotation of asset relative to its parent
scaleXHorizontal scaling of the asset
scaleYVertical scaling of the asset
xHorizontal offset of the asset relative to its parent
yVertical offset of the asset relative to its parent
Parsed stroke actions
actionsArray of graphical actions defining the asset.
Public methods
parseParse a method script.
disposeDispose of references and reset variables.
Private methods
parseAssetNameScans for an asset name, updates assetName if found.
parseClassTypeScans for a class type, updates classType if found.
parseDimensionsScans for local reference coordinate system dimensions, updates xMin, yMin, xMax, yMax if found.
parsePropertiesScans for display properties, updates dynamically properties on the parser as they are found.
parseActionsScans for actionKeywords method calls.
parseParametersScans action method call parameters, pushes found parameters on the given paramArray reference.
parseArrayScans an embedded array parameter from a method call for its values.
Public static helper
stripCommentsStrip comments from a script.
String conversion
toStringTransforms parsed properties into a form suitable for debugging.

Private constants

multiLineCommentBegin

private static const multiLineCommentBegin: String

Regex token for begin of a comment block.

multiLineCommentEnd

private static const multiLineCommentEnd: String

Regex token for end of a comment block.

singleLineComment

private static const singleLineComment: String

Regex token for a comment to end of line.

actionKeywords

private const actionKeywords: String

Regex tokens for recognized graphics actions.

Recognized actions

LinesmoveTo, lineTo, curveTo, lineStyle
FillsbeginFill, endFill, createGradientBox, beginGradientFill
ObjectsdrawCircle, drawEllipse, drawRect, drawRoundRect
FiltersBevelFilter, BlurFilter, DropShadowFilter
TweensTween, TweenEx, AdvancedTween, PathTween

propertyKeywords

private const propertyKeywords: String

Regex tokens for recognized graphics properties.

Recognized properties

Displayalpha, rotation, scaleX, scaleY, x, y

Parsed general properties

assetName

public var assetName: String

Name of the graphical asset.

classType

public var classType: String

Asset class type.  For example Shape, Sprite or Path.

xMin

public var xMin: Number

Minumum X in the asset’s local reference coordinate system

yMin

public var yMin: Number

Minumum Y in the asset’s local reference coordinate system

xMax

public var xMax: Number

Maximum X in the asset’s local reference coordinate system

yMax

public var yMax: Number

Maximum Y in the asset’s local reference coordinate system

Parsed stroke properties

alpha

public var alpha: Number

Asset alpha transparency level

rotation

public var rotation: Number

Rotation of asset relative to its parent

scaleX

public var scaleX: Number

Horizontal scaling of the asset

scaleY

public var scaleY: Number

Vertical scaling of the asset

x

public var x: Number

Horizontal offset of the asset relative to its parent

y

public var y: Number

Vertical offset of the asset relative to its parent

Parsed stroke actions

actions

public var actions: Array

Array of graphical actions defining the asset.

Each action item is an Object with an actionName property as defined in actionKeywords and a params property giving the parameters for the action.  A parameter can be an embedded array of parameters.

See also

toString

Public methods

parse

public function parse(scriptText: String):void

Parse a method script.  Recognized properties in the script are placed in the class properties.  Properties which were not defined in the script will have their default null/NaN values.

Parameters

scriptTexttext of a script for a graphical asset method

dispose

public function dispose():void

Dispose of references and reset variables.

Private methods

parseAssetName

private function parseAssetName(script: String):void

Scans for an asset name, updates assetName if found.

First looks for an assignment to a name property, if not found then looks to extract the name from the method name if it is a createAsset method.

Parameters

scriptTexttext of a script for a graphical asset method

parseClassType

private function parseClassType(script: String):void

Scans for a class type, updates classType if found.

Looks to extract the return type from the method if it is a createAsset method.

Parameters

scriptTexttext of a script for a graphical asset method

parseDimensions

private function parseDimensions(script: String):void

Scans for local reference coordinate system dimensions, updates xMin, yMin, xMax, yMax if found.

Looks for a pattern beginning with ‘Coordinate system’.  This information is contained in a comment so parsing should be performed before comments are stripped.

The coordinate system is not essential to recover the definition of an asset, it is used to present the asset in the same way it was defined.

Parameters

scriptTexttext of a script for a graphical asset method

parseProperties

private function parseProperties(script: String):void

Scans for display properties, updates dynamically properties on the parser as they are found.  See: Parsed stroke properties.

Looks for assignments to defined propertyKeywords.

Parameters

scriptTexttext of a script for a graphical asset method

parseActions

private function parseActions(script: String):void

Scans for actionKeywords method calls.  Found actions are pushed into the actions array as objects with an actionName string and a params array.

Parameters

scriptTexttext of a script for a graphical asset method

parseParameters

private function parseParameters(paramList: String,
paramArray: Array):void

Scans action method call parameters, pushes found parameters on the given paramArray reference.  Looks to distinguish simple parameters and embedded arrays.

Parameters

paramListscript text as found between parentheses on a method call
paramArrayarray where parameters can be placed as strings or arrays

parseArray

private function parseArray(paramList: String):Array

Scans an embedded array parameter from a method call for its values.

Parameters

paramListscript text as found with brackets in a method call parameter

Returns

Array of array values as strings

Public static helper

stripComments

public static function stripComments(script: String):String

Strip comments from a script.

Parameters

scriptTextscript text with comments

Returns

Script text without comments

String conversion

toString

public function toString():String

Transforms parsed properties into a form suitable for debugging.

private static const multiLineCommentBegin: String
Regex token for begin of a comment block.
private static const multiLineCommentEnd: String
Regex token for end of a comment block.
private static const singleLineComment: String
Regex token for a comment to end of line.
private const actionKeywords: String
Regex tokens for recognized graphics actions.
private const propertyKeywords: String
Regex tokens for recognized graphics properties.
public var assetName: String
Name of the graphical asset.
public var classType: String
Asset class type.
public var xMin: Number
Minumum X in the asset’s local reference coordinate system
public var yMin: Number
Minumum Y in the asset’s local reference coordinate system
public var xMax: Number
Maximum X in the asset’s local reference coordinate system
public var yMax: Number
Maximum Y in the asset’s local reference coordinate system
public var alpha: Number
Asset alpha transparency level
public var rotation: Number
Rotation of asset relative to its parent
public var scaleX: Number
Horizontal scaling of the asset
public var scaleY: Number
Vertical scaling of the asset
public var x: Number
Horizontal offset of the asset relative to its parent
public var y: Number
Vertical offset of the asset relative to its parent
public var actions: Array
Array of graphical actions defining the asset.
public function parse(scriptText: String):void
Parse a method script.
public function dispose():void
Dispose of references and reset variables.
private function parseAssetName(script: String):void
Scans for an asset name, updates assetName if found.
private function parseClassType(script: String):void
Scans for a class type, updates classType if found.
private function parseDimensions(script: String):void
Scans for local reference coordinate system dimensions, updates xMin, yMin, xMax, yMax if found.
private function parseProperties(script: String):void
Scans for display properties, updates dynamically properties on the parser as they are found.
private function parseActions(script: String):void
Scans for actionKeywords method calls.
private function parseParameters(paramList: String,
paramArray: Array):void
Scans action method call parameters, pushes found parameters on the given paramArray reference.
private function parseArray(paramList: String):Array
Scans an embedded array parameter from a method call for its values.
public static function stripComments(script: String):String
Strip comments from a script.
public function toString():String
Transforms parsed properties into a form suitable for debugging.
Close