本文整理汇总了C#中Expr.IsNodeType方法的典型用法代码示例。如果您正苦于以下问题:C# Expr.IsNodeType方法的具体用法?C# Expr.IsNodeType怎么用?C# Expr.IsNodeType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Expr
的用法示例。
在下文中一共展示了Expr.IsNodeType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMemberAccess
/// <summary>
/// Gets a member access object representing the a member access.
/// </summary>
/// <param name="node"></param>
/// <param name="ctx"></param>
/// <param name="varExp"></param>
/// <param name="memberName"></param>
/// <returns></returns>
public static MemberAccess GetMemberAccess(AstNode node, Context ctx, Expr varExp, string memberName, IAstVisitor visitor)
{
var isVariableExp = varExp.IsNodeType(NodeTypes.SysVariable);
var variableName = isVariableExp ? ((VariableExpr) varExp).Name : string.Empty;
// CASE 1: External function call "user.create"
if (isVariableExp && FunctionHelper.IsExternalFunction(ctx.ExternalFunctions, variableName, memberName))
return new MemberAccess(MemberMode.FunctionExternal) {Name = variableName, MemberName = memberName};
// CASE 2. Static method call: "Person.Create"
if (isVariableExp)
{
var result = MemberHelper.IsExternalTypeName(ctx.Memory, ctx.Types, variableName);
if (result.Success)
return MemberHelper.GetExternalTypeMember(node, (Type) result.Item, variableName, null, memberName, true);
}
// CASE 3: Module
if (varExp.IsNodeType(NodeTypes.SysVariable))
{
var name = varExp.ToQualifiedName();
if (!ctx.Memory.Contains(name))
{
var modresult = ResolveSymbol(varExp.SymScope, name);
if (modresult != null) return modresult;
}
}
// CASE 4: Nested member.
var res = varExp.Visit(visitor);
if (res is MemberAccess )
{
return res as MemberAccess;
}
var obj = res as LObject;
// Check for empty objects.
ExceptionHelper.NotNull(node, obj, "member access");
var type = obj.Type;
// Case 3: Method / Property on FluentScript type
bool isCoreType = obj.Type.IsBuiltInType();
if (isCoreType)
{
var result = MemberHelper.GetLangBasicTypeMember(node, ctx.Methods, obj, memberName);
return result;
}
// CASE 4: Method / Property on External/Host language type (C#)
var lclass = obj as LClass;
var lclassType = lclass.Type as LClassType;
var member = MemberHelper.GetExternalTypeMember(node, lclassType.DataType, variableName, lclass.Value, memberName, false);
return member;
}
示例2: AssignValue
/// <summary>
/// Assign a value to an expression.
/// </summary>
/// <param name="node"></param>
/// <param name="varExpr"></param>
/// <param name="valueExpr"></param>
/// <param name="isDeclaration"></param>
/// <returns></returns>
public static LObject AssignValue(AstNode node, Expr varExpr, Expr valueExpr, bool isDeclaration)
{
var ctx = varExpr.Ctx;
// CASE 1: Assign variable. a = 1
if (varExpr.IsNodeType(NodeTypes.SysVariable))
{
AssignHelper.SetVariableValue(ctx, node, isDeclaration, varExpr, valueExpr);
}
// CASE 2: Assign member.
// e.g. dictionary : user.name = 'kishore'
// e.g. property on class: user.age = 20
else if (varExpr.IsNodeType(NodeTypes.SysMemberAccess))
{
AssignHelper.SetMemberValue(ctx, node, varExpr, valueExpr);
}
// Case 3: Assign value to index: "users[0]" = <expression>;
else if (varExpr.IsNodeType(NodeTypes.SysIndex))
{
AssignHelper.SetIndexValue(ctx, node, varExpr, valueExpr);
}
return LObjects.Null;
}
示例3: ApplyDocTagsToFunction
/// <summary>
/// Applies the last doc tags to the function statement.
/// </summary>
/// <param name="stmt"></param>
protected void ApplyDocTagsToFunction(Expr stmt)
{
if (!_hasSummaryComments) return;
if (!(stmt.IsNodeType(NodeTypes.SysFunctionDeclare)))
{
throw _tokenIt.BuildSyntaxUnexpectedTokenException(_lastCommentToken);
}
// Get the function associated w/ the declaration.
// Parse the doc tags.
// Apply the doc tags to the function.
var func = ((FunctionDeclareExpr)stmt).Function;
var tags = DocHelper.ParseDocTags(_comments);
func.Meta.Doc = tags.Item1;
// Associate all the argument specifications to the function metadata
foreach (var arg in tags.Item1.Args)
{
if (string.IsNullOrEmpty(arg.Name))
continue;
if (!func.Meta.ArgumentsLookup.ContainsKey(arg.Name))
_tokenIt.BuildSyntaxException("Doc argument name : '" + arg.Name + "' does not exist in function : " + func.Name);
var funcArg = func.Meta.ArgumentsLookup[arg.Name];
funcArg.Alias = arg.Alias;
funcArg.Desc = arg.Desc;
funcArg.Examples = arg.Examples;
funcArg.Type = arg.Type;
// Now associate the alias to the arg names.
func.Meta.ArgumentsLookup[funcArg.Alias] = funcArg;
if (!string.IsNullOrEmpty(funcArg.Alias))
{
func.Meta.ArgumentNames[funcArg.Alias] = funcArg.Alias;
}
}
// Clear the comment state.
_comments.Clear();
_hasSummaryComments = false;
_lastCommentToken = null;
}
示例4: VisitExpr
/// <summary>
/// Visit the statement
/// </summary>
/// <param name="exp"></param>
public object VisitExpr( Expr exp)
{
if (exp.IsNodeType(NodeTypes.SysAssign))
VisitAssign(exp as AssignExpr);
if (exp.IsNodeType(NodeTypes.SysAssignMulti))
VisitAssignMulti(exp as AssignMultiExpr);
else if (exp.IsNodeType(NodeTypes.SysFor))
VisitFor(exp as ForExpr);
else if (exp.IsNodeType(NodeTypes.SysForEach))
VisitForEach(exp as ForEachExpr);
else if (exp.IsNodeType(NodeTypes.SysIf))
VisitIf(exp as IfExpr);
else if (exp.IsNodeType(NodeTypes.SysTryCatch))
VisitTryCatch(exp as TryCatchExpr);
else if (exp.IsNodeType(NodeTypes.SysWhile))
VisitWhile(exp as WhileExpr);
else if (exp.IsNodeType(NodeTypes.SysBinary))
VisitBinary(exp as BinaryExpr);
else if (exp.IsNodeType(NodeTypes.SysCompare))
VisitCompare(exp as CompareExpr);
else if (exp.IsNodeType(NodeTypes.SysCondition))
VisitCondition(exp as ConditionExpr);
else if (exp.IsNodeType(NodeTypes.SysFunctionDeclare))
VisitFunctionDeclare(exp as FunctionDeclareExpr);
else if (exp.IsNodeType(NodeTypes.SysFunctionCall))
VisitFunctionCall(exp as FunctionCallExpr);
return null;
}
示例5: ParseFrom
private void ParseFrom()
{
var token = _tokenIt.NextToken.Token;
// 1. "from book in books where"
if (string.Compare(token.Text, "from", StringComparison.InvariantCultureIgnoreCase) == 0)
{
_tokenIt.Advance();
_variableName = _tokenIt.ExpectId();
_tokenIt.Expect(Tokens.In);
_source = _parser.ParseIdExpression();
return;
}
// 2. books where
// In this case autocreate variable "book" using variable name.
_source = _parser.ParseIdExpression();
if (_source.IsNodeType(NodeTypes.SysVariable))
_variableName = ((VariableExpr)_source).Name;
else if (_source.IsNodeType(NodeTypes.SysMemberAccess))
_variableName = ((MemberAccessExpr)_source).MemberName;
// get "book" from "books".
_variableName = _variableName.Substring(0, _variableName.Length - 1);
}
示例6: EnsureConstant
private void EnsureConstant(string constName, Expr exp)
{
var ctx = _parser.Context;
if (ctx.Symbols.Contains(constName) && ctx.Symbols.IsConst(constName))
throw _tokenIt.BuildSyntaxException("Can not reassign constant", exp);
if (exp.IsNodeType(NodeTypes.SysNew))
{
var nexp = exp as NewExpr;
if(nexp.TypeName != "Date" && nexp.TypeName != "Time" )
throw _tokenIt.BuildSyntaxException("Const : " + constName + " must have a const value");
}
else if (!(exp.IsNodeType(NodeTypes.SysConstant)))
throw _tokenIt.BuildSyntaxException("Const : " + constName + " must have a const value");
}