public override Node VisitOw_rule(DeltinScriptParser.Ow_ruleContext context) { string name = context.STRINGLITERAL().GetText().Trim('"'); BlockNode block = (BlockNode)VisitBlock(context.block()); IExpressionNode[] conditions = new IExpressionNode[context.rule_if()?.expr().Length ?? 0]; Range[] conditionRanges = new Range[context.rule_if()?.expr().Length ?? 0]; for (int i = 0; i < conditions.Length; i++) { conditions[i] = (IExpressionNode)VisitExpr(context.rule_if().expr()[i]); conditionRanges[i] = Range.GetRange(context.rule_if().expr()[i]); } RuleEvent eventType = RuleEvent.OngoingGlobal; TeamSelector team = TeamSelector.All; PlayerSelector player = PlayerSelector.All; Range eventRange = null; Range teamRange = null; Range playerRange = null; foreach (var ruleOption in context.rule_option()) { string option = ruleOption.PART(0).GetText(); Range optionRange = Range.GetRange(ruleOption.PART(0).Symbol); string value = null; Range valueRange = null; if (ruleOption.PART().Length == 2) { value = ruleOption.PART(1).GetText(); valueRange = Range.GetRange(ruleOption.PART(1).Symbol); } switch (option) { case "Event": if (!Enum.TryParse <RuleEvent>(value, out eventType)) { _diagnostics.Add(new Diagnostic($"{value} is not a valid Event type.", valueRange)); } eventRange = Range.GetRange(ruleOption); break; case "Team": if (!Enum.TryParse <TeamSelector>(value, out team)) { _diagnostics.Add(new Diagnostic($"{value} is not a valid Team type.", valueRange)); } teamRange = Range.GetRange(ruleOption); break; case "Player": if (!Enum.TryParse <PlayerSelector>(value, out player)) { _diagnostics.Add(new Diagnostic($"{value} is not a valid Player type.", valueRange)); } playerRange = Range.GetRange(ruleOption); break; default: _diagnostics.Add(new Diagnostic($"{value} is not a valid rule option.", optionRange)); break; } } var node = new RuleNode(name, eventType, team, player, conditions, block, eventRange, teamRange, playerRange, Range.GetRange(context)); CheckRange(node); return(node); }