コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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++)
                {
                    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, scope, ruleContext.rule_if(i));
                    _missingBlockRange = DocRange.GetRange(ruleContext.rule_if(i));
                }
            }

            // Get the block.
            if (ruleContext.block() != null)
            {
                Block = new BlockAction(parseInfo, scope, ruleContext.block());
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Missing block.", _missingBlockRange);
            }

            // Get the rule order priority.
            if (ruleContext.number() != null)
            {
                Priority = double.Parse(ruleContext.number().GetText());
            }
        }
コード例 #4
0
        public RuleNode(DeltinScriptParser.Ow_ruleContext context, BuildAstVisitor visitor) : base(new Location(visitor.file, DocRange.GetRange(context)))
        {
            Name     = context.STRINGLITERAL().GetText().Trim('"');
            Block    = (BlockNode)visitor.VisitBlock(context.block());
            Disabled = context.DISABLED() != null;

            Conditions = new Node[context.rule_if().Length];
            DocRange[] conditionRanges = new DocRange          [context.rule_if().Length];

            for (int i = 0; i < context.rule_if().Length; i++)
            {
                if (context.rule_if(i).expr() != null)
                {
                    Conditions[i] = visitor.VisitExpr(context.rule_if(i).expr());
                }

                // Get the range between the ().
                conditionRanges[i] = DocRange.GetRange(
                    context.rule_if(i).LEFT_PAREN().Symbol,
                    context.rule_if(i).RIGHT_PAREN().Symbol
                    );
            }

            RuleEvent      eventType = RuleEvent.OngoingGlobal;
            Team           team      = Team.All;
            PlayerSelector player    = PlayerSelector.All;

            DocRange eventRange  = null;
            DocRange teamRange   = null;
            DocRange playerRange = null;

            foreach (var ruleOption in context.@enum())
            {
                string   option      = ruleOption.PART(0).GetText();
                DocRange optionRange = DocRange.GetRange(ruleOption.PART(0).Symbol);

                string   value      = ruleOption.PART(1)?.GetText();
                DocRange valueRange = null;
                if (value != null)
                {
                    valueRange = DocRange.GetRange(ruleOption.PART(1).Symbol);
                }

                DocRange totalRange;
                if (ruleOption.PART(1) != null)
                {
                    totalRange = DocRange.GetRange(ruleOption.PART(0).Symbol, ruleOption.PART(1).Symbol);
                }
                else
                {
                    totalRange = DocRange.GetRange(ruleOption.PART(0));
                }

                switch (option)
                {
                case "Event":
                    if (eventRange != null)
                    {
                        visitor._diagnostics.Error("Event already set.", new Location(visitor.file, totalRange));
                    }

                    if (!Enum.TryParse <RuleEvent>(value, out eventType))
                    {
                        visitor._diagnostics.Error($"{value} is not a valid Event type.", new Location(visitor.file, valueRange));
                    }

                    eventRange = DocRange.GetRange(ruleOption);
                    break;

                case "Team":
                    if (teamRange != null)
                    {
                        visitor._diagnostics.Error("Team already set.", new Location(visitor.file, totalRange));
                    }

                    if (!Enum.TryParse <Team>(value, out team))
                    {
                        visitor._diagnostics.Error($"{value} is not a valid Team type.", new Location(visitor.file, valueRange));
                    }

                    teamRange = DocRange.GetRange(ruleOption);
                    break;

                case "Player":
                    if (playerRange != null)
                    {
                        visitor._diagnostics.Error("Player already set.", new Location(visitor.file, totalRange));
                    }

                    if (!Enum.TryParse <PlayerSelector>(value, out player))
                    {
                        visitor._diagnostics.Error($"{value} is not a valid Player type.", new Location(visitor.file, valueRange));
                    }

                    playerRange = DocRange.GetRange(ruleOption);
                    break;

                default:
                    visitor._diagnostics.Error($"{option} is not a valid rule option.", new Location(visitor.file, optionRange));
                    break;
                }
            }
            Event  = eventType;
            Team   = team;
            Player = player;

            SubRanges = ArrayBuilder <DocRange> .Build(eventRange, teamRange, playerRange, conditionRanges);
        }