Enhanced C#
Language of your choice: library documentation
Public Types | Static Public Member Functions | List of all members
Loyc.Ecs.EcsValidators Class Reference

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. More...


Source file:

Remarks

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).

Public Types

enum  Pedantics { IgnoreWeirdAttributes = 1, IgnoreIllegalParentheses = 2, Lax = IgnoreWeirdAttributes | IgnoreIllegalParentheses }
 This is needed by the EC# node printer, but perhaps no one else. More...
 

Static Public Member Functions

static Symbol SpaceDefinitionKind (LNode n, Pedantics p=Pedantics.Lax)
 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. More...
 
static Symbol SpaceDefinitionKind (LNode n, out LNode name, out LNode bases, out LNode body, Pedantics p=Pedantics.Lax)
 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. More...
 
static Symbol MethodDefinitionKind (LNode n, bool allowDelegate, Pedantics p=Pedantics.Lax)
 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). More...
 
static Symbol MethodDefinitionKind (LNode n, out LNode retType, out LNode name, out LNode args, out LNode body, bool allowDelegate, Pedantics p=Pedantics.Lax)
 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). More...
 
static bool IsPropertyDefinition (LNode n, Pedantics p=Pedantics.Lax)
 Returns true iff the given node has a valid syntax tree for a property definition. More...
 
static bool IsPropertyDefinition (LNode n, out LNode retType, out LNode name, out LNode args, out LNode body, out LNode initialValue, Pedantics p=Pedantics.Lax)
 Returns true iff the given node has a valid syntax tree for a property definition, and gets the component parts of the definition. More...
 
static bool IsEventDefinition (LNode n, Pedantics p)
 
static bool IsVariableDeclExpr (LNode expr, out LNode type, out LNode name, out LNode initialValue)
 
static bool IsVariableDecl (LNode _n, bool allowMultiple, bool allowNoAssignment, Pedantics p)
 
static bool IsSimpleIdentifier (LNode n, Pedantics p)
 
static bool IsComplexIdentifier (LNode n, ICI f=ICI.Default, Pedantics p=Pedantics.Lax)
 
static bool IsPrintableTypeParam (LNode n, Pedantics p=Pedantics.Lax)
 Checks if 'n' is a legal type parameter definition. More...
 
static bool IsExecutableBlockStmt (LNode _n, Pedantics p=Pedantics.Lax)
 
static Symbol ExecutableBlockStmtType (LNode _n, Pedantics p=Pedantics.Lax)
 
static bool IsBracedBlock (LNode n)
 
static bool IsLabelStmt (LNode _n, Pedantics p=Pedantics.Lax)
 
static bool IsNamedArgument (LNode _n, Pedantics p=Pedantics.Lax)
 
static bool IsResultExpr (LNode n, Pedantics p=Pedantics.Lax)
 
static bool IsForwardedProperty (LNode _n, Pedantics p=Pedantics.Lax)
 
static Symbol KeyNameComponentOf (LNode name)
 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. More...
 
static bool IsPlainCsIdentStartChar (char c)
 
static bool IsPlainCsIdentContChar (char c)
 
static bool IsIdentStartChar (char c)
 
static bool IsIdentContChar (char c)
 
static bool IsPlainCsIdentifier (string text)
 
static bool IsAssignmentOperator (Symbol opName)
 
static bool IsOperator (Symbol opName)
 
static string SanitizeIdentifier (string id)
 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". More...
 

Member Enumeration Documentation

This is needed by the EC# node printer, but perhaps no one else.

Member Function Documentation

static bool Loyc.Ecs.EcsValidators.IsPrintableTypeParam ( LNode  n,
Pedantics  p = Pedantics.Lax 
)
inlinestatic

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.

References Loyc.Syntax.LNode.Args, Loyc.Syntax.LNode.Attrs, Loyc.Syntax.LNode.Calls(), and Loyc.Syntax.LNode.Name.

static bool Loyc.Ecs.EcsValidators.IsPropertyDefinition ( LNode  n,
Pedantics  p = Pedantics.Lax 
)
inlinestatic

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

static bool Loyc.Ecs.EcsValidators.IsPropertyDefinition ( LNode  n,
out LNode  retType,
out LNode  name,
out LNode  args,
out LNode  body,
out LNode  initialValue,
Pedantics  p = Pedantics.Lax 
)
inlinestatic

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.

References Loyc.Syntax.LNode.Args, Loyc.Syntax.LNode.Attrs, and Loyc.Syntax.LNode.Calls().

static Symbol Loyc.Ecs.EcsValidators.KeyNameComponentOf ( LNode  name)
inlinestatic

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".

References Loyc.Syntax.LNode.Args, Loyc.Syntax.LNode.CallsMin(), Loyc.Collections.VList< T >.Last, Loyc.Syntax.LNode.Name, and Loyc.Syntax.LNode.Target.

static Symbol Loyc.Ecs.EcsValidators.MethodDefinitionKind ( LNode  n,
bool  allowDelegate,
Pedantics  p = Pedantics.Lax 
)
inlinestatic

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).

static Symbol Loyc.Ecs.EcsValidators.MethodDefinitionKind ( LNode  n,
out LNode  retType,
out LNode  name,
out LNode  args,
out LNode  body,
bool  allowDelegate,
Pedantics  p = Pedantics.Lax 
)
inlinestatic

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).

Parameters
retTypeReturn type of the method (if it's a constructor, this will be the empty identifier).
nameName of the method.
argsargs.Args is the argument list of the method.
bodyThe method body, or null if there is no method body. The method body calls CodeSymbols.Braces if the method is a non-lambda-style method.
Returns
The definition kind (#fn, #cons, or #delegate), or null if it's no kind of method.

Method declarations (no body) also count.

A destructor counts as a #fn with a method name that calls the ~ operator.

References Loyc.Syntax.LNode.Args, and Loyc.Syntax.LNode.Name.

static string Loyc.Ecs.EcsValidators.SanitizeIdentifier ( string  id)
inlinestatic

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.

References Loyc.G.BareHtmlEntityNameForAscii().

static Symbol Loyc.Ecs.EcsValidators.SpaceDefinitionKind ( LNode  n,
Pedantics  p = Pedantics.Lax 
)
inlinestatic

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.

static Symbol Loyc.Ecs.EcsValidators.SpaceDefinitionKind ( LNode  n,
out LNode  name,
out LNode  bases,
out LNode  body,
Pedantics  p = Pedantics.Lax 
)
inlinestatic

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.

Parameters
nThe node to examine.
nameName of the space.
basesbases.Args will be the list of base types.
bodyA braced block of statements holding the contents of the space.

References Loyc.Syntax.LNode.Args, and Loyc.Syntax.LNode.Name.