static void Main(string[] args) { string template = GetTemplate(args[1]); Context c = Context.GetXMLContext(args[0]); ParseManager manager = new ParseManager(); Template t = manager.Parse(template); string toWrite = t.Execute(c); SaveFile(args[2], toWrite); Console.WriteLine("Operation complete"); Console.Write("Press any key to continue..."); Console.ReadKey(); }
public string Execute(Context c, MacroTable table) { ParseManager manager = new ParseManager(); string toReturn = ""; if (conditionSignatures[conditionSignatures.Count - 1].Item1 == "else") { bool executed = false; for (int i = 0; i < conditionSignatures.Count - 1; ++i) { string toCheck = conditionSignatures[i].Item2; if (LogicManager.IsTrue(toCheck, c)) { toReturn = manager.Parse(conditionBodies[i]).Execute(c); executed = true; break; } } if (!executed) { toReturn = manager.Parse(conditionBodies[conditionBodies.Count - 1]).Execute(c); } } else { for (int i = 0; i < conditionSignatures.Count; ++i) { string toCheck = manager.Parse(conditionSignatures[i].Item2).Execute(c); if (LogicManager.IsTrue(toCheck, c)) { toReturn = manager.Parse(conditionBodies[i]).Execute(c, table); break; } } } return(toReturn); }
public string Execute(Context c, MacroTable table) { KeyValuePair <Tuple <string, int>, string> data = table.GetMacros(name, variables.Count()); if (data.Key.Item2 != -1) { List <string> parameters = data.Key.Item1.Split(' ').ToList(); parameters.RemoveAll(x => x == ""); parameters = parameters.Skip(1).ToList(); for (int i = 0; i < parameters.Count; ++i) { parameters[i] = parameters[i].Substring(1); } Context newContext = (Context)c.Clone(); for (int i = 0; i < parameters.Count; ++i) { if (variables[i].Length > 1 && variables[i][0] == '$') { string toPass = c.GetValue(variables[i].Substring(1)).ToString(); newContext.SetValue(parameters[i], toPass); } else { newContext.SetValue(parameters[i], variables[i]); } } ParseManager manager = new ParseManager(); Template innerMacros = manager.Parse(data.Value); string toReturn = innerMacros.Execute(newContext, table); return(toReturn); } else { throw new ArgumentException(String.Format("Macro table does not contain definition for method {0} with {1} parameters", name, variables.Count())); } }
public string Execute(Context c, MacroTable table) { object containerData = c.GetValue(containerName.Substring(1, containerName.Length - 1)); if (containerData != null) { IEnumerable <object> objects = containerData as IEnumerable <object>; if (objects != null) { ParseManager manager = new ParseManager(); Template t = manager.Parse(loopBody); string toReturn = ""; foreach (object obj in objects) { Context toPass = (Context)c.Clone(); toPass.SetValue(itemName.Substring(1, itemName.Length - 1), obj); toReturn += t.Execute(toPass, table); } return(toReturn); } else { throw new ArgumentException("Wrong data type for container"); } } else { throw new ArgumentException("Container not found"); } }
private static bool ComputePostfix(List <string> terms, Dictionary <string, string> replacements, Context c) { string toAdd = ""; ParseManager manager = new ParseManager(); for (int i = 0; i < terms.Count; ++i) { terms[i] = manager.Parse(terms[i]).Execute(c); } foreach (var kvp in replacements) { for (int i = 0; i < terms.Count; ++i) { if (terms[i] == kvp.Key) { terms[i] = kvp.Value; } } } while (terms.Count() != 1) { bool signFound = false; for (int i = 0; i < terms.Count(); ++i) { switch (terms[i]) { case "!=": case "==": case "&&": case "||": case ">=": case "<=": toAdd = Compute(terms[i - 2], terms[i - 1], terms[i]); terms.Insert(i - 2, toAdd); terms.RemoveAt(i - 1); terms.RemoveAt(i - 1); terms.RemoveAt(i - 1); signFound = true; break; case "!": toAdd = Compute(terms[i - 1], "", "!"); terms.Insert(i - 1, toAdd); terms.RemoveAt(i); terms.RemoveAt(i); signFound = true; break; } if (signFound) { signFound = false; break; } } } return(bool.Parse(terms[0])); }