Exemplo n.º 1
0
 void myPdflatexOutputParser_OnTexError(object sender, TexOutputParser.TexError e, Job job)
 {
     if (OnTexError != null)
     {
         OnTexError(sender, e, job);
     }
 }
        // Unfortunately, due to a debugger "bug", the exception has to be caught and transferred into a cancelled event
        // this cancel event type is AsyncParserResultType. It is passed to AsyncParser_RunWorkerCompleted().
        void AsyncParser_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            AsyncParserResultType Result = new AsyncParserResultType();
            //make sure that double typed numbers are converted with decimal point (not comma!) to string
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");

            try
            {
                AsyncParserJob job = e.Argument as AsyncParserJob;
                Tikz_ParseTree tp = TikzParser.Parse(job.code);
                Result.ParseTree = tp;
                Result.DocumentID = job.DocumentID;

                //include any styles from include files via \input cmd
                string inputfile = "";
                try
                {
                    //find input files using Regex
                    Regex InputsRegex = new Regex(@"(^[^%]*|\n[^\n%]*?)\\input{(?<file>.*)}", RegexOptions.Compiled);
                    MatchCollection files = InputsRegex.Matches(job.code);
                    foreach (Match file in files)
                    {
                        //open, read, parse, and close each included file.
                        inputfile = file.Groups["file"].ToString();
                        if (File.Exists(inputfile))
                        {
                            StreamReader sr = new StreamReader(inputfile);
                            string inputcode = sr.ReadToEnd();
                            sr.Close();
                            Tikz_ParseTree tp2 = TikzParser.ParseInputFile(inputcode);
                            //if tp2 == null there probably was nothing useful included.
                            if (tp2 != null)
                            {
                                //every style that was found in included file, add it to parse tree of main file.
                                foreach (KeyValuePair<string, Tikz_Option> style in tp2.styles)
                                {
                                    if(! Result.ParseTree.styles.ContainsKey(style.Key))
                                    {
                                        Result.ParseTree.styles.Add(style.Key, style.Value);
                                    }
                                    else
                                    {
                                        ParserException pe = new ParserException("");
                                        TexOutputParser.TexError te = new TexOutputParser.TexError();
                                        te.Message = "Style [" + style.Key + "] is defined multiple times. Check position " + style.Value.StartPosition() + " in " + inputfile + " and this definition.";
                                        te.pos = Result.ParseTree.styles[style.Key].StartPosition();
                                        te.severity = Severity.WARNING;
                                        pe.e = te;
                                        throw pe;
                                    }
                                }
                            }

                        }
                    }

                }
                catch (Exception ex)
                {
                    Result.Warning = ex;
                    Result.WarningSource = inputfile;
                }
            }
            catch (Exception ex)
            {
                //never set e.Cancel = true;
                //if you do, you cannot access e.Result from AsyncParser_RunWorkerCompleted.
                Result.Error = ex;
                Result.WarningSource = CurFile;
            }
            finally
            {
                e.Result = Result;
            }
        }
        private void Test2Click(object sender, RoutedEventArgs e)
        {
            TexOutputParser.TexError err = new TexOutputParser.TexError();
            err.Line = 33;
            err.Message = "blabla";
            err.severity = Severity.WARNING;
            addProblemMarker(this, err);

            err = new TexOutputParser.TexError();
            err.Line = 44;
            err.Message = "blabl2a";
            err.severity = Severity.ERROR;
            addProblemMarker(this, err);

            err = new TexOutputParser.TexError();
            err.Line = 55;
            err.Message = "blabla3";
            err.severity = Severity.ERROR;
            addProblemMarker(this, err);

            err = new TexOutputParser.TexError();
            err.Line = 66;
            err.Message = "blabla4";
            err.severity = Severity.NOTICE;
            addProblemMarker(this, err);

            err = new TexOutputParser.TexError();
            err.Line = 77;
            err.Message = "blabla5";
            err.severity = Severity.WARNING;
            addProblemMarker(this, err);
        }
 public void addProblemMarker(string msg, int line, int pos, Severity severity, string file)
 {
     TexOutputParser.TexError err = new TexOutputParser.TexError();
     err.error = msg;
     err.causingSourceFile = file;
     err.linenr = line;
     err.pos = pos;
     err.severity = severity;
     addProblemMarker(this, err);
 }