Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public MessageBaseElement(HaJSCompiler compiler, string text)
 {
     if (ControlFlowBreaker)
     {
         status = compiler.RegisterMessage(this);
     }
     this.text = text;
 }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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());
        }
Ejemplo n.º 7
0
        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)));
        }
Ejemplo n.º 8
0
        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());
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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());
        }
Ejemplo n.º 11
0
        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
        }
Ejemplo n.º 12
0
 public OptionsMessageElement(HaJSCompiler compiler, string text)
     : base(compiler, text)
 {
 }
Ejemplo n.º 13
0
 public virtual string PostCompile(HaJSCompiler compiler, HaJSElement parent)
 {
     return(null);
 }
Ejemplo n.º 14
0
 public PrevNextMessageElement(HaJSCompiler compiler, string text)
     : base(compiler, text)
 {
 }
Ejemplo n.º 15
0
 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)) + ";");
 }
Ejemplo n.º 16
0
 public abstract string Compile(HaJSCompiler compiler);
Ejemplo n.º 17
0
 public override string Compile(HaJSCompiler compiler)
 {
     return(compiler.GetFeature("dlg_YesNo").Compile(compiler, Stringify(text)));
 }
Ejemplo n.º 18
0
 public YesNoMessageElement(HaJSCompiler compiler, string text, string noText)
     : base(compiler, text)
 {
     this.noText = noText;
 }
Ejemplo n.º 19
0
 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()));
 }