Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL.Views/3.4/GpdlEditor.cs @ 9674

Last change on this file since 9674 was 9674, checked in by gkronber, 11 years ago

#2026: Worked on integration of ICSharpCode.AvalonEdit control for GPDL syntax-highlighting and error reporting.

File size: 2.4 KB
RevLine 
[9519]1using System;
2using System.IO;
3using System.Linq;
4using HeuristicLab.MainForm.WindowsForms;
5using HeuristicLab.Problems.Instances;
6using HeuristicLab.Problems.Instances.Views;
7
8namespace HeuristicLab.Problems.GPDL.Views {
9  public partial class GpdlEditor : AsynchronousContentView, IProblemInstanceConsumer<string> {
10    public GpdlEditor() {
11      InitializeComponent();
12
13      viewHost.Content = null; //necessary to enable the change of the ViewType
14      viewHost.ViewType = typeof(GpdlProblemInstanceConsumerView);
15      viewHost.Content = this;
16      ProblemInstanceConsumerView view = (ProblemInstanceConsumerView)viewHost.ActiveView;
17      splitContainer.Panel1Collapsed = !view.ProblemInstanceProviders.Any();
18    }
19
20    private void compileButton_Click(object sender, EventArgs e) {
[9674]21      Utils.InstallModule("Utils", Utils.UtilsMethod);
22      Utils.InstallModule("Sets", Sets.SetsMethod);
23      Utils.InstallModule("Errors", Errors.ErrorsMethod);
[9519]24
[9674]25      Utils.InstallModule("GPDefLex", GPDefLex.GPDefLexMethod);
26      Utils.InstallModule("GPDefSem", GPDefSem.GPDefSemMethod);
27      Utils.InstallModule("GPDefSyn", GPDefSyn.GPDefSynMethod);
[9519]28
29      // --- initialize modules ---
30      Utils.Modules(Utils.ModuleAction.initModule);
31
32      Errors.PushAbortMethod(new Errors.AbortMethod(Abort));
33
[9674]34      using (var src = new StringReader(codeEditor.textEditor.Text)) {
[9519]35        GPDefLex.src = src;
36        GPDefSyn.Parse();
37      }
38
[9674]39      codeEditor.ClearErrors();
[9519]40
[9674]41      if (Errors.NumOfErrors() == 0) {
42        GPDefLex.InitLex();
43        GPDefSyn.Interpret();
44
45        MainForm.MainFormManager.MainForm.ShowContent(GPDefSem.problem);
46      } else {
47        int nLexErrors = Errors.NumOfLexErrors();
48        for (int i = 0; i < nLexErrors; i++) {
49          var lexErr = Errors.GetLexError(i == 0);
50          codeEditor.SetLexError(lexErr.msg, lexErr.line, lexErr.col);
51        }
52        int nSynErrors = Errors.NumOfSynErrors();
53        for (int i = 0; i < nSynErrors; i++) {
54          var synErr = Errors.GetSynError(i == 0);
55          codeEditor.SetLexError(synErr.msg, synErr.line, synErr.col);
56        }
57      }
[9519]58    }
59
60    private void Abort(string abortKind, string moduleName, string methodName, string descr) {
61
62    }
63
64    void IProblemInstanceConsumer<string>.Load(string data) {
[9674]65      codeEditor.textEditor.Text = data;
[9519]66    }
67  }
68}
Note: See TracBrowser for help on using the repository browser.