# HG changeset patch # User windel # Date 1317979206 -7200 # Node ID 1784af239df48b696215b367986256038c53c454 # Parent 818f80afa78bd8cfd53c4e3581c3351cc26d3cfb Added error list diff -r 818f80afa78b -r 1784af239df4 ide/compiler/compiler.py --- 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 diff -r 818f80afa78b -r 1784af239df4 ide/compiler/errors.py --- 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) diff -r 818f80afa78b -r 1784af239df4 ide/compiler/parser.py --- 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 diff -r 818f80afa78b -r 1784af239df4 ide/ide/ide.py --- 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: