Example #1
0
        public IfAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.IfContext ifContext)
        {
            // Get the if condition.
            if (ifContext.expr() != null)
            {
                Expression = DeltinScript.GetExpression(parseInfo, scope, ifContext.expr());
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(ifContext.LEFT_PAREN()));
            }

            // Contains the path info of all blocks in the if/else-if/else list.
            var paths = new List <PathInfo>();

            // Get the if's block.
            if (ifContext.block() != null)
            {
                Block = new BlockAction(parseInfo, scope, ifContext.block());
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Expected block.", DocRange.GetRange(ifContext.IF()));
            }

            // Add the if block path info.
            paths.Add(new PathInfo(Block, DocRange.GetRange(ifContext.IF()), false));

            // Get the else-ifs.
            if (ifContext.else_if() != null)
            {
                ElseIfs = new ElseIf[ifContext.else_if().Length];
                for (int i = 0; i < ElseIfs.Length; i++)
                {
                    ElseIfs[i] = new ElseIf(parseInfo, scope, ifContext.else_if(i));
                    paths.Add(new PathInfo(Block, DocRange.GetRange(ifContext.else_if(i).ELSE(), ifContext.else_if(i).IF()), false));
                }
            }
            // If there is none, set `ElseIfs` to an empty array since it should not be null.
            else
            {
                ElseIfs = new ElseIf[0];
            }

            // If there is an else statement, get the else block.
            if (ifContext.@else() != null)
            {
                if (ifContext.block() == null)
                {
                    parseInfo.Script.Diagnostics.Error("Expected block.", DocRange.GetRange(ifContext.@else().block()));
                }
                else
                {
                    ElseBlock = new BlockAction(parseInfo, scope, ifContext.@else().block());
                }

                // Add the else path info.
                paths.Add(new PathInfo(ElseBlock, DocRange.GetRange(ifContext.@else().ELSE()), true));
            }
            Paths = paths.ToArray();
        }
Example #2
0
 public override void Call(ParseInfo parseInfo, DocRange callRange)
 {
     base.Call(parseInfo, callRange);
     parseInfo.Script.Elements.AddDeclarationCall(Provider, new DeclarationCall(callRange, false));
     parseInfo.Script.AddDefinitionLink(callRange, Provider.DefinedAt);
 }
Example #3
0
 public VarInfo(string name, Location definedAt, ParseInfo parseInfo)
 {
     Name      = name;
     DefinedAt = definedAt;
     ParseInfo = parseInfo;
 }
Example #4
0
 public ParseReturnHandler(ParseInfo parseInfo)
 {
     _parseInfo = parseInfo;
 }
 public void Call(ParseInfo parseInfo, DocRange callRange)
 {
     IVariableInstance.Call(this, parseInfo, callRange);
     parseInfo.Script.AddDefinitionLink(callRange, Var.DefinedAt);
 }
Example #6
0
 public DefineContextHandler(ParseInfo parseInfo, VariableDeclaration defineContext)
 {
     _defineContext = defineContext;
     ParseInfo      = parseInfo;
 }
 public virtual void Call(ParseInfo parseInfo, DocRange callRange)
 {
     parseInfo.Script.AddHover(callRange, GetLabel(true));
 }
        void Translate()
        {
            AddComponent <RecursionCheckComponent>();

            // Get the enums
            foreach (ScriptFile script in Importer.ScriptFiles)
            {
                foreach (var enumContext in script.Context.Enums)
                {
                    var newEnum = new GenericCodeTypeInitializer(new DefinedEnum(new ParseInfo(script, this), enumContext));
                    RulesetScope.AddType(newEnum);
                    Types.AllTypes.Add(newEnum);
                    Types.DefinedTypes.Add(newEnum);
                }
            }

            // Get the types
            foreach (ScriptFile script in Importer.ScriptFiles)
            {
                foreach (var typeContext in script.Context.Classes)
                {
                    var newType = IDefinedTypeInitializer.GetInitializer(new ParseInfo(script, this), RulesetScope, typeContext);
                    RulesetScope.AddType(newType);
                    Types.AllTypes.Add(newType);
                    Types.DefinedTypes.Add(newType);
                }
            }

            // Get the variable reservations
            foreach (ScriptFile script in Importer.ScriptFiles)
            {
                foreach (Token reservation in script.Context.GlobalvarReservations)
                {
                    string text = reservation.GetText().RemoveQuotes();

                    if (Int32.TryParse(text, out int id))
                    {
                        VarCollection.Reserve(id, true, script.Diagnostics, reservation.Range);
                    }
                    else
                    {
                        VarCollection.Reserve(text, true);
                    }
                }
                foreach (Token reservation in script.Context.PlayervarReservations)
                {
                    string text = reservation.GetText().RemoveQuotes();

                    if (Int32.TryParse(text, out int id))
                    {
                        VarCollection.Reserve(id, false, script.Diagnostics, reservation.Range);
                    }
                    else
                    {
                        VarCollection.Reserve(text, false);
                    }
                }
            }
            // Get variable declarations
            foreach (ScriptFile script in Importer.ScriptFiles)
            {
                foreach (var declaration in script.Context.Declarations)
                {
                    if (declaration is VariableDeclaration variable)
                    {
                        Var var = new RuleLevelVariable(RulesetScope, new DefineContextHandler(new ParseInfo(script, this), variable)).GetVar();

                        if (var.StoreType != StoreType.None)
                        {
                            rulesetVariables.Add(var);

                            // Add the variable to the player variables scope if it is a player variable.
                            if (var.VariableType == VariableType.Player)
                            {
                                PlayerVariableScope.CopyVariable(var.GetDefaultInstance(null));
                            }
                        }
                    }
                }
            }

            ElementList.AddWorkshopFunctionsToScope(GlobalScope, Types); // Add workshop methods to global scope.
            GlobalFunctions.GlobalFunctions.Add(this, GlobalScope);      // Add built-in methods.

            // Get the function declarations
            foreach (ScriptFile script in Importer.ScriptFiles)
            {
                ParseInfo parseInfo = new ParseInfo(script, this);
                foreach (var declaration in script.Context.Declarations)
                {
                    if (declaration is FunctionContext function)
                    {
                        DefinedMethodProvider.GetDefinedMethod(parseInfo, this, function, null);
                    }
                }
            }

            StagedInitiation.Start();

            // Get hooks
            foreach (ScriptFile script in Importer.ScriptFiles)
            {
                foreach (var hookContext in script.Context.Hooks)
                {
                    HookVar.GetHook(new ParseInfo(script, this), RulesetScope, hookContext);
                }
            }

            // Get the rules
            foreach (ScriptFile script in Importer.ScriptFiles)
            {
                foreach (var ruleContext in script.Context.Rules)
                {
                    rules.Add(new RuleAction(new ParseInfo(script, this), RulesetScope, ruleContext));
                }
            }

            GetComponent <SymbolLinkComponent>().Collect();
        }
 public virtual void Call(ParseInfo parseInfo, DocRange callRange)
 {
 }
