public override Node VisitForeach(DeltinScriptParser.ForeachContext context) { Node array = Visit(context.expr()); string name = context.PART().GetText(); BlockNode block = (BlockNode)VisitBlock(context.block()); int repeaters = 1; if (context.number() != null) { repeaters = int.Parse(context.number().GetText()); } return(new ForEachNode(name, array, block, repeaters, new Location(file, Range.GetRange(context)))); }
public override Node VisitUser_method(DeltinScriptParser.User_methodContext context) { string name = context.PART(0).GetText(); string[] parameters = new string[context.PART().Length - 1]; for (int i = 0; i < parameters.Length; i++) { parameters[i] = context.PART(i + 1).GetText(); } BlockNode block = (BlockNode)VisitBlock(context.block()); Node node = new UserMethodNode(name, parameters, block, Range.GetRange(context)); CheckRange(node); return(node); }
private static void ReturnNodes(BlockNode block, List <ReturnNode> returnNodes) { foreach (var statement in block.Statements) { if (statement is IBlockContainer) { foreach (var container in ((IBlockContainer)statement).Paths()) { ReturnNodes(container.Block, returnNodes); } } if (statement is ReturnNode) { returnNodes.Add((ReturnNode)statement); } } }
public override Node VisitFor(DeltinScriptParser.ForContext context) { Node node; BlockNode block = (BlockNode)VisitBlock(context.block()); if (context.IN() != null) { IExpressionNode array = (IExpressionNode)Visit(context.expr()); string variable = context.PART().GetText(); node = new ForEachNode(variable, array, block, Range.GetRange(context)); } else { VarSetNode varSet = null; if (context.varset() != null) { varSet = (VarSetNode)VisitVarset(context.varset()); } ScopedDefineNode defineNode = null; if (context.define() != null) { defineNode = (ScopedDefineNode)VisitDefine(context.define()); } IExpressionNode expression = null; if (context.expr() != null) { expression = (IExpressionNode)VisitExpr(context.expr()); } IStatementNode statement = null; if (context.statement() != null) { statement = (IStatementNode)VisitStatement(context.statement()); } node = new ForNode(varSet, defineNode, expression, statement, block, Range.GetRange(context)); } CheckRange(node); return(node); }
public void ParseBlock(ScopeGroup getter, ScopeGroup scopeGroup, BlockNode blockNode, bool fulfillReturns, IndexedVar returnVar) { if (scopeGroup == null) { throw new ArgumentNullException(nameof(scopeGroup)); } blockNode.RelatedScopeGroup = scopeGroup; int returnSkipStart = ReturnSkips.Count; for (int i = 0; i < blockNode.Statements.Length; i++) { ParseStatement(getter, scopeGroup, blockNode.Statements[i], returnVar); } if (fulfillReturns) { FulfillReturns(returnSkipStart); } }
public override Node VisitIf(DeltinScriptParser.IfContext context) { // Get the if data IfData ifData = new IfData ( (IExpressionNode)VisitExpr(context.expr()), (BlockNode)VisitBlock(context.block()) ); // Get the else-if data IfData[] elseIfData = null; if (context.else_if() != null) { elseIfData = new IfData[context.else_if().Length]; for (int i = 0; i < context.else_if().Length; i++) { elseIfData[i] = new IfData ( (IExpressionNode)VisitExpr(context.else_if()[i].expr()), (BlockNode)VisitBlock(context.else_if()[i].block()) ); } } // Get the else block BlockNode elseBlock = null; if (context.@else() != null) { elseBlock = (BlockNode)VisitBlock(context.@else().block()); } Node node = new IfNode(ifData, elseIfData, elseBlock, Range.GetRange(context)); CheckRange(node); return(node); }
public IfNode(IfData ifData, IfData[] elseIfData, BlockNode elseBlock, Range range) : base(range) { IfData = ifData; ElseIfData = elseIfData; ElseBlock = elseBlock; }
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); }
public WhileNode(IExpressionNode expression, BlockNode block, Range range) : base(range) { Expression = expression; Block = block; }
public ForNode(VarSetNode varSetNode, ScopedDefineNode defineNode, IExpressionNode expression, IStatementNode statement, BlockNode block, Range range) : base(range) { VarSetNode = varSetNode; DefineNode = defineNode; Expression = expression; Statement = statement; Block = block; }
public ForEachNode(string variable, IExpressionNode array, BlockNode block, Range range) : base(range) { Array = array; Variable = variable; Block = block; }
public PathInfo(BlockNode block, Location errorRange, bool willRun) { Block = block; ErrorRange = errorRange; WillRun = willRun; }
public UserMethodNode(string name, string[] parameters, BlockNode block, Range range) : base(range) { Name = name; Parameters = parameters; Block = block; }
public RuleNode(string name, RuleEvent eventType, TeamSelector team, PlayerSelector player, IExpressionNode[] conditions, BlockNode block, Range eventRange, Range teamRange, Range playerRange, Range range) : base(range, eventRange, teamRange, playerRange) { Name = name; Event = eventType; Team = team; Player = player; Conditions = conditions; Block = block; }
public Constructor(AccessLevel accessLevel, ParameterBase[] parameters, BlockNode block) { AccessLevel = accessLevel; Parameters = parameters; BlockNode = block; }
public IfData(IExpressionNode expression, BlockNode block) { Expression = expression; Block = block; }
public RuleNode(DeltinScriptParser.Ow_ruleContext context, BuildAstVisitor visitor) : base(new Location(visitor.file, Range.GetRange(context))) { Name = context.STRINGLITERAL().GetText().Trim('"'); Block = (BlockNode)visitor.VisitBlock(context.block()); Conditions = new Node[context.rule_if().Length]; Range[] conditionRanges = new Range [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] = Range.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; Range eventRange = null; Range teamRange = null; Range playerRange = null; foreach (var ruleOption in context.@enum()) { string option = ruleOption.PART(0).GetText(); Range optionRange = Range.GetRange(ruleOption.PART(0).Symbol); string value = ruleOption.PART(1)?.GetText(); Range valueRange = null; if (value != null) { valueRange = Range.GetRange(ruleOption.PART(1).Symbol); } Range totalRange; if (ruleOption.PART(1) != null) { totalRange = Range.GetRange(ruleOption.PART(0).Symbol, ruleOption.PART(1).Symbol); } else { totalRange = Range.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 = Range.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 = Range.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 = Range.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 <Range> .Build(eventRange, teamRange, playerRange, conditionRanges); }
public ForNode(VarSetNode varSetNode, DefineNode defineNode, Node expression, VarSetNode statement, BlockNode block, Location location) : base(location) { VarSetNode = varSetNode; DefineNode = defineNode; Expression = expression; Statement = statement; Block = block; }
public IfNode(IfData ifData, IfData[] elseIfData, BlockNode elseBlock, Location location) : base(location) { IfData = ifData; ElseIfData = elseIfData; ElseBlock = elseBlock; }
public WhileNode(Node expression, BlockNode block, Location location) : base(location) { Expression = expression; Block = block; }