public static string Translate(HaJSCompiler compiler, string x) { int i = x.IndexOf("$"); while (i != -1) { int callOpen = x.IndexOf("(", i); if (callOpen != -1) { int callClose = x.IndexOf(")", callOpen); if (callClose != -1) { string feature = x.Substring(i + 1, callOpen - (i + 1)); string[] args = x.Substring(callOpen + 1, callClose - (callOpen + 1)).Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (compiler.HasFeature(feature)) { HaJSFeature f = compiler.GetFeature(feature); string replacement = f.Compile(compiler, args.ElementAtOrDefault(0), args.ElementAtOrDefault(1), args.ElementAtOrDefault(2)); x = x.Remove(i, callClose + 1 - i); // Remove old string x = x.Insert(i, replacement); // Insert our replacement i += replacement.Length; } } } if (i + 1 >= x.Length) { break; } i = x.IndexOf("$", i + 1); } return(x); }
public virtual string Compile(HaJSCompiler compiler, string x = null, string y = null, string z = null) { if (dep != null) { compiler.Dependencies.Add(dep); } string result = val; if (val.Contains("$.")) { result = result.Replace("$.", compiler.manager + "."); } if (val.Contains("$x")) { result = result.Replace("$x", x); } if (val.Contains("$y")) { result = result.Replace("$y", y); } if (val.Contains("$z")) { result = result.Replace("$z", z); } return(result); }
private void button2_Click(object sender, EventArgs e) { if (serverConfigPathBox.Text == "" || inputXmlBox.Text == "") { return; } HaJSCompiler jsc = new HaJSCompiler(serverConfigPathBox.Text); string folder = Path.GetDirectoryName(inputXmlBox.Text); foreach (FileInfo fi in new DirectoryInfo(folder).GetFiles()) { if (fi.Extension.ToLower() == ".xml") { #if !DEBUG try { #endif jsc.Compile(fi.FullName, Path.Combine(folder, Path.GetFileNameWithoutExtension(fi.FullName) + ".js")); #if !DEBUG } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } #endif } } MessageBox.Show("Finished compiling " + folder); }
public MessageBaseElement(HaJSCompiler compiler, string text) { if (ControlFlowBreaker) { status = compiler.RegisterMessage(this); } this.text = text; }
public override string Compile(HaJSCompiler compiler, string x = null, string y = null, string z = null) { string rval = base.Compile(compiler, x, y, z); string lval = left; if (left.Contains("$.")) { lval = lval.Replace("$.", compiler.manager + "."); } return(lval + " == " + rval); }
public override string PostCompile(HaJSCompiler compiler, HaJSElement parent) { StringBuilder sb = new StringBuilder(); sb.AppendLine("if (mode == 0)"); sb.AppendLine("{"); sb.AppendLine(IndentedStringBuilder.Indent + compiler.GetFeature("dlg_Ok").Compile(compiler, Stringify(noText))); sb.AppendLine(IndentedStringBuilder.Indent + compiler.GetFeature("special_End").Compile(compiler)); sb.AppendLine(IndentedStringBuilder.Indent + "return;"); sb.AppendLine("}"); return(sb.ToString()); }
public override string Compile(HaJSCompiler compiler) { string fullText = text + "#b"; for (int i = 0; i < Children.Count; i++) { OptionElement oe = (OptionElement)Children[i]; fullText += "\\r\\n#L" + i.ToString() + "#" + oe.Text + "#l"; } fullText += "#k"; return(compiler.GetFeature("dlg_Options").Compile(compiler, Stringify(fullText))); }
public override string PostCompile(HaJSCompiler compiler, HaJSElement parent) { StringBuilder sb = new StringBuilder(); sb.AppendLine("if (mode == 0)"); sb.AppendLine("{"); sb.AppendLine(IndentedStringBuilder.Indent + "status = " + GetPreviousStatus(parent).ToString()); sb.AppendLine(IndentedStringBuilder.Indent + "action(1,0,0);"); sb.AppendLine(IndentedStringBuilder.Indent + "return;"); sb.AppendLine("}"); return(sb.ToString()); }
public string GetLeft(HaJSCompiler compiler) { if (dep != null) { compiler.Dependencies.Add(dep); } string lval = left; if (left.Contains("$.")) { lval = lval.Replace("$.", compiler.manager + "."); } return(lval); }
public string Compile(HaJSCompiler compiler, HaJSSwitchFeature feature, bool first) { if (defCase) { return("else"); } StringBuilder sb = new StringBuilder(); sb.Append(first ? "if (" : "else if ("); if (arbitrary) { sb.Append(ArbitraryJSTranslator.Translate(compiler, value.Replace("$x", feature.GetLeft(compiler)))); } else { string[] rvalues = value.Split(",".ToCharArray()); sb.Append(rvalues.Select(x => feature.Compile(compiler, x)).Aggregate((x, y) => x + " || " + y)); } sb.Append(")"); return(sb.ToString()); }
private void button1_Click(object sender, EventArgs e) { if (serverConfigPathBox.Text == "" || inputXmlBox.Text == "") { return; } HaJSCompiler jsc = new HaJSCompiler(serverConfigPathBox.Text); string outPath = Path.Combine(Path.GetDirectoryName(inputXmlBox.Text), Path.GetFileNameWithoutExtension(inputXmlBox.Text) + ".js"); #if !DEBUG try { #endif jsc.Compile(inputXmlBox.Text, outPath); MessageBox.Show("Finished compiling to " + outPath); #if !DEBUG } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } #endif }
public OptionsMessageElement(HaJSCompiler compiler, string text) : base(compiler, text) { }
public virtual string PostCompile(HaJSCompiler compiler, HaJSElement parent) { return(null); }
public PrevNextMessageElement(HaJSCompiler compiler, string text) : base(compiler, text) { }
public string Compile(HaJSCompiler compiler) { args = args.Select(x => x == null ? x : ArbitraryJSTranslator.Translate(compiler, x)).ToList(); return(feature.Compile(compiler, args.ElementAtOrDefault(0), args.ElementAtOrDefault(1), args.ElementAtOrDefault(2)) + ";"); }
public abstract string Compile(HaJSCompiler compiler);
public override string Compile(HaJSCompiler compiler) { return(compiler.GetFeature("dlg_YesNo").Compile(compiler, Stringify(text))); }
public YesNoMessageElement(HaJSCompiler compiler, string text, string noText) : base(compiler, text) { this.noText = noText; }
public override string Compile(HaJSCompiler compiler) { return(style == -1 ? compiler.GetFeature("dlg_Ok").Compile(compiler, Stringify(text)) : compiler.GetFeature("dlg_OkExtended").Compile(compiler, Stringify(text), style.ToString())); }