Example #10
0
        private void GetRuleSettings(ParseInfo parseInfo, Scope scope, RuleContext ruleContext)
        {
            RuleSetting teamContext = null, playerContext = null;
            bool        setEventType = false, setTeam = false, setPlayer = false;

            foreach (var setting in ruleContext.Settings)
            {
                // Add completion.
                switch (setting.Setting.Text)
                {
                case "Event": AddCompletion(parseInfo, setting.Dot, setting.Value, EventItems); break;

                case "Team": AddCompletion(parseInfo, setting.Dot, setting.Value, TeamItems); break;

                case "Player": AddCompletion(parseInfo, setting.Dot, setting.Value, PlayerItems); break;
                }

                // Get the value.
                if (setting.Value != null)
                {
                    var      alreadySet = new Diagnostic("The " + setting.Setting.Text + " rule setting was already set.", setting.Range, Diagnostic.Error);
                    string   name       = setting.Value.Text;
                    DocRange range      = setting.Value.Range;

                    switch (setting.Setting.Text)
                    {
                    case "Event":
                        if (setEventType)
                        {
                            parseInfo.Script.Diagnostics.AddDiagnostic(alreadySet);
                        }
                        EventType    = GetMember <RuleEvent>("Event", name, parseInfo.Script.Diagnostics, range);
                        setEventType = true;
                        break;

                    case "Team":
                        if (setTeam)
                        {
                            parseInfo.Script.Diagnostics.AddDiagnostic(alreadySet);
                        }
                        Team        = GetMember <Team>("Team", name, parseInfo.Script.Diagnostics, range);
                        setTeam     = true;
                        teamContext = setting;
                        break;

                    case "Player":
                        if (setPlayer)
                        {
                            parseInfo.Script.Diagnostics.AddDiagnostic(alreadySet);
                        }
                        Player        = GetMember <PlayerSelector>("Player", name, parseInfo.Script.Diagnostics, range);
                        setPlayer     = true;
                        playerContext = setting;
                        break;

                    default:
                        parseInfo.Script.Diagnostics.Error("Expected an enumerator of type 'Event', 'Team', or 'Player'.", setting.Setting.Range);
                        break;
                    }
                }
            }

            // Set the event type to player if the event type was not set and player or team was changed.
            if (!setEventType && ((setPlayer && Player != PlayerSelector.All) || (setTeam && Team != Team.All)))
            {
                EventType = RuleEvent.OngoingPlayer;
            }

            if (setEventType && EventType == RuleEvent.OngoingGlobal)
            {
                // Syntax error if the event type is global and the team type is not default.
                if (Team != Team.All)
                {
                    parseInfo.Script.Diagnostics.Error("Can't change rule Team type with an event type of Ongoing Global.", teamContext.Range);
                }
                // Syntax error if the event type is global and the player type is not default.
                if (Player != PlayerSelector.All)
                {
                    parseInfo.Script.Diagnostics.Error("Can't change rule Player type with an event type of Ongoing Global.", playerContext.Range);
                }
            }
        }
 public override void Call(ParseInfo parseInfo, DocRange callRange)
 {
     parseInfo.Script.AddDefinitionLink(callRange, DefinedAt);
     parseInfo.CurrentCallInfo?.Call(_recursiveCallHandler, callRange);
     ((DefinedType)Type).AddLink(parseInfo.GetLocation(callRange));
 }
Example #12
0
 public ReferenceCodeLensRange(ICallable callable, ParseInfo parseInfo, CodeLensSourceType sourceType, DocRange range) : base(sourceType, range, "ostw.showReferences")
 {
     Callable   = callable;
     _parseInfo = parseInfo;
 }
 public VariableApply(ParseInfo parseInfo)
 {
     _parseInfo = parseInfo;
 }
 public OperatorAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.E_op_compareContext context)
 {
     GetParts(parseInfo, scope, context.left, context.op.Text, DocRange.GetRange(context.op), context.right);
 }
