Exemple #1
0
        private List<ProgramError> CompileJavascript(ProgramBlock program)
        {
            List<ProgramError> errors = new List<ProgramError>();

            Jint.Parser.JavaScriptParser jp = new Jint.Parser.JavaScriptParser(false);
            Jint.Parser.ParserOptions po = new Jint.Parser.ParserOptions();
            try
            {
                Jint.Parser.Ast.Program p = jp.Parse(program.ScriptCondition);
            }
            catch (Exception e)
            {
                // TODO: parse error message
                if (e.Message.Contains(":"))
                {
                    string[] error = e.Message.Split(':');
                    string message = error[1];
                    if (message != "hg is not defined") // TODO: find a better solution for this
                    {
                        int line = int.Parse(error[0].Split(' ')[0]);
                        errors.Add(new ProgramError()
                        {
                            Line = line,
                            ErrorMessage = message,
                            CodeBlock = "TC"
                        });
                    }
                }
            }
            //
            try
            {
                Jint.Parser.Ast.Program p = jp.Parse(program.ScriptSource);
            }
            catch (Exception e)
            {
                // TODO: parse error message
                if (e.Message.Contains(":"))
                {
                    string[] error = e.Message.Split(':');
                    string message = error[1];
                    if (message != "hg is not defined") // TODO: find a better solution for this
                    {
                        int line = int.Parse(error[0].Split(' ')[0]);
                        errors.Add(new ProgramError()
                        {
                            Line = line,
                            ErrorMessage = message,
                            CodeBlock = "CR"
                        });
                    }
                }
            }

            return errors;
        }