changeset 6:1784af239df4

Added error list
author windel
date Fri, 07 Oct 2011 11:20:06 +0200
parents 818f80afa78b
children 2db4d2b362e6
files ide/compiler/compiler.py ide/compiler/errors.py ide/compiler/parser.py ide/ide/ide.py
diffstat 4 files changed, 45 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/ide/compiler/compiler.py	Thu Sep 22 17:44:31 2011 +0200
+++ b/ide/compiler/compiler.py	Fri Oct 07 11:20:06 2011 +0200
@@ -16,11 +16,11 @@
 
    def compilesource(self, src):
       """ Front end that handles the stages: """
+      self.errorlist = []
       # Pass 1: parsing and type checking
       tokens = lexer.tokenize(src) # Lexical stage
       p = Parser(tokens)
       ast = p.parseModule() # Parse a module
-      print(p.errorlist)
       if len(p.errorlist) > 0:
          self.errorlist = p.errorlist
          return
--- a/ide/compiler/errors.py	Thu Sep 22 17:44:31 2011 +0200
+++ b/ide/compiler/errors.py	Fri Oct 07 11:20:06 2011 +0200
@@ -10,6 +10,11 @@
   def __str__(self):
      return self.msg
 
+class ErrorNode:
+   def __init__(self, row, col, msg):
+      self.row, self.col = row,col
+      self.msg = msg
+
 def Error(msg, node=None):
    if node is None:
       raise CompilerException(msg)
--- a/ide/compiler/parser.py	Thu Sep 22 17:44:31 2011 +0200
+++ b/ide/compiler/parser.py	Fri Oct 07 11:20:06 2011 +0200
@@ -360,6 +360,7 @@
      return procedures
 
    def parseProcedureDeclaration(self):
+     loc = self.getLocation()
      self.Consume('procedure')
      i = self.parseIdentDef()
      procname = i.name
@@ -405,6 +406,7 @@
         self.Error('endname should match {0}'.format(name))
      self.cst = procsymtable.parent    # Switch back to parent symbol table
      proc = Procedure(procname, proctyp, block, procsymtable, returnexpression)
+     self.setLocation(proc, loc)
      self.cst.addSymbol(proc)
      proc.public = i.ispublic
      return proc
--- a/ide/ide/ide.py	Thu Sep 22 17:44:31 2011 +0200
+++ b/ide/ide/ide.py	Fri Oct 07 11:20:06 2011 +0200
@@ -9,12 +9,22 @@
 module x;
 var 
  a,b,c : integer;
+
 procedure test(x:integer);
  var y,z:integer;
 begin
   y := x * 3 + 2;
   z := x + y + a;
 end test;
+
+procedure add(a:integer; b:integer):integer;
+ var 
+  tmp : integer;
+ begin
+  tmp := a + b;
+  return tmp
+ end add;
+
 begin
   a := 12;
   b := a * 12 + 33;
@@ -32,12 +42,29 @@
       self.setReadOnly(True)
       self.append('Build output will appear here!')
 
-class BuildErrors(QListWidget):
+class BuildErrors(QListView):
+   sigErrorSelected = pyqtSignal(object)
    def __init__(self, parent=None):
       super(BuildErrors, self).__init__(parent)
-      item = QListWidgetItem('Hallo dan!')
-      self.addItem(item)
-      
+      model = QStandardItemModel()
+      item = QStandardItem('Hallo dan!')
+      model.appendRow(item)
+      self.setModel(model)
+      self.clicked.connect(self.itemSelected)
+   def setErrorList(self, errorlist):
+      model = QStandardItemModel()
+      for e in errorlist:
+         item = QStandardItem(str(e))
+         item.setData(e)
+         model.appendRow(item)
+      self.setModel(model)
+   def itemSelected(self, index):
+      if not index.isValid():
+         return
+      model = self.model()
+      item = model.itemFromIndex(index)
+      err = item.data()
+      self.sigErrorSelected.emit(err)
 
 class Ide(QMainWindow):
   def __init__(self, parent=None):
@@ -64,6 +91,7 @@
 
     self.builderrors = BuildErrors()
     self.addComponent('Build errors', self.builderrors)
+    self.builderrors.sigErrorSelected.connect(self.errorSelected)
 
     # Create actions:
     self.buildAction = QAction('Build!', self)
@@ -105,6 +133,10 @@
       else:
          self.codeedit.clearErrors()
 
+  def errorSelected(self, err):
+     row, col, msg = err
+     self.codeedit.highlightErrorLocation(row, col)
+
   def buildFile(self):
      self.buildOutput.clear()
      self.codeedit.clearErrors()
@@ -113,6 +145,7 @@
      self.astViewer.setAst(None)
      try:
         output = self.compiler.compilesource(source)
+        self.builderrors.setErrorList(self.compiler.errorlist)
         self.astViewer.setAst(output)
         self.buildOutput.append("Done!")
      except compiler.errors.CompilerException as e: