/// <summary>Finds any other entries in the given code fragment.</summary> /// <param name="fragment">The fragment to search.</param> public void FindOperations(CodeFragment fragment) { CodeFragment child = fragment.FirstChild; CodeFragment next = null; BracketFragment ovrs = null; while (child != null) { next = child.NextChild; if (child.IsParent) { // Got one! // Just gotta transfer it into the method body of OnScriptReady: if (ovrs == null) { ovrs = GetStartMethod().CodeBlock; } // Remove it as a child: child.Remove(); // Remove the word 'var' to ensure its properties are globally scoped. GloballyScope(child); // Add it to start method: ovrs.AddChild(child); } child = next; } }
public override AddResult AddTo(CodeFragment to, CodeLexer sr) { if (Value == "") { return(AddResult.Ok); } else if (Value == "var") { // We're reading a local: return(AddResult.Local); } else if (Value == "for" || Value == "while") { return(new ForFragment(sr, Value).AddTo(to, sr)); } else if (Value == "switch") { return(new SwitchFragment(sr).AddTo(to, sr)); } else if (Value == "if") { return(new IfFragment(sr).AddTo(to, sr)); } else if (Value == "else") { CodeFragment previous = to.ParentFragment; // Parent->prev operation->last object. Should be an IF. if (previous == null || ((previous = previous.LastChild) == null) || ((previous = previous.LastChild) == null) || previous.GetType() != typeof(IfFragment)) { Error("Else can only be applied to an if. E.g. if(){}else{}."); } IfFragment ifFrag = (IfFragment)previous; ifFrag.ApplyElseTo.SetIfFalse(new BracketFragment(sr)); return(AddResult.Stop); } else if (Value == "elseif") { CodeFragment previous = to.ParentFragment; // Parent->prev operation->last object. Should be an IF. if (previous == null || ((previous = previous.LastChild) == null) || ((previous = previous.LastChild) == null) || previous.GetType() != typeof(IfFragment)) { Error("Else if can only be applied to an if. E.g. if(){}else if{}.."); } IfFragment ifFrag = (IfFragment)previous; IfFragment newfrag = new IfFragment(sr); BracketFragment bf = new BracketFragment(); OperationFragment op = new OperationFragment(); op.AddChild(newfrag); bf.AddChild(op); ifFrag.ApplyElseTo.SetIfFalse(bf); ifFrag.ApplyElseTo = newfrag; return(AddResult.Stop); } else { return(base.AddTo(to, sr)); } }
public override AddResult AddTo(CodeFragment to,CodeLexer sr){ if(Value==""){ return AddResult.Ok; }else if(Value=="var"){ // We're reading a local: return AddResult.Local; }else if(Value=="for" || Value=="while"){ return new ForFragment(sr,Value).AddTo(to,sr); }else if(Value=="switch"){ return new SwitchFragment(sr).AddTo(to,sr); }else if(Value=="if"){ return new IfFragment(sr).AddTo(to,sr); }else if(Value=="else"){ CodeFragment previous=to.ParentFragment; // Parent->prev operation->last object. Should be an IF. if(previous==null||((previous=previous.LastChild)==null)||((previous=previous.LastChild)==null)||previous.GetType()!=typeof(IfFragment)){ Error("Else can only be applied to an if. E.g. if(){}else{}."); } IfFragment ifFrag=(IfFragment)previous; ifFrag.ApplyElseTo.SetIfFalse(new BracketFragment(sr)); return AddResult.Stop; }else if(Value=="elseif"){ CodeFragment previous=to.ParentFragment; // Parent->prev operation->last object. Should be an IF. if(previous==null||((previous=previous.LastChild)==null)||((previous=previous.LastChild)==null)||previous.GetType()!=typeof(IfFragment)){ Error("Else if can only be applied to an if. E.g. if(){}else if{}.."); } IfFragment ifFrag=(IfFragment)previous; IfFragment newfrag=new IfFragment(sr); BracketFragment bf=new BracketFragment(); OperationFragment op=new OperationFragment(); op.AddChild(newfrag); bf.AddChild(op); ifFrag.ApplyElseTo.SetIfFalse(bf); ifFrag.ApplyElseTo=newfrag; return AddResult.Stop; }else{ return base.AddTo(to,sr); } }