Example #15
0
        public DefinedMethod(ParseInfo parseInfo, Scope objectScope, Scope staticScope, DeltinScriptParser.Define_methodContext context, CodeType containingType)
            : base(parseInfo, context.name.Text, new Location(parseInfo.Script.Uri, DocRange.GetRange(context.name)))
        {
            this.context = context;
            Attributes.ContainingType = containingType;

            DocRange nameRange = DocRange.GetRange(context.name);

            // Get the attributes.
            GetAttributes();

            SetupScope(Static ? staticScope : objectScope);

            // Get the type.
            if (context.VOID() == null)
            {
                doesReturnValue = true;
                ReturnType      = CodeType.GetCodeTypeFromContext(parseInfo, context.code_type());
            }

            // Setup the parameters and parse the block.
            if (!IsSubroutine)
            {
                SetupParameters(context.setParameters(), false);
            }
            else
            {
                Attributes.Parallelable = true;
                parseInfo.TranslateInfo.AddSubroutine(this);

                // Subroutines should not have parameters.
                SetupParameters(context.setParameters(), true);
            }

            // Override attribute.
            if (Attributes.Override)
            {
                IMethod overriding = objectScope.GetMethodOverload(this);

                // No method with the name and parameters found.
                if (overriding == null)
                {
                    parseInfo.Script.Diagnostics.Error("Could not find a method to override.", nameRange);
                }
                else if (!overriding.Attributes.IsOverrideable)
                {
                    parseInfo.Script.Diagnostics.Error("The specified method is not marked as virtual.", nameRange);
                }
                else
                {
                    overriding.Attributes.AddOverride(this);
                }

                if (overriding != null && overriding.DefinedAt != null)
                {
                    // Make the override keyword go to the base method.
                    parseInfo.Script.AddDefinitionLink(
                        attributes.First(at => at.Type == MethodAttributeType.Override).Range,
                        overriding.DefinedAt
                        );
                }
            }

            if (Attributes.IsOverrideable && AccessLevel == AccessLevel.Private)
            {
                parseInfo.Script.Diagnostics.Error("A method marked as virtual or abstract must have the protection level 'public' or 'protected'.", nameRange);
            }

            // Syntax error if the block is missing.
            if (context.block() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected block.", nameRange);
            }

            // Add to the scope. Check for conflicts if the method is not overriding.
            objectScope.AddMethod(this, parseInfo.Script.Diagnostics, nameRange, !Attributes.Override);

            // Add the hover info.
            parseInfo.Script.AddHover(DocRange.GetRange(context.name), GetLabel(true));

            if (Attributes.IsOverrideable)
            {
                parseInfo.Script.AddCodeLensRange(new ImplementsCodeLensRange(this, parseInfo.Script, CodeLensSourceType.Function, nameRange));
            }

            parseInfo.TranslateInfo.ApplyBlock(this);
        }
 public override void Call(ParseInfo parseInfo, DocRange callRange)
 {
     base.Call(parseInfo, callRange);
     parseInfo.Script.AddDefinitionLink(callRange, DefinedAt);
     AddLink(new LanguageServer.Location(parseInfo.Script.Uri, callRange));
 }
        public DefinedMethod(ParseInfo parseInfo, Scope objectScope, Scope staticScope, FunctionContext context, CodeType containingType)
            : base(parseInfo, context.Identifier.Text, new Location(parseInfo.Script.Uri, context.Identifier.Range))
        {
            this.Context = context;

            Attributes.ContainingType = containingType;

            DocRange nameRange = context.Identifier.Range;

            // Get the attributes.
            MethodAttributeAppender attributeResult = new MethodAttributeAppender(Attributes);
            MethodAttributesGetter  attributeGetter = new MethodAttributesGetter(context, attributeResult);

            attributeGetter.GetAttributes(parseInfo.Script.Diagnostics);

            // Copy attribute results
            Static         = attributeResult.Static;
            IsSubroutine   = attributeResult.IsSubroutine;
            SubroutineName = attributeResult.SubroutineName;
            AccessLevel    = attributeResult.AccessLevel;

            // Setup scope.
            SetupScope(Static ? staticScope : objectScope);
            methodScope.MethodContainer = true;

            // Get the type.
            if (!context.Type.IsVoid)
            {
                DoesReturnValue = true;
                CodeType        = CodeType.GetCodeTypeFromContext(parseInfo, context.Type);
            }

            // Setup the parameters and parse the block.
            if (!IsSubroutine)
            {
                SetupParameters(context.Parameters, false);
            }
            else
            {
                SubroutineDefaultGlobal = context.PlayerVar == null;
                Attributes.Parallelable = true;

                // Subroutines should not have parameters.
                SetupParameters(context.Parameters, true);
            }

            // Override attribute.
            if (Attributes.Override)
            {
                IMethod overriding = objectScope.GetMethodOverload(this);
                Attributes.Overriding = overriding;

                // No method with the name and parameters found.
                if (overriding == null)
                {
                    parseInfo.Script.Diagnostics.Error("Could not find a method to override.", nameRange);
                }
                else if (!overriding.Attributes.IsOverrideable)
                {
                    parseInfo.Script.Diagnostics.Error("The specified method is not marked as virtual.", nameRange);
                }
                else
                {
                    overriding.Attributes.AddOverride(this);
                }

                if (overriding != null && overriding.DefinedAt != null)
                {
                    // Make the override keyword go to the base method.
                    parseInfo.Script.AddDefinitionLink(
                        attributeGetter.ObtainedAttributes.First(at => at.Type == MethodAttributeType.Override).Range,
                        overriding.DefinedAt
                        );

                    if (!Attributes.Recursive)
                    {
                        Attributes.Recursive = overriding.Attributes.Recursive;
                    }
                }
            }

            if (Attributes.IsOverrideable && AccessLevel == AccessLevel.Private)
            {
                parseInfo.Script.Diagnostics.Error("A method marked as virtual or abstract must have the protection level 'public' or 'protected'.", nameRange);
            }

            // Add to the scope. Check for conflicts if the method is not overriding.
            containingScope.AddMethod(this, parseInfo.Script.Diagnostics, nameRange, !Attributes.Override);

            // Add the hover info.
            parseInfo.Script.AddHover(nameRange, GetLabel(true));

            if (Attributes.IsOverrideable)
            {
                parseInfo.Script.AddCodeLensRange(new ImplementsCodeLensRange(this, parseInfo.Script, CodeLensSourceType.Function, nameRange));
            }

            parseInfo.TranslateInfo.ApplyBlock(this);
        }
 public void CheckConflict(ParseInfo parseInfo, CheckConflict identifier, DocRange range) => RulesetScope.CheckConflict(parseInfo, identifier, range);
        private void GetRuleSettings(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Ow_ruleContext ruleContext)
        {
            DeltinScriptParser.ExprContext eventContext  = null;
            DeltinScriptParser.ExprContext teamContext   = null;
            DeltinScriptParser.ExprContext playerContext = null;

            foreach (var exprContext in ruleContext.expr())
            {
                _missingBlockRange = DocRange.GetRange(exprContext);

                var enumSetting = (DeltinScript.GetExpression(parseInfo, scope, exprContext) as ExpressionTree)?.Result as ScopedEnumMember;
                var enumData    = (enumSetting?.Enum as WorkshopEnumType)?.EnumData;

                if (enumData == null || !ValidRuleEnums.Contains(enumData))
                {
                    parseInfo.Script.Diagnostics.Error("Expected enum of type " + string.Join(", ", ValidRuleEnums.Select(vre => vre.CodeName)) + ".", DocRange.GetRange(exprContext));
                }
                else
                {
                    var alreadySet = new Diagnostic("The " + enumData.CodeName + " rule setting was already set.", DocRange.GetRange(exprContext), Diagnostic.Error);

                    // Get the Event option.
                    if (enumData == EnumData.GetEnum <RuleEvent>())
                    {
                        if (_setEventType)
                        {
                            parseInfo.Script.Diagnostics.AddDiagnostic(alreadySet);
                        }
                        EventType     = (RuleEvent)enumSetting.EnumMember.Value;
                        _setEventType = true;
                        eventContext  = exprContext;
                    }
                    // Get the Team option.
                    if (enumData == EnumData.GetEnum <Team>())
                    {
                        if (_setTeam)
                        {
                            parseInfo.Script.Diagnostics.AddDiagnostic(alreadySet);
                        }
                        Team        = (Team)enumSetting.EnumMember.Value;
                        _setTeam    = true;
                        teamContext = exprContext;
                    }
                    // Get the Player option.
                    if (enumData == EnumData.GetEnum <PlayerSelector>())
                    {
                        if (_setPlayer)
                        {
                            parseInfo.Script.Diagnostics.AddDiagnostic(alreadySet);
                        }
                        Player        = (PlayerSelector)enumSetting.EnumMember.Value;
                        _setPlayer    = true;
                        playerContext = exprContext;
                    }
                }
            }

            // Syntax error if changing the Team type when the Event type is set to Global.
            if (_setEventType && EventType == RuleEvent.OngoingGlobal)
            {
                if (Team != Team.All)
                {
                    parseInfo.Script.Diagnostics.Error("Can't change rule Team type with an event type of Ongoing Global.", DocRange.GetRange(teamContext));
                }
                if (Player != PlayerSelector.All)
                {
                    parseInfo.Script.Diagnostics.Error("Can't change rule Player type with an event type of Ongoing Global.", DocRange.GetRange(playerContext));
                }
            }
        }
 public void Call(ParseInfo parseInfo, DocRange callRange)
 {
     parseInfo.Script.AddDefinitionLink(callRange, DefinedAt);
     parseInfo.Script.AddHover(callRange, GetLabel(true));
     parseInfo.TranslateInfo.GetComponent <SymbolLinkComponent>().AddSymbolLink(this, new Location(parseInfo.Script.Uri, callRange));
 }
