public ForAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.ForContext forContext) { Scope varScope = scope.Child(); if (forContext.define() != null) { DefinedVariable = new ScopedVariable(varScope, new DefineContextHandler(parseInfo, forContext.define())); } else if (forContext.initialVarset != null) { InitialVarSet = new SetVariableAction(parseInfo, varScope, forContext.initialVarset); } if (forContext.expr() != null) { Condition = DeltinScript.GetExpression(parseInfo, varScope, forContext.expr()); } if (forContext.endingVarset != null) { SetVariableAction = new SetVariableAction(parseInfo, varScope, forContext.endingVarset); } // Get the block. if (forContext.block() != null) { Block = new BlockAction(parseInfo.SetLoop(this), varScope, forContext.block()); // Get the path info. Path = new PathInfo(Block, DocRange.GetRange(forContext.FOR()), false); } else { parseInfo.Script.Diagnostics.Error("Expected a block.", DocRange.GetRange(forContext.RIGHT_PAREN())); } }
private void GetCompletion(ScriptFile script, Scope scope) { for (int i = 0; i < Tree.Length; i++) { if (Tree[i] != null) { // Get the treescope. Don't get the completion items if it is null. var treeScope = ExprContextTree[i].GetScope(); if (treeScope != null) { DocRange range; if (i < Tree.Length - 1) { range = ExprContextTree[i + 1].GetRange(); } // Expression path has a trailing '.' else if (_trailingSeperator != null) { range = new DocRange( DocRange.GetRange(_trailingSeperator).end, DocRange.GetRange(script.NextToken(_trailingSeperator)).start ); } else { continue; } script.AddCompletionRange(new CompletionRange(treeScope, scope, range, CompletionRangeKind.ClearRest)); } } } }
public IsAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.E_isContext isContext) { // Get the expression. expression = DeltinScript.GetExpression(parseInfo, scope, isContext.expr()); // Get the type. if (isContext.type == null) { parseInfo.Script.Diagnostics.Error("Expected type name.", DocRange.GetRange(isContext.IS())); } else { CodeType type = parseInfo.TranslateInfo.GetCodeType(isContext.type.Text, parseInfo.Script.Diagnostics, DocRange.GetRange(isContext.type)); // Make sure the received type is a class. if (type != null && type is ClassType == false) { parseInfo.Script.Diagnostics.Error("Expected a class type.", DocRange.GetRange(isContext.type)); } else { checkingIfType = (ClassType)type; } } }
public MethodAttributeHandler(DeltinScriptParser.Method_attributesContext attributeContext) { AttributeContext = attributeContext; Range = DocRange.GetRange(attributeContext); if (attributeContext.accessor() != null) { Type = MethodAttributeType.Accessor; } else if (attributeContext.STATIC() != null) { Type = MethodAttributeType.Static; } else if (attributeContext.VIRTUAL() != null) { Type = MethodAttributeType.Virtual; } else if (attributeContext.OVERRIDE() != null) { Type = MethodAttributeType.Override; } else if (attributeContext.RECURSIVE() != null) { Type = MethodAttributeType.Recursive; } else { throw new NotImplementedException(); } }
public MethodNode(DeltinScriptParser.MethodContext context, BuildAstVisitor visitor) : base( new Location(visitor.file, DocRange.GetRange(context)), DocRange.GetRange(context.PART().Symbol), DocRange.GetRange(context.LEFT_PAREN().Symbol, context.RIGHT_PAREN().Symbol) ) { Name = context.PART().GetText(); if (context.call_parameters() != null) { Parameters = new Node[context.call_parameters().expr().Length]; for (int i = 0; i < Parameters.Length; i++) { Parameters[i] = visitor.Visit(context.call_parameters().expr()[i]); } } else if (context.picky_parameters() != null) { PickyParameters = new PickyParameter[context.picky_parameters().picky_parameter().Length]; for (int i = 0; i < PickyParameters.Length; i++) { PickyParameters[i] = new PickyParameter(context.picky_parameters().picky_parameter(i), visitor); } } else { Parameters = new Node[0]; } }
public CreateObjectAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Create_objectContext context) { // Get the type. Syntax error if there is no type name. if (context.type == null) { parseInfo.Script.Diagnostics.Error("Expected a type name.", DocRange.GetRange(context.NEW())); } else { CreatingObjectOf = parseInfo.TranslateInfo.Types.GetCodeType(context.type.Text, parseInfo.Script.Diagnostics, DocRange.GetRange(context.type)); } if (CreatingObjectOf != null) { DocRange nameRange = DocRange.GetRange(context.type); // Get the constructor to use. OverloadChooser = new OverloadChooser( CreatingObjectOf.Constructors, parseInfo, CreatingObjectOf.ReturningScope(), scope, nameRange, DocRange.GetRange(context), new OverloadError("type " + CreatingObjectOf.Name) ); OverloadChooser.Apply(context.call_parameters()); Constructor = (Constructor)OverloadChooser.Overload; ConstructorValues = OverloadChooser.Values ?? new IExpression[0]; if (Constructor != null) { parseInfo.TranslateInfo.GetComponent <SymbolLinkComponent>().AddSymbolLink(Constructor, new Location(parseInfo.Script.Uri, nameRange)); Constructor.Call(parseInfo, DocRange.GetRange(context.type)); parseInfo.Script.AddHover(DocRange.GetRange(context), Constructor.GetLabel(true)); } } }
public static void GetHook(ParseInfo parseInfo, Scope scope, DeltinScriptParser.HookContext context) { // Get the hook variable's expression. IExpression variableExpression = parseInfo.GetExpression(scope, context.var); // Get the hook value. IExpression valueExpression = parseInfo.GetExpression(scope, context.value); // Resolve the variable. VariableResolve resolvedVariable = new VariableResolve(new VariableResolveOptions() { // Not indexable CanBeIndexed = false, // Hook variables are not settable. ShouldBeSettable = false }, variableExpression, DocRange.GetRange(context.var), parseInfo.Script.Diagnostics); if (valueExpression == null) { return; } // Check if the resolved variable is a HookVar. if (resolvedVariable.SetVariable?.Calling is HookVar hookVar) { // If it is, set the hook. hookVar.TrySet(parseInfo, valueExpression, DocRange.GetRange(context.value)); } else { // Not a hook variable. parseInfo.Script.Diagnostics.Error("Expected a hook variable.", DocRange.GetRange(context.var)); } }
public ForNode(DeltinScriptParser.ForContext context, BuildAstVisitor visitor) : base(new Location(visitor.file, DocRange.GetRange(context))) { errorRange = new Location(visitor.file, DocRange.GetRange(context.FOR())); Block = (BlockNode)visitor.VisitBlock(context.block()); if (context.varset() != null) { VarSetNode = (VarSetNode)visitor.VisitVarset(context.varset()); } if (context.define() != null) { DefineNode = (DefineNode)visitor.VisitDefine(context.define()); } if (context.expr() != null) { Expression = visitor.VisitExpr(context.expr()); } if (context.forEndStatement() != null) { Statement = (VarSetNode)visitor.VisitVarset(context.forEndStatement().varset()); } }
public MacroVar(ParseInfo parseInfo, Scope objectScope, Scope staticScope, DeltinScriptParser.Define_macroContext macroContext, CodeType returnType) { _context = macroContext; Name = macroContext.name.Text; // Get the attributes. FunctionAttributesGetter attributeResult = new MacroAttributesGetter(macroContext, new MacroVarAttribute(this)); attributeResult.GetAttributes(parseInfo.Script.Diagnostics); ContainingType = (Static ? staticScope : objectScope).This; DefinedAt = new Location(parseInfo.Script.Uri, DocRange.GetRange(macroContext.name)); _recursiveCallHandler = new RecursiveCallHandler(this); CallInfo = new CallInfo(_recursiveCallHandler, parseInfo.Script); ReturnType = returnType; _expressionToParse = macroContext.expr(); _scope = Static ? staticScope : objectScope; this._parseInfo = parseInfo; _scope.AddMacro(this, parseInfo.Script.Diagnostics, DocRange.GetRange(macroContext.name), !Override); parseInfo.TranslateInfo.GetComponent <SymbolLinkComponent>().AddSymbolLink(this, DefinedAt, true); parseInfo.Script.AddHover(DocRange.GetRange(macroContext.name), GetLabel(true)); parseInfo.Script.AddCodeLensRange(new ReferenceCodeLensRange(this, parseInfo, CodeLensSourceType.Variable, DefinedAt.range)); DocRange nameRange = DocRange.GetRange(_context.name); if (Override) { MacroVar overriding = (MacroVar)objectScope.GetMacroOverload(Name, DefinedAt); if (overriding == this) { parseInfo.Script.Diagnostics.Error("Overriding itself!", nameRange); } // No method with the name and parameters found. if (overriding == null) { parseInfo.Script.Diagnostics.Error("Could not find a macro to override.", nameRange); } else if (!overriding.IsOverridable) { parseInfo.Script.Diagnostics.Error("The specified macro is not marked as virtual.", nameRange); } else { overriding.Overriders.Add(this); } if (overriding != null && overriding.DefinedAt != null) { // Make the override keyword go to the base method. parseInfo.Script.AddDefinitionLink( attributeResult.ObtainedAttributes.First(at => at.Type == MethodAttributeType.Override).Range, overriding.DefinedAt ); } } }
public RuleAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Ow_ruleContext ruleContext) { Name = Extras.RemoveQuotes(ruleContext.STRINGLITERAL().GetText()); Disabled = ruleContext.DISABLED() != null; _missingBlockRange = DocRange.GetRange(ruleContext.RULE_WORD()); GetRuleSettings(parseInfo, scope, ruleContext); // Get the conditions if (ruleContext.rule_if() == null) { Conditions = new RuleIfAction[0]; } else { Conditions = new RuleIfAction[ruleContext.rule_if().Length]; for (int i = 0; i < Conditions.Length; i++) { Conditions[i] = new RuleIfAction(parseInfo, scope, ruleContext.rule_if(i)); _missingBlockRange = DocRange.GetRange(ruleContext.rule_if(i)); } } if (ruleContext.block() != null) { Block = new BlockAction(parseInfo, scope, ruleContext.block()); } else { parseInfo.Script.Diagnostics.Error("Missing block.", _missingBlockRange); } }
public ForeachAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.ForeachContext foreachContext) { RawContinue = false; Scope varScope = scope.Child(); ForeachVar = new ForeachVariable(varScope, new ForeachContextHandler(parseInfo, foreachContext)); // Get the array that will be iterated on. Syntax error if it is missing. if (foreachContext.expr() != null) { Array = parseInfo.GetExpression(scope, foreachContext.expr()); } else { parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(foreachContext.IN())); } // Get the foreach block. Syntax error if it is missing. if (foreachContext.block() != null) { Block = new BlockAction(parseInfo.SetLoop(this), varScope, foreachContext.block()); // Get the path info. Path = new PathInfo(Block, DocRange.GetRange(foreachContext.FOREACH()), false); } else { parseInfo.Script.Diagnostics.Error("Expected block.", DocRange.GetRange(foreachContext.RIGHT_PAREN())); } }
// Makes sure each return statement returns a value if the method returns a value and that each path returns a value. private void ValidateReturns() { ReturnAction[] returns = GetReturns(); if (doesReturnValue) { // If there is only one return statement, return the reference to // the return statement to reduce the number of actions. multiplePaths = returns.Length > 1; // Syntax error if there are any paths that don't return a value. CheckPath(parseInfo.Script, new PathInfo(block, DocRange.GetRange(context.name), true)); // Syntax error if a return statement does not return a value. foreach (var ret in returns) { if (ret.ReturningValue == null) { parseInfo.Script.Diagnostics.Error("Must return a value.", ret.ErrorRange); } } } else { // Syntax error on any return statement that returns a value. foreach (var ret in returns) { if (ret.ReturningValue != null) { parseInfo.Script.Diagnostics.Error(Name + " is void, so no value can be returned.", ret.ErrorRange); } } } }
public DefinedMethod(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Define_methodContext context) : base(parseInfo, scope, context.name.Text, new Location(parseInfo.Script.Uri, DocRange.GetRange(context.name))) { this.context = context; // Check if recursion is enabled. IsRecursive = context.RECURSIVE() != null; // Get the type. ReturnType = CodeType.GetCodeTypeFromContext(parseInfo, context.code_type()); // Get the access level. AccessLevel = context.accessor().GetAccessLevel(); // Setup the parameters and parse the block. SetupParameters(context.setParameters()); if (context.block() == null) { parseInfo.Script.Diagnostics.Error("Expected block.", DocRange.GetRange(context.name)); } scope.AddMethod(this, parseInfo.Script.Diagnostics, DocRange.GetRange(context.name)); // Add the hover info. parseInfo.Script.AddHover(DocRange.GetRange(context.name), GetLabel(true)); }
public SetVariableAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.VarsetContext varsetContext) { IExpression variableExpression = parseInfo.GetExpression(scope, varsetContext.var); // Get the variable being set. VariableResolve = new VariableResolve(new VariableResolveOptions(), variableExpression, DocRange.GetRange(varsetContext), parseInfo.Script.Diagnostics); // Get the operation. if (varsetContext.statement_operation() != null) { Operation = varsetContext.statement_operation().GetText(); // If there is no value, syntax error. if (varsetContext.val == null) { parseInfo.Script.Diagnostics.Error("Expected an expression.", DocRange.GetRange(varsetContext).end.ToRange()); } // Parse the value. else { Value = parseInfo.GetExpression(scope, varsetContext.val); } } else if (varsetContext.INCREMENT() != null) { Operation = "++"; } else if (varsetContext.DECREMENT() != null) { Operation = "--"; } }
string GetImportedFile(ScriptFile script, FileImporter importer, DeltinScriptParser.Import_fileContext importFileContext) { DocRange stringRange = DocRange.GetRange(importFileContext.STRINGLITERAL()); var importResult = importer.Import( stringRange, Extras.RemoveQuotes(importFileContext.STRINGLITERAL().GetText()), script.Uri ); if (!importResult.SuccessfulReference) { return(importResult.Directory); } script.AddDefinitionLink(stringRange, new Location(importResult.Uri, DocRange.Zero)); script.AddHover(stringRange, importResult.FilePath); if (importResult.ShouldImport) { ScriptFile importedScript = new ScriptFile(Diagnostics, importResult.Uri, FileGetter.GetScript(importResult.Uri)); CollectScriptFiles(importedScript); } return(importResult.Directory); }
public ForeachAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.ForeachContext foreachContext) { Scope varScope = scope.Child(); ForeachVar = new Var(foreachContext.name.Text, new Location(parseInfo.Script.Uri, DocRange.GetRange(foreachContext.name)), parseInfo); ForeachVar.VariableType = VariableType.ElementReference; ForeachVar.CodeType = CodeType.GetCodeTypeFromContext(parseInfo, foreachContext.code_type()); ForeachVar.Finalize(varScope); // Get the array that will be iterated on. Syntax error if it is missing. if (foreachContext.expr() != null) { Array = DeltinScript.GetExpression(parseInfo, scope, foreachContext.expr()); } else { parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(foreachContext.IN())); } // Get the foreach block. Syntax error if it is missing. if (foreachContext.block() != null) { Block = new BlockAction(parseInfo, varScope, foreachContext.block()); // Get the path info. Path = new PathInfo(Block, DocRange.GetRange(foreachContext.FOREACH()), false); } else { parseInfo.Script.Diagnostics.Error("Expected block.", DocRange.GetRange(foreachContext.RIGHT_PAREN())); } }
public DocRange GetNameRange() { if (_foreachContext.name != null) { return(DocRange.GetRange(_foreachContext.name)); } return(DocRange.GetRange(_foreachContext)); }
public ReturnAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.ReturnContext returnContext) { ErrorRange = DocRange.GetRange(returnContext.RETURN()); if (returnContext.expr() != null) { ReturningValue = DeltinScript.GetExpression(parseInfo, scope, returnContext.expr()); } }
public override Node VisitEnum(DeltinScriptParser.EnumContext context) { string[] split = context.GetText().Split('.'); string type = split[0]; string value = split[1]; return(new EnumNode(type, value, new Location(file, DocRange.GetRange(context)))); }
public DocRange GetNameRange() { if (_defineContext.name == null) { return(DocRange.GetRange(_defineContext)); } return(DocRange.GetRange(_defineContext.name)); }
public override void SetupParameters() { SetupParameters(context.setParameters(), false); parseInfo.Script.AddHover(DocRange.GetRange(context.name), GetLabel(true)); if (!containingScope.IsAlreadyInScope(this)) { containingScope.AddMethod(this, parseInfo.Script.Diagnostics, DefinedAt.range); } }
public void SetupParameters() { var parameterInfo = CodeParameter.GetParameters(parseInfo, ConstructorScope, context.setParameters(), false); Parameters = parameterInfo.Parameters; ParameterVars = parameterInfo.Variables; parseInfo.Script.AddHover(DocRange.GetRange(context.name), GetLabel(true)); }
private ITreeContextPart[] Flatten(ScriptFile script, DeltinScriptParser.E_expr_treeContext exprContext) { var exprList = new List <ITreeContextPart>(); Flatten(script, exprContext, exprList); return(exprList.ToArray()); // Recursive flatten function. void Flatten(ScriptFile script, DeltinScriptParser.E_expr_treeContext exprContext, List <ITreeContextPart> exprList) { // If the expression is a Tree, recursively flatten. if (exprContext.expr() is DeltinScriptParser.E_expr_treeContext) { Flatten(script, (DeltinScriptParser.E_expr_treeContext)exprContext.expr(), exprList); } // Otherwise, add the expression to the list. else { // Get the function. if (exprContext.expr() is DeltinScriptParser.E_methodContext method) { exprList.Add(new FunctionPart(method.method())); } // Get the variable. else if (exprContext.expr() is DeltinScriptParser.E_variableContext variable) { exprList.Add(new VariableOrTypePart(variable.variable())); } // Get the expression. else { exprList.Add(new ExpressionPart(exprContext.expr())); } } // Syntax error if there is no method or variable. if (exprContext.method() == null && exprContext.variable() == null) { script.Diagnostics.Error("Expected expression.", DocRange.GetRange(exprContext.SEPERATOR())); _trailingSeperator = exprContext.SEPERATOR(); } else { // Get the method. if (exprContext.method() != null) { exprList.Add(new FunctionPart(exprContext.method())); } // Get the variable. if (exprContext.variable() != null) { exprList.Add(new VariableOrTypePart(exprContext.variable())); } } } }
public RuleAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Ow_ruleContext ruleContext) { Name = Extras.RemoveQuotes(ruleContext.STRINGLITERAL().GetText()); Disabled = ruleContext.DISABLED() != null; DocRange ruleInfoRange = DocRange.GetRange(ruleContext.RULE_WORD()); missingBlockRange = ruleInfoRange; GetRuleSettings(parseInfo, scope, ruleContext); // Store restricted calls CallInfo callInfo = new CallInfo(parseInfo.Script); // Get the conditions. if (ruleContext.rule_if() == null) { Conditions = new RuleIfAction[0]; } else { Conditions = new RuleIfAction[ruleContext.rule_if().Length]; for (int i = 0; i < Conditions.Length; i++) { parseInfo.Script.AddCompletionRange(new CompletionRange( scope, DocRange.GetRange(ruleContext.rule_if(i).LEFT_PAREN(), ruleContext.rule_if(i).RIGHT_PAREN()), CompletionRangeKind.Catch )); Conditions[i] = new RuleIfAction(parseInfo.SetCallInfo(callInfo), scope, ruleContext.rule_if(i)); missingBlockRange = DocRange.GetRange(ruleContext.rule_if(i)); } } // Get the block. if (ruleContext.block() != null) { Block = new BlockAction(parseInfo.SetCallInfo(callInfo), scope, ruleContext.block()); } else { parseInfo.Script.Diagnostics.Error("Missing block.", missingBlockRange); } // Check restricted calls. callInfo.CheckRestrictedCalls(EventType); // Get the rule order priority. if (ruleContext.number() != null) { Priority = double.Parse(ruleContext.number().GetText()); } ElementCountLens = new ElementCountCodeLens(ruleInfoRange, parseInfo.TranslateInfo.OptimizeOutput); parseInfo.Script.AddCodeLensRange(ElementCountLens); }
public override Node VisitBlock(DeltinScriptParser.BlockContext context) { Node[] statements = new Node[context.statement().Length]; for (int i = 0; i < statements.Length; i++) { statements[i] = VisitStatement(context.statement()[i]); } return(new BlockNode(statements, new Location(file, DocRange.GetRange(context)))); }
public void SetupBlock() { var parameterInfo = CodeParameter.GetParameters(parseInfo, ConstructorScope, context.setParameters()); Parameters = parameterInfo.Parameters; ParameterVars = parameterInfo.Variables; Block = new BlockAction(parseInfo.SetCallInfo(CallInfo), ConstructorScope, context.block()); parseInfo.Script.AddHover(DocRange.GetRange(context.name), GetLabel(true)); }
public override Node VisitCreatearray(DeltinScriptParser.CreatearrayContext context) { Node[] values = new Node[context.expr().Length]; for (int i = 0; i < values.Length; i++) { values[i] = VisitExpr(context.expr()[i]); } return(new CreateArrayNode(values, new Location(file, DocRange.GetRange(context)))); }
public CallMethodAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.MethodContext methodContext, bool usedAsExpression, Scope getter) { this.parseInfo = parseInfo; string methodName = methodContext.PART().GetText(); NameRange = DocRange.GetRange(methodContext.PART()); UsedAsExpression = usedAsExpression; if (methodContext.ASYNC() != null) { if (methodContext.NOT() == null) { Parallel = CallParallel.AlreadyRunning_RestartRule; } else { Parallel = CallParallel.AlreadyRunning_DoNothing; } } var options = scope.GetMethodsByName(methodName); if (options.Length == 0) { parseInfo.Script.Diagnostics.Error($"No method by the name of '{methodName}' exists in the current context.", NameRange); } else { OverloadChooser = new OverloadChooser(options, parseInfo, scope, getter, NameRange, DocRange.GetRange(methodContext), new OverloadError("method '" + methodName + "'")); OverloadChooser.Apply(methodContext.call_parameters()); CallingMethod = (IMethod)OverloadChooser.Overload; ParameterValues = OverloadChooser.Values; if (CallingMethod != null) { CallingMethod.Call(parseInfo, NameRange); // Todo: move this to DefinedFunction.Call. if (CallingMethod is DefinedFunction definedFunction) { definedFunction.OnBlockApply(this); parseInfo.CurrentCallInfo?.Call(definedFunction, NameRange); } if (Parallel != CallParallel.NoParallel && !CallingMethod.Attributes.Parallelable) { parseInfo.Script.Diagnostics.Error($"The method '{CallingMethod.Name}' cannot be called in parallel.", NameRange); } parseInfo.Script.AddHover(DocRange.GetRange(methodContext), CallingMethod.GetLabel(true)); } } }
public static CodeType GetCodeTypeFromContext(ParseInfo parseInfo, DeltinScriptParser.Code_typeContext typeContext) { if (typeContext == null) { return(null); } CodeType type = null; if (typeContext.PART() != null) { type = parseInfo.TranslateInfo.Types.GetCodeType(typeContext.PART().GetText(), parseInfo.Script.Diagnostics, DocRange.GetRange(typeContext)); } // Get generics if (typeContext.generics() != null) { // Create a list to store the generics. List <CodeType> generics = new List <CodeType>(); // Get the generics. foreach (var genericContext in typeContext.generics().code_type()) { generics.Add(GetCodeTypeFromContext(parseInfo, genericContext)); } if (type is Lambda.ValueBlockLambda) { type = new Lambda.ValueBlockLambda(generics[0], generics.Skip(1).ToArray()); } else if (type is Lambda.BlockLambda) { type = new Lambda.BlockLambda(generics.ToArray()); } else if (type is Lambda.MacroLambda) { type = new Lambda.MacroLambda(generics[0], generics.Skip(1).ToArray()); } } if (type != null) { type.Call(parseInfo, DocRange.GetRange(typeContext.PART())); } if (typeContext.INDEX_START() != null) { for (int i = 0; i < typeContext.INDEX_START().Length; i++) { type = new ArrayType(type); } } return(type); }
public LambdaAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.LambdaContext context) { Scope lambdaScope = scope.Child(); RecursiveCallHandler = new LambdaRecursionHandler(this); CallInfo = new CallInfo(RecursiveCallHandler, parseInfo.Script); // Get the lambda parameters. Parameters = new Var[context.define().Length]; InvokedState = new SubLambdaInvoke[Parameters.Length]; for (int i = 0; i < Parameters.Length; i++) { InvokedState[i] = new SubLambdaInvoke(); // TODO: Make custom builder. Parameters[i] = new ParameterVariable(lambdaScope, new DefineContextHandler(parseInfo, context.define(i)), InvokedState[i]); } CodeType[] argumentTypes = Parameters.Select(arg => arg.CodeType).ToArray(); // context.block() will not be null if the lambda is a block. // () => {} if (context.block() != null) { // Parse the block. Block = new BlockAction(parseInfo.SetCallInfo(CallInfo), lambdaScope, context.block()); // Validate the block. BlockTreeScan validation = new BlockTreeScan(parseInfo, Block, "lambda", DocRange.GetRange(context.INS())); validation.ValidateReturns(); if (validation.ReturnsValue) { LambdaType = new ValueBlockLambda(validation.ReturnType, argumentTypes); MultiplePaths = validation.MultiplePaths; } else { LambdaType = new BlockLambda(argumentTypes); } } // context.expr() will not be null if the lambda is an expression. // () => 2 * x else if (context.expr() != null) { // Get the lambda expression. Expression = parseInfo.SetCallInfo(CallInfo).GetExpression(lambdaScope, context.expr()); LambdaType = new MacroLambda(Expression.Type(), argumentTypes); } // Add so the lambda can be recursive-checked. parseInfo.TranslateInfo.RecursionCheck(CallInfo); // Add hover info parseInfo.Script.AddHover(DocRange.GetRange(context.INS()), new MarkupBuilder().StartCodeLine().Add(LambdaType.GetName()).EndCodeLine().ToString()); }