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 RuleAction(ParseInfo parseInfo, Scope scope, RuleContext ruleContext) { Name = ruleContext.Name; Disabled = ruleContext.Disabled != null; DocRange ruleInfoRange = ruleContext.RuleToken.Range; GetRuleSettings(parseInfo, scope, ruleContext); // Store restricted calls CallInfo callInfo = new CallInfo(parseInfo.Script); // Get the conditions. Conditions = new ConditionAction[ruleContext.Conditions.Count]; for (int i = 0; i < Conditions.Length; i++) { // Make sure both left and right parentheses exists. if (ruleContext.Conditions[i].LeftParen && ruleContext.Conditions[i].RightParen) { parseInfo.Script.AddCompletionRange(new CompletionRange( parseInfo.TranslateInfo, scope, ruleContext.Conditions[i].LeftParen.Range + ruleContext.Conditions[i].RightParen.Range, CompletionRangeKind.Catch )); } Conditions[i] = new ConditionAction( parseInfo.SetCallInfo(callInfo).GetExpression(scope, ruleContext.Conditions[i].Expression), ruleContext.Conditions[i].Comment ); } // Get the block. Block = parseInfo.SetCallInfo(callInfo).GetStatement(scope, ruleContext.Statement); // Check restricted calls. callInfo.CheckRestrictedCalls(EventType); // Get the rule order priority. if (ruleContext.Order != null) { Priority = ruleContext.Order.Value; } ElementCountLens = new ElementCountCodeLens(ruleInfoRange); parseInfo.Script.AddCodeLensRange(ElementCountLens); }
public void SetupBlock() { if (_expressionToParse != null) { Expression = _parseInfo.SetCallInfo(CallInfo).GetExpression(_scope.Child(), _expressionToParse); } foreach (var listener in listeners) { listener.Applied(); } }
public void SetupBlock() { if (_expressionToParse != null) { Expression = _parseInfo.SetCallInfo(CallInfo).SetExpectingLambda(CodeType).GetExpression(_scope.Child(), _expressionToParse); } _wasApplied = true; foreach (var listener in listeners) { listener.Applied(); } }
public static void GetHook(ParseInfo parseInfo, Scope scope, Hook context) { parseInfo = parseInfo.SetCallInfo(new CallInfo(parseInfo.Script)); // Get the hook variable's expression. IExpression variableExpression = parseInfo.GetExpression(scope, context.Variable); // 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, context.Variable.Range, 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, context.Value.Range); } else { // Not a hook variable. parseInfo.Script.Diagnostics.Error("Expected a hook variable.", context.Variable.Range); } }
private void GetInitialValue() { // Get the initial value. if (_initialValueContext != null) { ParseInfo parseInfo = this._parseInfo; // Store the initial value's restricted calls. RestrictedCallList restrictedCalls = null; if (_handleRestrictedCalls) { restrictedCalls = new RestrictedCallList(); parseInfo = parseInfo.SetRestrictedCallHandler(restrictedCalls); } ParseInfo initialValueParseInfo = parseInfo.SetExpectType(CodeType); if (parseInfo.CurrentCallInfo == null) { CallInfo callInfo = new CallInfo(parseInfo.Script); initialValueParseInfo = initialValueParseInfo.SetCallInfo(callInfo); } // Parse the initial value. InitialValue = initialValueParseInfo.GetExpression(_operationalScope, _initialValueContext); // Get the inferred type. if (_inferType) { CodeType = InitialValue.Type(); _variableTypeHandler.SetType(CodeType); AddScriptData(); } // If the initial value's type is constant, make sure the constant type's implements the variable's type. if (InitialValue?.Type() != null && InitialValue.Type().IsConstant() && !InitialValue.Type().Implements(CodeType)) { parseInfo.Script.Diagnostics.Error($"The type '{InitialValue.Type().Name}' cannot be stored.", _initialValueContext.Range); } // If the variable's type is constant, make sure the value's type matches. else { SemanticsHelper.ExpectValueType(parseInfo, InitialValue, CodeType, _initialValueContext.Range); } // Check restricted calls. if (_handleRestrictedCalls) { foreach (RestrictedCall call in restrictedCalls) { // If the variable type is global, or the variable type is player and the restricted call type is not player... if (VariableType == VariableType.Global || (VariableType == VariableType.Player && call.CallType != RestrictedCallType.EventPlayer)) { // ... then add the error. call.AddDiagnostic(parseInfo.Script.Diagnostics); } } } } ValueReady.Set(); }