Example #21
0
        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 + "'"));

                if (methodContext.call_parameters() != null)
                {
                    OverloadChooser.SetContext(methodContext.call_parameters());
                }
                else if (methodContext.picky_parameters() != null)
                {
                    OverloadChooser.SetContext(methodContext.picky_parameters());
                }
                else
                {
                    OverloadChooser.SetContext();
                }

                CallingMethod   = (IMethod)OverloadChooser.Overload;
                ParameterValues = OverloadChooser.Values;

                if (CallingMethod != null)
                {
                    if (CallingMethod is DefinedFunction definedFunction)
                    {
                        definedFunction.OnBlockApply(this);
                        definedFunction.Call(parseInfo.Script, NameRange);
                        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));
                }
            }
        }
        void Translate()
        {
            // Get the reserved variables and IDs
            foreach (ScriptFile script in Importer.ScriptFiles)
            {
                if (script.Context.reserved_global()?.reserved_list() != null)
                {
                    foreach (var name in script.Context.reserved_global().reserved_list().PART())
                    {
                        VarCollection.Reserve(name.GetText(), true);
                    }
                    foreach (var id in script.Context.reserved_global().reserved_list().NUMBER())
                    {
                        VarCollection.Reserve(int.Parse(id.GetText()), true, null, null);
                    }
                }
                if (script.Context.reserved_player()?.reserved_list() != null)
                {
                    foreach (var name in script.Context.reserved_player().reserved_list().PART())
                    {
                        VarCollection.Reserve(name.GetText(), false);
                    }
                    foreach (var id in script.Context.reserved_player().reserved_list().NUMBER())
                    {
                        VarCollection.Reserve(int.Parse(id.GetText()), false, null, null);
                    }
                }
            }

            // Get the enums
            foreach (ScriptFile script in Importer.ScriptFiles)
            {
                foreach (var enumContext in script.Context.enum_define())
                {
                    var newEnum = new DefinedEnum(new ParseInfo(script, this), enumContext);
                    Types.AllTypes.Add(newEnum);
                    Types.DefinedTypes.Add(newEnum);
                    Types.CalledTypes.Add(newEnum);
                }
            }

            // Get the types
            foreach (ScriptFile script in Importer.ScriptFiles)
            {
                foreach (var typeContext in script.Context.type_define())
                {
                    var newType = new DefinedType(new ParseInfo(script, this), GlobalScope, typeContext);
                    Types.AllTypes.Add(newType);
                    Types.DefinedTypes.Add(newType);
                    Types.CalledTypes.Add(newType);
                }
            }

            // Get the methods and macros
            foreach (ScriptFile script in Importer.ScriptFiles)
            {
                ParseInfo parseInfo = new ParseInfo(script, this);

                // Get the methods.
                foreach (var methodContext in script.Context.define_method())
                {
                    new DefinedMethod(parseInfo, RulesetScope, RulesetScope, methodContext, null);
                }

                // Get the macros.
                foreach (var macroContext in script.Context.define_macro())
                {
                    parseInfo.GetMacro(RulesetScope, RulesetScope, macroContext);
                }
            }

            // Get the defined variables.
            foreach (ScriptFile script in Importer.ScriptFiles)
            {
                foreach (var varContext in script.Context.define())
                {
                    Var newVar = new RuleLevelVariable(RulesetScope, new DefineContextHandler(new ParseInfo(script, this), varContext));
                    rulesetVariables.Add(newVar);

                    // Add the variable to the player variables scope if it is a player variable.
                    if (newVar.VariableType == VariableType.Player)
                    {
                        PlayerVariableScope.CopyVariable(newVar);
                    }
                }
            }

            foreach (var applyType in Types.AllTypes)
            {
                if (applyType is ClassType classType)
                {
                    classType.ResolveElements();
                }
            }
            foreach (var apply in applyBlocks)
            {
                apply.SetupParameters();
            }
            foreach (var apply in applyBlocks)
            {
                apply.SetupBlock();
            }
            foreach (var apply in applyBlocks)
            {
                apply.CallInfo?.CheckRecursion();
            }

            // Get the rules
            foreach (ScriptFile script in Importer.ScriptFiles)
            {
                foreach (var ruleContext in script.Context.ow_rule())
                {
                    rules.Add(new RuleAction(new ParseInfo(script, this), RulesetScope, ruleContext));
                }
            }
        }
