public VarSetNode(DeltinScriptParser.VarsetContext context, BuildAstVisitor visitor) : base(new Location(visitor.file, Range.GetRange(context))) { Variable = visitor.VisitExpr(context.var); Node[] index = new Node[context.array()?.expr().Length ?? 0]; for (int i = 0; i < index.Length; i++) { index[i] = visitor.VisitExpr(context.array().expr(i)); } if (context.val != null) { Value = visitor.VisitExpr(context.val); } Operation = context.statement_operation()?.GetText(); if (Operation == null) { if (context.INCREMENT() != null) { Operation = "++"; } else if (context.DECREMENT() != null) { Operation = "--"; } } }
public ForNode(DeltinScriptParser.ForContext context, BuildAstVisitor visitor) : base(new Location(visitor.file, DocRange.GetRange(context))) { errorRange = new Location(visitor.file, DocRange.GetRange(context.FOR())); Block = (BlockNode)visitor.VisitBlock(context.block()); if (context.varset() != null) { VarSetNode = (VarSetNode)visitor.VisitVarset(context.varset()); } if (context.define() != null) { DefineNode = (DefineNode)visitor.VisitDefine(context.define()); } if (context.expr() != null) { Expression = visitor.VisitExpr(context.expr()); } if (context.forEndStatement() != null) { Statement = (VarSetNode)visitor.VisitVarset(context.forEndStatement().varset()); } }
public ExpressionTreeNode(DeltinScriptParser.ExprContext context, BuildAstVisitor visitor) : base(new Location(visitor.file, Range.GetRange(context))) { Tree = new Node[context.expr().Length]; for (int i = 0; i < Tree.Length; i++) { Tree[i] = visitor.VisitExpr(context.expr(i)); } }
public IfNode(DeltinScriptParser.IfContext context, BuildAstVisitor visitor) : base(new Location(visitor.file, DocRange.GetRange(context))) { // Get the if data IfData = new IfData ( visitor.VisitExpr(context.expr()), (BlockNode)visitor.VisitBlock(context.block()) ); paths.Add(new PathInfo(IfData.Block, new Location(visitor.file, DocRange.GetRange(context.IF())), false)); // Get the else-if data 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 ( visitor.VisitExpr(context.else_if(i).expr()), (BlockNode)visitor.VisitBlock(context.else_if(i).block()) ); paths.Add( new PathInfo( ElseIfData[i].Block, new Location( visitor.file, DocRange.GetRange( context.else_if(i).ELSE(), context.else_if(i).IF() ) ), false ) ); } } // Get the else block ElseBlock = null; if (context.@else() != null) { ElseBlock = (BlockNode)visitor.VisitBlock(context.@else().block()); paths.Add(new PathInfo(ElseBlock, new Location(visitor.file, DocRange.GetRange(context.@else().ELSE())), true)); } }
public CreateObjectNode(DeltinScriptParser.Create_objectContext context, BuildAstVisitor visitor) : base(new Location(visitor.file, Range.GetRange(context))) { TypeName = context.type.Text; Parameters = new Node[context.call_parameters()?.expr().Length ?? 0]; for (int i = 0; i < Parameters.Length; i++) { Parameters[i] = visitor.VisitExpr(context.call_parameters().expr()[i]); } }
public VariableNode(DeltinScriptParser.VariableContext context, BuildAstVisitor visitor) : base(new Location(visitor.file, Range.GetRange(context))) { Name = context.PART().GetText(); Index = new Node[context.array()?.expr().Length ?? 0]; for (int i = 0; i < Index.Length; i++) { Index[i] = visitor.VisitExpr(context.array().expr(i)); } }
public DefineNode(DeltinScriptParser.DefineContext context, BuildAstVisitor visitor) : base(new Location(visitor.file, DocRange.GetRange(context))) { VariableName = context.name.Text; Type = context.type?.Text; Extended = context.NOT() != null; if (context.expr() != null) { Value = visitor.VisitExpr(context.expr()); } }
public DefineNode(DeltinScriptParser.DefineContext context, BuildAstVisitor visitor) : base(new Location(visitor.file, Range.GetRange(context))) { VariableName = context.name.Text; Type = context.type?.Text; if (context.expr() != null) { Value = visitor.VisitExpr(context.expr()); } if (context.useVar() != null) { UseVar = (UseVarNode)visitor.VisitUseVar(context.useVar()); } }
public MacroNode(DeltinScriptParser.MacroContext context, BuildAstVisitor visitor) : base(new Location(visitor.file, DocRange.GetRange(context))) { Name = context.name.Text; Documentation = GetDocumentation(context.DOCUMENTATION()); Parameters = new ParameterDefineNode[context.setParameters().parameter_define().Length]; for (int i = 0; i < Parameters.Length; i++) { Parameters[i] = new ParameterDefineNode(context.setParameters().parameter_define(i), visitor); } AccessLevel = AccessLevel.Private; if (context.accessor() != null) { AccessLevel = (AccessLevel)Enum.Parse(typeof(AccessLevel), context.accessor().GetText(), true); } Expression = visitor.VisitExpr(context.expr()); }
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 TypeConvertNode(DeltinScriptParser.TypeconvertContext context, BuildAstVisitor visitor) : base(new Location(visitor.file, DocRange.GetRange(context))) { Type = context.PART().GetText(); Expression = visitor.VisitExpr(context.expr()); }
public DeleteNode(DeltinScriptParser.DeleteContext context, BuildAstVisitor visitor) : base(new Location(visitor.file, DocRange.GetRange(context))) { Delete = visitor.VisitExpr(context.expr()); }
public WhileNode(DeltinScriptParser.WhileContext context, BuildAstVisitor visitor) : base(new Location(visitor.file, DocRange.GetRange(context))) { Expression = visitor.VisitExpr(context.expr()); Block = (BlockNode)visitor.VisitBlock(context.block()); errorRange = new Location(visitor.file, DocRange.GetRange(context.WHILE())); }