C# Class Loyc.Ecs.EcsValidators

A class filled with methods for checking whether a node has the correct LNode.Name and structure. For example, IsPropertyDefinition(node) checks whether node meets the requirements for being a property definition, such as having a Name equal to #property, and having name and return value that are complex identifiers.
This class also has useful helper functions, such as KeyNameComponentOf(LNode).
Exibir arquivo Open project: qwertie/ecsharp Class Usage Examples

Public Methods

Method Description
ExecutableBlockStmtType ( LNode _n, Pedantics p = Pedantics.Lax ) : Symbol
IsAssignmentOperator ( Symbol opName ) : bool
IsBracedBlock ( LNode n ) : bool
IsComplexIdentifier ( LNode n, ICI f = ICI.Default, Pedantics p = Pedantics.Lax ) : bool
IsEventDefinition ( LNode n, Pedantics p ) : bool
IsExecutableBlockStmt ( LNode _n, Pedantics p = Pedantics.Lax ) : bool
IsForwardedProperty ( LNode _n, Pedantics p = Pedantics.Lax ) : bool
IsIdentContChar ( char c ) : bool
IsIdentStartChar ( char c ) : bool
IsLabelStmt ( LNode _n, Pedantics p = Pedantics.Lax ) : bool
IsNamedArgument ( LNode _n, Pedantics p = Pedantics.Lax ) : bool
IsOperator ( Symbol opName ) : bool
IsPlainCsIdentContChar ( char c ) : bool
IsPlainCsIdentStartChar ( char c ) : bool
IsPlainCsIdentifier ( string text ) : bool
IsPrintableTypeParam ( LNode n, Pedantics p = Pedantics.Lax ) : bool

Checks if 'n' is a legal type parameter definition.

A type parameter definition must be a simple symbol with at most one #in or #out attribute, and at most one #where attribute with an argument list consisting of complex identifiers.

IsPropertyDefinition ( LNode n, LNode &retType, LNode &name, LNode &args, LNode &body, LNode &initialValue, Pedantics p = Pedantics.Lax ) : bool

Returns true iff the given node has a valid syntax tree for a property definition, and gets the component parts of the definition.

The body may be anything. If it calls CodeSymbols.Braces, it's a normal body.

IsPropertyDefinition ( LNode n, Pedantics p = Pedantics.Lax ) : bool

Returns true iff the given node has a valid syntax tree for a property definition.

IsResultExpr ( LNode n, Pedantics p = Pedantics.Lax ) : bool
IsSimpleIdentifier ( LNode n, Pedantics p ) : bool
IsVariableDecl ( LNode _n, bool allowMultiple, bool allowNoAssignment, Pedantics p ) : bool
IsVariableDeclExpr ( LNode expr, LNode &type, LNode &name, LNode &initialValue ) : bool

Verifies that a declaration of a single variable is valid and gets its parts.

KeyNameComponentOf ( LNode name ) : Symbol

Given a complex name such as global::Foo<int>.Bar<T>, this method identifies the base name component, which in this example is Bar. This is used, for example, to identify the expected name for a constructor based on the class name, e.g. Foo<T> => Foo.

It is not verified that name is a complex identifier. There is no error detection but in some cases an empty name may be returned, e.g. for input like Foo."Hello".

MayBeImplicitChildStatement ( LNode node, int childIndex ) : bool

Returns true if the specified child of the specified node can be an implicit child statement, i.e. a child statement that is not necessarily a braced block, e.g. the second child of a while loop.

This method helps the printer decide when a newline should be added before an unbraced child statement when there are no attributes dictating whether to add a newline or not. This method only cares about executable parent nodes. It returns false for class/space and function/property bodies, which are always braced blocks and therefore get a newline before every child statement automatically.

MethodDefinitionKind ( LNode n, LNode &retType, LNode &name, LNode &args, LNode &body, bool allowDelegate, Pedantics p = Pedantics.Lax ) : Symbol