Example #23
0
        public ForAction(ParseInfo parseInfo, Scope scope, For forContext)
        {
            Scope varScope = scope.Child();

            IsAutoFor = forContext.Iterator is ExpressionStatement;

            // Get the initializer.
            if (!IsAutoFor)
            {
                // Normal for loop initializer.
                if (forContext.Initializer != null)
                {
                    // Declaration for initializer.
                    if (forContext.Initializer is VariableDeclaration declaration)
                    {
                        DefinedVariable = new ScopedVariable(varScope, new DefineContextHandler(parseInfo, declaration));
                    }
                    // Variable assignment for initializer
                    else if (forContext.Initializer is Assignment assignment)
                    {
                        Initializer = new SetVariableAction(parseInfo, varScope, assignment);
                    }

                    // TODO: Throw error on incorrect initializer type.
                }
            }
            else
            {
                // Auto-for initializer.
                // Missing initializer.
                if (forContext.Initializer == null)
                {
                    // Error if there is no initializer.
                    if (forContext.InitializerSemicolon)
                    {
                        parseInfo.Script.Diagnostics.Error("Auto-for loops require an initializer.", forContext.InitializerSemicolon.Range);
                    }
                }
                // Declaration
                else if (forContext.Initializer is VariableDeclaration declaration)
                {
                    DefinedVariable = new ScopedVariable(varScope, new DefineContextHandler(parseInfo, declaration));
                }
                // Assignment
                else if (forContext.Initializer is Assignment assignment)
                {
                    // Get the variable being set.
                    VariableResolve = new VariableResolve(new VariableResolveOptions()
                    {
                        // The for cannot be indexed and should be on the rule-level.
                        CanBeIndexed = false,
                        FullVariable = true
                    }, parseInfo.GetExpression(varScope, assignment.VariableExpression), assignment.VariableExpression.Range, parseInfo.Script.Diagnostics);

                    InitialResolveValue = parseInfo.GetExpression(scope, assignment.Value);
                }
                // Variable
                else if (forContext.Initializer is ExpressionStatement exprStatement && exprStatement.Expression is Identifier identifier)
                {
                    // The variable is defined but no start value was given. In this case, just start at 0.
                    // Get the variable.
                    VariableResolve = new VariableResolve(new VariableResolveOptions()
                    {
                        // The for cannot be indexed and should be on the rule-level.
                        CanBeIndexed = false,
                        FullVariable = true
                    }, parseInfo.GetExpression(varScope, identifier), identifier.Range, parseInfo.Script.Diagnostics);
                }
Example #24
0
 public override void Call(ParseInfo parseInfo, DocRange callRange)
 {
     base.Call(parseInfo, callRange);
     parseInfo.Script.AddDefinitionLink(callRange, DefinedAt);
     _translateInfo.GetComponent <SymbolLinkComponent>().AddSymbolLink(this, new Location(parseInfo.Script.Uri, callRange));
 }
 public InverseAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.ExprContext exprContext)
 {
     Expression = DeltinScript.GetExpression(parseInfo, scope, exprContext);
 }
Example #26
0
 public ParseReturnHandler(ParseInfo parseInfo, string objectName) : this(parseInfo)
 {
     VoidReturnValueMessage = objectName + " is void, so no value can be returned.";
 }
 public OperatorAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.E_op_boolContext context)
 {
     GetParts(parseInfo, scope, context.left, context.BOOL().GetText(), DocRange.GetRange(context.BOOL()), context.right);
 }
 /// <summary>Calls a type from the specified document range.</summary>
 /// <param name="parseInfo">The script that the type was called from.</param>
 /// <param name="callRange">The range of the call.</param>
 public virtual void Call(ParseInfo parseInfo, DocRange callRange)
 {
     parseInfo.TranslateInfo.Types.CallType(this);
     parseInfo.Script.AddHover(callRange, HoverHandler.Sectioned(Kind + " " + Name, Description));
     parseInfo.Script.AddToken(callRange, TokenType, TokenModifiers.ToArray());
 }
 public void Call(ParseInfo parseInfo, DocRange callRange)
 {
     parseInfo.Script.AddDefinitionLink(callRange, DefinedAt);
     parseInfo.TranslateInfo.GetComponent <SymbolLinkComponent>().AddSymbolLink(this, new Location(parseInfo.Script.Uri, callRange));
     parseInfo.CurrentCallInfo.Call(_recursiveCallHandler, callRange);
 }