|
Enhanced C#
Loyc library documentation
|
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...
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) |
Returns true if n is a potential type name. More... | |
| 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 pattern) |
| Checks whether an expression is a valid "is" test (pattern- matching expression) such as "x is Foo", "x is Foo y" or "x is (> 1, int)". As of C# 8 the syntax of this operator is extremely complex and in the interest in limiting my workload, a full validation is not performed. 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... | |
This is needed by the EC# node printer, but perhaps no one else.
|
inlinestatic |
Returns true if n is a potential type name.
| n | |
| f | |
| p |
References Loyc.Syntax.CodeSymbols.ColonColon, Loyc.Syntax.CodeSymbols.Dot, Loyc.Syntax.CodeSymbols.Of, and Loyc.Syntax.CodeSymbols.Var.
|
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 (> 1, int)". As of C# 8 the syntax of this operator is extremely complex and in the interest in limiting my workload, a full validation is not performed.
Before v2.9 the format of a valid "is" test was @'is(subject, type_or_vardecl, extraArgsList). The new version drops support for extraArgsList and for the unary form of the is operator (which was stored as @'is(@``, Foo)), in favor of simply copying the changes introduced in C# 8 and 9.
References Loyc.Syntax.LNode.Calls(), and Loyc.Syntax.CodeSymbols.Is.
|
inlinestatic |
Alias for MethodDefinitionKind(LNode,bool,Pedantics) that returns true if MethodDefinitionKind returns #fn.
|
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, and Loyc.Syntax.CodeSymbols.WhereClause.
|
inlinestatic |
Returns true iff the given node has a valid syntax tree for a property definition.
|
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, and Loyc.Syntax.CodeSymbols.Property.
|
inlinestatic |
Verifies that a declaration of a single variable is valid, and gets its parts.
| expr | Potential variable or field declaration |
| type | Variable type (empty identifier if var) |
| name | Variable name (identifier or $substutution expr) |
| initialValue | Initial value that is assigned in expr, or null if unassigned. |
expr is declaration of a single variable.References Loyc.Syntax.CodeSymbols.Assign, Loyc.Syntax.LNode.Calls(), and Loyc.Syntax.CodeSymbols.Var.
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.Syntax.CodeSymbols.Dot, Loyc.Syntax.CodeSymbols.Of, and Loyc.Syntax.LNode.Target.
|
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).
|
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).
| retType | Return type of the method (if it's a constructor, this will be the empty identifier). |
| name | Name of the method. |
| args | args.Args is the argument list of the method. |
| body | The 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. |
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.CodeSymbols.Braces, Loyc.Syntax.CodeSymbols.Delegate, and Loyc.Syntax.CodeSymbols.Missing.
|
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.
|
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.
|
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.
| n | The node to examine. |
| name | Name of the space. |
| bases | bases.Args will be the list of base types. |
| body | A braced block of statements holding the contents of the space. |
References Loyc.Syntax.CodeSymbols.Alias, Loyc.Syntax.CodeSymbols.Assign, Loyc.Syntax.CodeSymbols.Braces, and Loyc.Syntax.CodeSymbols.Missing.
1.8.7