C# Class Spring.Expressions.Parser.antlr.ASTFactory

AST Support code shared by TreeParser and Parser.

We use delegation to share code (and have only one bit of code to maintain) rather than subclassing or superclassing (forces AST support code to be loaded even when you don't want to do AST stuff).

Typically, setASTNodeType is used to specify the homogeneous type of node to create, but you can override create() to make heterogeneous nodes etc...

Datei anzeigen Open project: spring-projects/spring-net Class Usage Examples

Protected Properties

Property Type Description
defaultASTNodeTypeObject_ Type
defaultCreator_ ASTNodeCreator
heteroList_ FactoryEntry[]
typename2creator_ Hashtable

Public Methods

Method Description
ASTFactory ( ) : System

Constructs an ASTFactory with the default AST node type of antlr.CommonAST.

ASTFactory ( Type nodeType ) : System

Constructs an ASTFactory and use the specified AST node type as the default.

ASTFactory ( string nodeTypeName ) : System

Constructs an ASTFactory and use the specified AST node type as the default.

addASTChild ( ASTPair &currentAST, Spring.Expressions.Parser.antlr.collections.AST child ) : void

Add a child to the current AST

create ( ) : Spring.Expressions.Parser.antlr.collections.AST

Creates a new uninitialized AST node. Since a specific AST Node Type wasn't indicated, the new AST node is created using the current default AST Node type - defaultASTNodeTypeObject_

create ( IToken tok ) : Spring.Expressions.Parser.antlr.collections.AST

Creates and initializes a new AST node using the specified Token instance. The System.Type used for creating this new AST node is determined by the following: the current TokenTypeID-to-ASTNodeType mapping (if any) or, the defaultASTNodeTypeObject_ otherwise

create ( IToken tok, string ASTNodeTypeName ) : Spring.Expressions.Parser.antlr.collections.AST

Creates a new AST node using the specified AST Node Type name.

Once created, the new AST node is initialized with the specified Token instance. The System.Type used for creating this new AST node is determined solely by ASTNodeTypeName.

The AST Node type must have a default/parameterless constructor.

create ( Spring.Expressions.Parser.antlr.collections.AST aNode ) : Spring.Expressions.Parser.antlr.collections.AST

Creates and initializes a new AST node using the specified AST Node instance. the new AST node is initialized with the specified Token type ID and string. The System.Type used for creating this new AST node is determined solely by aNode. The AST Node type must have a default/parameterless constructor.

create ( int type ) : Spring.Expressions.Parser.antlr.collections.AST

Creates and initializes a new AST node using the specified Token Type ID. The System.Type used for creating this new AST node is determined by the following: the current TokenTypeID-to-ASTNodeType mapping (if any) or, the defaultASTNodeTypeObject_ otherwise

create ( int type, string txt ) : Spring.Expressions.Parser.antlr.collections.AST

Creates and initializes a new AST node using the specified Token Type ID. The System.Type used for creating this new AST node is determined by the following: the current TokenTypeID-to-ASTNodeType mapping (if any) or, the defaultASTNodeTypeObject_ otherwise

create ( int type, string txt, string ASTNodeTypeName ) : Spring.Expressions.Parser.antlr.collections.AST

Creates a new AST node using the specified AST Node Type name. Once created, the new AST node is initialized with the specified Token type ID and string. The System.Type used for creating this new AST node is determined solely by ASTNodeTypeName. The AST Node type must have a default/parameterless constructor.

dup ( Spring.Expressions.Parser.antlr.collections.AST t ) : Spring.Expressions.Parser.antlr.collections.AST

Returns a copy of the specified AST Node instance. The copy is obtained by using the ICloneable method Clone().

dupList ( Spring.Expressions.Parser.antlr.collections.AST t ) : Spring.Expressions.Parser.antlr.collections.AST

Duplicate AST Node tree rooted at specified AST node and all of it's siblings.

dupTree ( Spring.Expressions.Parser.antlr.collections.AST t ) : Spring.Expressions.Parser.antlr.collections.AST

Duplicate AST Node tree rooted at specified AST node. Ignore it's siblings.

error ( string e ) : void

To change where error messages go, can subclass/override this method and then setASTFactory in Parser and TreeParser. This method removes a prior dependency on class antlr.Tool.

make ( ) : Spring.Expressions.Parser.antlr.collections.AST

Make a tree from a list of nodes. The first element in the array is the root. If the root is null, then the tree is a simple list not a tree. Handles null children nodes correctly. For example, build(a, b, null, c) yields tree (a b c). build(null,a,b) yields tree (nil a b).

make ( Spring.Expressions.Parser.antlr.collections.impl.ASTArray nodes ) : Spring.Expressions.Parser.antlr.collections.AST

Make a tree from a list of nodes, where the nodes are contained in an ASTArray object.

makeASTRoot ( ASTPair &currentAST, Spring.Expressions.Parser.antlr.collections.AST root ) : void

Make an AST the root of current AST.

setASTNodeCreator ( ASTNodeCreator creator ) : void

Register an ASTNodeCreator to be used for creating node by default.

setASTNodeType ( string t ) : void

Sets the global default AST Node Type for this ASTFactory instance. This method also attempts to load the System.Type instance for the specified typename.

setMaxNodeType ( int NodeType ) : void

Pre-expands the internal list of TokenTypeID-to-ASTNodeType mappings to the specified size. This is primarily a convenience method that can be used to prevent unnecessary and costly re-org of the mappings list.

setTokenTypeASTNodeCreator ( int NodeType, ASTNodeCreator creator ) : void

Register an ASTNodeCreator for a given Token type ID.

setTokenTypeASTNodeType ( int tokenType, string NodeTypeName ) : void

Specify an "override" for the AST type created for the specified Token type.

This method is useful for situations that ANTLR cannot oridinarily deal with (i.e., when you create a token based upon a nonliteral token symbol like #[LT(1)]. This is a runtime value and ANTLR cannot determine the token type (and hence the AST) statically.

Private Methods

Method Description
createFromAST ( Spring.Expressions.Parser.antlr.collections.AST node ) : Spring.Expressions.Parser.antlr.collections.AST
createFromNodeName ( string nodeTypeName ) : Spring.Expressions.Parser.antlr.collections.AST
createFromNodeType ( int nodeTypeIndex ) : Spring.Expressions.Parser.antlr.collections.AST
createFromNodeTypeObject ( Type nodeTypeObject ) : Spring.Expressions.Parser.antlr.collections.AST
loadNodeTypeObject ( string nodeTypeName ) : Type
registerFactory ( int NodeType, string NodeTypeName ) : void

Method Details

ASTFactory() public method

Constructs an ASTFactory with the default AST node type of antlr.CommonAST.
public ASTFactory ( ) : System
return System

ASTFactory() public method

Constructs an ASTFactory and use the specified AST node type as the default.
public ASTFactory ( Type nodeType ) : System
nodeType System.Type /// MetaType of default AST node type for this factory. ///
return System

ASTFactory() public method

Constructs an ASTFactory and use the specified AST node type as the default.
public ASTFactory ( string nodeTypeName ) : System
nodeTypeName string /// Name of default AST node type for this factory. ///
return System

addASTChild() public method

Add a child to the current AST
public addASTChild ( ASTPair &currentAST, Spring.Expressions.Parser.antlr.collections.AST child ) : void
currentAST ASTPair The AST to add a child to
child Spring.Expressions.Parser.antlr.collections.AST The child AST to be added
return void

create() public method

Creates a new uninitialized AST node. Since a specific AST Node Type wasn't indicated, the new AST node is created using the current default AST Node type - defaultASTNodeTypeObject_
public create ( ) : Spring.Expressions.Parser.antlr.collections.AST
return Spring.Expressions.Parser.antlr.collections.AST

create() public method

Creates and initializes a new AST node using the specified Token instance. The System.Type used for creating this new AST node is determined by the following: the current TokenTypeID-to-ASTNodeType mapping (if any) or, the defaultASTNodeTypeObject_ otherwise
public create ( IToken tok ) : Spring.Expressions.Parser.antlr.collections.AST
tok IToken Token instance to be used to create new AST Node.
return Spring.Expressions.Parser.antlr.collections.AST

create() public method

Creates a new AST node using the specified AST Node Type name.
Once created, the new AST node is initialized with the specified Token instance. The System.Type used for creating this new AST node is determined solely by ASTNodeTypeName.

The AST Node type must have a default/parameterless constructor.

public create ( IToken tok, string ASTNodeTypeName ) : Spring.Expressions.Parser.antlr.collections.AST
tok IToken Token instance to be used to initialize the new AST Node.
ASTNodeTypeName string /// Fully qualified name of the Type to be used for creating the new AST Node. ///
return Spring.Expressions.Parser.antlr.collections.AST

create() public method

Creates and initializes a new AST node using the specified AST Node instance. the new AST node is initialized with the specified Token type ID and string. The System.Type used for creating this new AST node is determined solely by aNode. The AST Node type must have a default/parameterless constructor.
public create ( Spring.Expressions.Parser.antlr.collections.AST aNode ) : Spring.Expressions.Parser.antlr.collections.AST
aNode Spring.Expressions.Parser.antlr.collections.AST AST Node instance to be used for creating the new AST Node.
return Spring.Expressions.Parser.antlr.collections.AST

create() public method

Creates and initializes a new AST node using the specified Token Type ID. The System.Type used for creating this new AST node is determined by the following: the current TokenTypeID-to-ASTNodeType mapping (if any) or, the defaultASTNodeTypeObject_ otherwise
public create ( int type ) : Spring.Expressions.Parser.antlr.collections.AST
type int Token type ID to be used to create new AST Node.
return Spring.Expressions.Parser.antlr.collections.AST

create() public method

Creates and initializes a new AST node using the specified Token Type ID. The System.Type used for creating this new AST node is determined by the following: the current TokenTypeID-to-ASTNodeType mapping (if any) or, the defaultASTNodeTypeObject_ otherwise
public create ( int type, string txt ) : Spring.Expressions.Parser.antlr.collections.AST
type int Token type ID to be used to create new AST Node.
txt string Text for initializing the new AST Node.
return Spring.Expressions.Parser.antlr.collections.AST

create() public method

Creates a new AST node using the specified AST Node Type name. Once created, the new AST node is initialized with the specified Token type ID and string. The System.Type used for creating this new AST node is determined solely by ASTNodeTypeName. The AST Node type must have a default/parameterless constructor.
public create ( int type, string txt, string ASTNodeTypeName ) : Spring.Expressions.Parser.antlr.collections.AST
type int Token type ID to be used to create new AST Node.
txt string Text for initializing the new AST Node.
ASTNodeTypeName string Fully qualified name of the Type to be used for creating the new AST Node.
return Spring.Expressions.Parser.antlr.collections.AST

dup() public method

Returns a copy of the specified AST Node instance. The copy is obtained by using the ICloneable method Clone().
public dup ( Spring.Expressions.Parser.antlr.collections.AST t ) : Spring.Expressions.Parser.antlr.collections.AST
t Spring.Expressions.Parser.antlr.collections.AST AST Node to copy.
return Spring.Expressions.Parser.antlr.collections.AST

dupList() public method

Duplicate AST Node tree rooted at specified AST node and all of it's siblings.
public dupList ( Spring.Expressions.Parser.antlr.collections.AST t ) : Spring.Expressions.Parser.antlr.collections.AST
t Spring.Expressions.Parser.antlr.collections.AST Root of AST Node tree.
return Spring.Expressions.Parser.antlr.collections.AST

dupTree() public method

Duplicate AST Node tree rooted at specified AST node. Ignore it's siblings.
public dupTree ( Spring.Expressions.Parser.antlr.collections.AST t ) : Spring.Expressions.Parser.antlr.collections.AST
t Spring.Expressions.Parser.antlr.collections.AST Root of AST Node tree.
return Spring.Expressions.Parser.antlr.collections.AST

error() public method

To change where error messages go, can subclass/override this method and then setASTFactory in Parser and TreeParser. This method removes a prior dependency on class antlr.Tool.
public error ( string e ) : void
e string
return void

make() public method

Make a tree from a list of nodes. The first element in the array is the root. If the root is null, then the tree is a simple list not a tree. Handles null children nodes correctly. For example, build(a, b, null, c) yields tree (a b c). build(null,a,b) yields tree (nil a b).
public make ( ) : Spring.Expressions.Parser.antlr.collections.AST
return Spring.Expressions.Parser.antlr.collections.AST

make() public method

Make a tree from a list of nodes, where the nodes are contained in an ASTArray object.
public make ( Spring.Expressions.Parser.antlr.collections.impl.ASTArray nodes ) : Spring.Expressions.Parser.antlr.collections.AST
nodes Spring.Expressions.Parser.antlr.collections.impl.ASTArray List of Nodes.
return Spring.Expressions.Parser.antlr.collections.AST

makeASTRoot() public method

Make an AST the root of current AST.
public makeASTRoot ( ASTPair &currentAST, Spring.Expressions.Parser.antlr.collections.AST root ) : void
currentAST ASTPair
root Spring.Expressions.Parser.antlr.collections.AST
return void

setASTNodeCreator() public method

Register an ASTNodeCreator to be used for creating node by default.
public setASTNodeCreator ( ASTNodeCreator creator ) : void
creator ASTNodeCreator The ASTNodeCreator.
return void

setASTNodeType() public method

Sets the global default AST Node Type for this ASTFactory instance. This method also attempts to load the System.Type instance for the specified typename.
public setASTNodeType ( string t ) : void
t string Fully qualified AST Node Type name.
return void

setMaxNodeType() public method

Pre-expands the internal list of TokenTypeID-to-ASTNodeType mappings to the specified size. This is primarily a convenience method that can be used to prevent unnecessary and costly re-org of the mappings list.
public setMaxNodeType ( int NodeType ) : void
NodeType int Maximum Token Type ID.
return void

setTokenTypeASTNodeCreator() public method

Register an ASTNodeCreator for a given Token type ID.
public setTokenTypeASTNodeCreator ( int NodeType, ASTNodeCreator creator ) : void
NodeType int The Token type ID.
creator ASTNodeCreator The creater to register.
return void

setTokenTypeASTNodeType() public method

Specify an "override" for the AST type created for the specified Token type.
This method is useful for situations that ANTLR cannot oridinarily deal with (i.e., when you create a token based upon a nonliteral token symbol like #[LT(1)]. This is a runtime value and ANTLR cannot determine the token type (and hence the AST) statically.
public setTokenTypeASTNodeType ( int tokenType, string NodeTypeName ) : void
tokenType int Token type to override.
NodeTypeName string /// Fully qualified AST typename (or null to specify /// the factory's default AST type). ///
return void

Property Details

defaultASTNodeTypeObject_ protected_oe property

Stores the Type of the default AST node class to be used during tree construction.
protected Type defaultASTNodeTypeObject_
return Type

defaultCreator_ protected_oe property

protected ASTNodeCreator defaultCreator_
return ASTNodeCreator

heteroList_ protected_oe property

Stores the mapping between custom AST NodeTypes and their NodeTypeName/NodeTypeClass and ASTNodeCreator.
protected FactoryEntry[] heteroList_
return FactoryEntry[]

typename2creator_ protected_oe property

Stores the mapping between AST node typenames and their token ID.
protected Hashtable typename2creator_
return Hashtable