public IExpressionNode Visit(ArrowAnonymFunctionSyntaxNode arrowAnonymFunNode) { if (arrowAnonymFunNode.Definition == null) { throw ErrorFactory.AnonymousFunDefinitionIsMissing(arrowAnonymFunNode); } if (arrowAnonymFunNode.Body == null) { throw ErrorFactory.AnonymousFunBodyIsMissing(arrowAnonymFunNode); } //Anonym fun arguments list var argumentLexNodes = arrowAnonymFunNode.ArgumentsDefinition; //Prepare local variable scope //Capture all outerscope variables var localVariables = new VariableDictionary(_variables.GetAllSources()); var arguments = new VariableSource[argumentLexNodes.Length]; var argIndex = 0; foreach (var arg in argumentLexNodes) { //Convert argument node var varNode = FunArgumentExpressionNode.CreateWith(arg); var source = VariableSource.CreateWithStrictTypeLabel(varNode.Name, varNode.Type, arg.Interval, isOutput: false); //collect argument arguments[argIndex] = source; argIndex++; //add argument to local scope if (!localVariables.TryAdd(source)) { //Check for duplicated arg-names //If outer-scope contains the conflict variable name if (_variables.GetSourceOrNull(varNode.Name) != null) { throw ErrorFactory.AnonymousFunctionArgumentConflictsWithOuterScope(varNode.Name, arrowAnonymFunNode.Interval); } else //else it is duplicated arg name { throw ErrorFactory.AnonymousFunctionArgumentDuplicates(varNode, arrowAnonymFunNode.Definition); } } } var body = arrowAnonymFunNode.Body; return(BuildAnonymousFunction(arrowAnonymFunNode.Interval, body, localVariables, arguments)); }
public static Exception AnonymousFunDefinitionIsIncorrect(ArrowAnonymFunctionSyntaxNode arrowAnonymFunNode) => new FunParseException(569, $"'Anonym fun definition is incorrect ", arrowAnonymFunNode.Interval);
public virtual VisitorEnterResult Visit(ArrowAnonymFunctionSyntaxNode arrowAnonymFunNode) => DefaultVisitEnter(arrowAnonymFunNode);
public bool Visit(ArrowAnonymFunctionSyntaxNode node) { _aliasScope.EnterScope(node.OrderNumber); foreach (var syntaxNode in node.ArgumentsDefinition) { //setup arguments. string originName; string anonymName; if (syntaxNode is TypedVarDefSyntaxNode typed) { //argument has type definition on it originName = typed.Id; anonymName = MakeAnonVariableName(node, originName); if (!typed.FunnyType.Equals(FunnyType.Empty)) { var ticType = typed.FunnyType.ConvertToTiType(); _ticTypeGraph.SetVarType(anonymName, ticType); } } else if (syntaxNode is NamedIdSyntaxNode varNode) { //argument has no type definition on it originName = varNode.Id; anonymName = MakeAnonVariableName(node, originName); } else { throw ErrorFactory.AnonymousFunArgumentIsIncorrect(syntaxNode); } _aliasScope.AddVariableAlias(originName, anonymName); } VisitChildren(node); var aliasNames = new string[node.ArgumentsDefinition.Length]; for (var i = 0; i < node.ArgumentsDefinition.Length; i++) { var syntaxNode = node.ArgumentsDefinition[i]; if (syntaxNode is TypedVarDefSyntaxNode typed) { aliasNames[i] = _aliasScope.GetVariableAlias(typed.Id); } else if (syntaxNode is NamedIdSyntaxNode varNode) { aliasNames[i] = _aliasScope.GetVariableAlias(varNode.Id); } } #if DEBUG Trace(node, $"f({string.Join(" ", aliasNames)}):{node.OutputType}= {{{node.OrderNumber}}}"); #endif if (node.ReturnType == FunnyType.Empty) { _ticTypeGraph.CreateLambda(node.Body.OrderNumber, node.OrderNumber, aliasNames); } else { var retType = (ITypeState)node.ReturnType.ConvertToTiType(); _ticTypeGraph.CreateLambda( node.Body.OrderNumber, node.OrderNumber, retType, aliasNames); } _aliasScope.ExitScope(); return(true); }
public string Visit(ArrowAnonymFunctionSyntaxNode arrowAnonymFunNode) => "(..)=>..";
public virtual bool Visit(ArrowAnonymFunctionSyntaxNode arrowAnonymFunNode) => true;