If the given node has a valid syntax tree for a method definition, a constructor, or (when orDelegate is true) a delegate definition, gets the definition kind (#fn, #cons, or #delegate).

Method declarations (no body) also count. A destructor counts as a #fn with a method name that calls the ~ operator.

MethodDefinitionKind ( LNode n, bool allowDelegate, Pedantics p = Pedantics.Lax ) : Symbol

If the given node has a valid syntax tree for a method definition, a constructor, or (when orDelegate is true) a delegate definition, gets the definition kind (#fn, #cons, or #delegate).

SanitizeIdentifier ( string id ) : string

Eliminates punctuation and special characters from a string so that the string can be used as a plain C# identifier, e.g. "I'd" => "I_aposd", "123" => "_123", "+5" => "_plus5".

The empty string "" becomes "__empty__", ASCII punctuation becomes "_xyz" where xyz is an HTML entity name, e.g. '!' becomes "_excl", and all other characters become "Xxx" where xx is the hexadecimal representation of the code point. Designed for the Unicode BMP only.

SpaceDefinitionKind ( LNode n, LNode &name, LNode &bases, LNode &body, Pedantics p = Pedantics.Lax ) : Symbol

Returns the space kind, which is one of the names #struct, #class, #enum, #interface, #namespace, #alias, #trait, or null if the node Name or structure is not valid for a space statement.

SpaceDefinitionKind ( LNode n, Pedantics p = Pedantics.Lax ) : Symbol

Returns the space kind, which is one of the names #struct, #class, #enum, #interface, #namespace, #alias, #trait, or null if the node Name or structure is not valid for a space statement.

Private Methods

Method Description
CallsMinWPAIH ( LNode self, Symbol name, int argCount, Pedantics p ) : bool
CallsWPAIH ( LNode self, Symbol name, Pedantics p ) : bool
CallsWPAIH ( LNode self, Symbol name, int argCount, Pedantics p ) : bool
HasPAttrs ( LNode node, Pedantics p ) : bool
HasPAttrsOrParens ( LNode node, Pedantics p ) : bool
HasSimpleHeadWPA ( LNode self, Pedantics p ) : bool
IsEventDefinition ( LNode node, LNode &type, LNode &name, LNode &body, Pedantics p ) : bool
IsSimpleExecutableKeywordStmt ( LNode _n, Pedantics p ) : bool
IsSimpleSymbolWPA ( LNode self, Pedantics p ) : bool
IsSimpleSymbolWPA ( LNode self, Symbol name, Pedantics p ) : bool
OtherBlockStmtType ( LNode _n, Pedantics p ) : Symbol
TwoArgBlockStmtType ( LNode _n, Pedantics p ) : Symbol

Method Details

ExecutableBlockStmtType() public static method

public static ExecutableBlockStmtType ( LNode _n, Pedantics p = Pedantics.Lax ) : Symbol
_n LNode
p Pedantics
return Symbol

IsAssignmentOperator() public static method

public static IsAssignmentOperator ( Symbol opName ) : bool
opName Symbol
return bool

IsBracedBlock() public static method

public static IsBracedBlock ( LNode n ) : bool
n LNode
return bool

IsComplexIdentifier() public static method

public static IsComplexIdentifier ( LNode n, ICI f = ICI.Default, Pedantics p = Pedantics.Lax ) : bool
n LNode
f ICI
p Pedantics
return bool

IsEventDefinition() public static method

public static IsEventDefinition ( LNode n, Pedantics p ) : bool
n LNode
p Pedantics
return bool

IsExecutableBlockStmt() public static method

public static IsExecutableBlockStmt ( LNode _n, Pedantics p = Pedantics.Lax ) : bool
_n LNode
p Pedantics
return bool

IsForwardedProperty() public static method

public static IsForwardedProperty ( LNode _n, Pedantics p = Pedantics.Lax ) : bool
_n LNode
p Pedantics
return bool

IsIdentContChar() public static method

public static IsIdentContChar ( char c ) : bool
c char
return bool

IsIdentStartChar() public static method

public static IsIdentStartChar ( char c ) : bool
c char
return bool

IsLabelStmt() public static method

public static IsLabelStmt ( LNode _n, Pedantics p = Pedantics.Lax ) : bool
_n LNode
p Pedantics
return bool

IsNamedArgument() public static method

public static IsNamedArgument ( LNode _n, Pedantics p = Pedantics.Lax ) : bool
_n LNode
p Pedantics
return bool

IsOperator() public static method

public static IsOperator ( Symbol opName ) : bool
opName Symbol
return bool

IsPlainCsIdentContChar() public static method

public static IsPlainCsIdentContChar ( char c ) : bool
c char
return bool

IsPlainCsIdentStartChar() public static method

public static IsPlainCsIdentStartChar ( char c ) : bool
c char
return bool

IsPlainCsIdentifier() public static method

public static IsPlainCsIdentifier ( string text ) : bool
text string
return bool

IsPrintableTypeParam() public static method

Checks if 'n' is a legal type parameter definition.
A type parameter definition must be a simple symbol with at most one #in or #out attribute, and at most one #where attribute with an argument list consisting of complex identifiers.
public static IsPrintableTypeParam ( LNode n, Pedantics p = Pedantics.Lax ) : bool
n LNode
p Pedantics
return bool

IsPropertyDefinition() public static method

Returns true iff the given node has a valid syntax tree for a property definition, and gets the component parts of the definition.
The body may be anything. If it calls CodeSymbols.Braces, it's a normal body.
public static IsPropertyDefinition ( LNode n, LNode &retType, LNode &name, LNode &args, LNode &body, LNode &initialValue, Pedantics p = Pedantics.Lax ) : bool
n LNode
retType LNode
name LNode
args LNode
body LNode
initialValue LNode
p Pedantics
return bool

IsPropertyDefinition() public static method

Returns true iff the given node has a valid syntax tree for a property definition.
public static IsPropertyDefinition ( LNode n, Pedantics p = Pedantics.Lax ) : bool
n LNode
p Pedantics
return bool

IsResultExpr() public static method

public static IsResultExpr ( LNode n, Pedantics p = Pedantics.Lax ) : bool
n LNode
p Pedantics
return bool

IsSimpleIdentifier() public static method

public static IsSimpleIdentifier ( LNode n, Pedantics p ) : bool
n LNode
p Pedantics
return bool

IsVariableDecl() public static method

public static IsVariableDecl ( LNode _n, bool allowMultiple, bool allowNoAssignment, Pedantics p ) : bool
_n LNode
allowMultiple bool
allowNoAssignment bool
p Pedantics
return bool

IsVariableDeclExpr() public static method

Verifies that a declaration of a single variable is valid and gets its parts.
public static IsVariableDeclExpr ( LNode expr, LNode &type, LNode &name, LNode &initialValue ) : bool
expr LNode Potential variable or field declaration
type LNode Variable type (empty identifier if `var`)
name LNode Variable name (identifier or $substutution expr)
initialValue LNode Initial value that is assigned in expr, or null if unassigned.
return bool

KeyNameComponentOf() public static method

Given a complex name such as global::Foo<int>.Bar<T>, this method identifies the base name component, which in this example is Bar. This is used, for example, to identify the expected name for a constructor based on the class name, e.g. Foo<T> => Foo.
It is not verified that name is a complex identifier. There is no error detection but in some cases an empty name may be returned, e.g. for input like Foo."Hello".
public static KeyNameComponentOf ( LNode name ) : Symbol
name LNode
return Symbol

MayBeImplicitChildStatement() public static method

Returns true if the specified child of the specified node can be an implicit child statement, i.e. a child statement that is not necessarily a braced block, e.g. the second child of a while loop.
This method helps the printer decide when a newline should be added before an unbraced child statement when there are no attributes dictating whether to add a newline or not. This method only cares about executable parent nodes. It returns false for class/space and function/property bodies, which are always braced blocks and therefore get a newline before every child statement automatically.
public static MayBeImplicitChildStatement ( LNode node, int childIndex ) : bool
node LNode
childIndex int
return bool

MethodDefinitionKind() public static method

If the given node has a valid syntax tree for a method definition, a constructor, or (when orDelegate is true) a delegate definition, gets the definition kind (#fn, #cons, or #delegate).
Method declarations (no body) also count. A destructor counts as a #fn with a method name that calls the ~ operator.
public static MethodDefinitionKind ( LNode n, LNode &retType, LNode &name, LNode &args, LNode &body, bool allowDelegate, Pedantics p = Pedantics.Lax ) : Symbol
n LNode
retType LNode Return type of the method (if it's a constructor, this will be the empty identifier).
name LNode Name of the method.
args LNode args.Args is the argument list of the method.
body LNode The method body, or null if there is no method body. /// The method body calls if the method is a /// non-lambda-style method.
allowDelegate bool
p Pedantics
return Symbol

MethodDefinitionKind() public static method

If the given node has a valid syntax tree for a method definition, a constructor, or (when orDelegate is true) a delegate definition, gets the definition kind (#fn, #cons, or #delegate).
public static MethodDefinitionKind ( LNode n, bool allowDelegate, Pedantics p = Pedantics.Lax ) : Symbol
n LNode
allowDelegate bool
p Pedantics
return Symbol

SanitizeIdentifier() public static method

Eliminates punctuation and special characters from a string so that the string can be used as a plain C# identifier, e.g. "I'd" => "I_aposd", "123" => "_123", "+5" => "_plus5".
The empty string "" becomes "__empty__", ASCII punctuation becomes "_xyz" where xyz is an HTML entity name, e.g. '!' becomes "_excl", and all other characters become "Xxx" where xx is the hexadecimal representation of the code point. Designed for the Unicode BMP only.
public static SanitizeIdentifier ( string id ) : string
id string
return string

SpaceDefinitionKind() public static method

Returns the space kind, which is one of the names #struct, #class, #enum, #interface, #namespace, #alias, #trait, or null if the node Name or structure is not valid for a space statement.
public static SpaceDefinitionKind ( LNode n, LNode &name, LNode &bases, LNode &body, Pedantics p = Pedantics.Lax ) : Symbol
n LNode The node to examine.
name LNode Name of the space.
bases LNode bases.Args will be the list of base types.
body LNode A braced block of statements holding the contents of the space.
p Pedantics
return Symbol

SpaceDefinitionKind() public static method

Returns the space kind, which is one of the names #struct, #class, #enum, #interface, #namespace, #alias, #trait, or null if the node Name or structure is not valid for a space statement.
public static SpaceDefinitionKind ( LNode n, Pedantics p = Pedantics.Lax ) : Symbol
n LNode
p Pedantics
return Symbol