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 {
  Strict = 0, IgnoreAttributesInOddPlaces = 1, IgnoreIllegalParentheses = 2,
  Lax = IgnoreAttributesInOddPlaces | 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 bool IsNormalMethod (LNode n, Pedantics p=Pedantics.Lax)
 Alias for MethodDefinitionKind(LNode,bool,Pedantics) that returns true if MethodDefinitionKind returns #fn. More...
 
static Symbol MethodDefinitionKind (LNode n, out LNode retType, out LNode name, out LNode args, out LNode body, bool allowDelegate=true, 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, Pedantics p=Pedantics.Lax)
 Verifies that a declaration of a single variable is valid, and gets its parts. More...
 
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 bool IsIsTest (LNode n, out LNode subject, out LNode targetType, out LNode targetVarName, out LNode extraArgs, Pedantics p=Pedantics.Lax)
 Checks whether an expression is a valid "is" test (pattern- matching expression) such as "x is Foo", "x is Foo y" or "x is Foo y(z)". More...
 
static bool IsLinqExpression (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

◆ Pedantics

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

Member Function Documentation

◆ IsIsTest()

static bool Loyc.Ecs.EcsValidators.IsIsTest ( LNode  n,
out LNode  subject,
out LNode  targetType,
out LNode  targetVarName,
out LNode  extraArgs,
Pedantics  p = Pedantics.Lax 
)
inlinestatic

Checks whether an expression is a valid "is" test (pattern- matching expression) such as "x is Foo", "x is Foo y" or "x is Foo y(z)".

The format of a valid "is" test is @'is(subject, type_or_vardecl, extraArgsList). For example a is Foo would be @'is(a, Foo) and a is Foo b(c, d) would be @'is(a, #var(Foo, b), #(c, d)). Unary "is" expressions like is Foo are stored as binary expressions with an empty identifier as the left-hand side: @'is(@``, Foo).

References Loyc.Syntax.CodeSymbols.AltList, Loyc.Syntax.LNode.Args, Loyc.Syntax.LNode.CallsMin(), Loyc.Syntax.CodeSymbols.Is, and Loyc.Ecs.EcsValidators.IsVariableDeclExpr().

◆ IsNormalMethod()

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

Alias for MethodDefinitionKind(LNode,bool,Pedantics) that returns true if MethodDefinitionKind returns #fn.

References Loyc.Ecs.EcsValidators.MethodDefinitionKind().

◆ IsPrintableTypeParam()

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.Attrs, Loyc.Syntax.CodeSymbols.New, Loyc.Syntax.CodeSymbols.Out, and Loyc.Syntax.CodeSymbols.Where.

◆ IsPropertyDefinition() [1/2]

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, otherwise it's a getter-only body (e.g. int Foo => 42). Indexer properties can have an argument list, e.g. T Foo[int x] { get; } would have a syntax tree like #property(T, Foo, #(#var(#int32, x)), { get; }).

References Loyc.Syntax.CodeSymbols.AltList, Loyc.Syntax.LNode.Args, Loyc.Syntax.CodeSymbols.Missing, and Loyc.Syntax.CodeSymbols.Property.

◆ IsPropertyDefinition() [2/2]

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.

◆ IsVariableDeclExpr()

static bool Loyc.Ecs.EcsValidators.IsVariableDeclExpr ( LNode  expr,
out LNode  type,
out LNode  name,
out LNode  initialValue,
Pedantics  p = Pedantics.Lax 
)
inlinestatic

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

Parameters
exprPotential variable or field declaration
typeVariable type (empty identifier if var)
nameVariable name (identifier or $substutution expr)
initialValueInitial value that is assigned in expr, or null if unassigned.
Returns
True if expr is declaration of a single variable.

References Loyc.Syntax.LNode.Args, Loyc.Syntax.CodeSymbols.Assign, Loyc.Syntax.LNode.Calls(), and Loyc.Syntax.CodeSymbols.Var.

Referenced by Loyc.Ecs.EcsValidators.IsIsTest().

◆ KeyNameComponentOf()

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.Calls(), Loyc.Syntax.LNode.CallsMin(), Loyc.Syntax.CodeSymbols.ColonColon, Loyc.Syntax.CodeSymbols.Dot, Loyc.Syntax.LNode.Name, Loyc.Syntax.CodeSymbols.Of, and Loyc.Syntax.LNode.Target.

◆ MethodDefinitionKind() [1/2]

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

Referenced by Loyc.Ecs.EcsValidators.IsNormalMethod().

◆ MethodDefinitionKind() [2/2]

static Symbol Loyc.Ecs.EcsValidators.MethodDefinitionKind ( LNode  n,
out LNode  retType,
out LNode  name,
out LNode  args,
out LNode  body,
bool  allowDelegate = true,
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.CodeSymbols._Destruct, Loyc.Syntax.CodeSymbols.AltList, Loyc.Syntax.LNode.Args, Loyc.Syntax.CodeSymbols.Braces, Loyc.Syntax.CodeSymbols.Delegate, Loyc.Syntax.CodeSymbols.Missing, and Loyc.Syntax.LNode.Name.

◆ SanitizeIdentifier()

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

◆ SpaceDefinitionKind() [1/2]

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.CodeSymbols.Alias, Loyc.Syntax.CodeSymbols.AltList, Loyc.Syntax.LNode.Args, Loyc.Syntax.CodeSymbols.Assign, Loyc.Syntax.CodeSymbols.Braces, Loyc.Syntax.CodeSymbols.Missing, and Loyc.Syntax.LNode.Name.

◆ SpaceDefinitionKind() [2/2]

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.