diff --git a/learnbot_dsl/learnbotCode/LearnBlock.py b/learnbot_dsl/learnbotCode/LearnBlock.py
index 4472d205..70f3a556 100755
--- a/learnbot_dsl/learnbotCode/LearnBlock.py
+++ b/learnbot_dsl/learnbotCode/LearnBlock.py
@@ -979,10 +979,10 @@ def textCodeToPython(self, name_Client):
msgBox.setStandardButtons(QtWidgets.QMessageBox.Ok)
msgBox.setDefaultButton(QtWidgets.QMessageBox.Ok)
msgBox.exec_()
-
- self.updateNotifications()
else:
self.ui.pythonCode.setPlainText(code)
+
+ self.updateNotifications()
return code
except ParseException as e:
traceback.print_exc()
diff --git a/learnbot_dsl/learnbotCode/Notification.py b/learnbot_dsl/learnbotCode/Notification.py
index bfef99d2..6970397b 100644
--- a/learnbot_dsl/learnbotCode/Notification.py
+++ b/learnbot_dsl/learnbotCode/Notification.py
@@ -13,6 +13,7 @@ class Notification(QtWidgets.QWidget):
def __init__(self, src, start, end = None, *args, **kwargs):
super().__init__(*args, **kwargs)
+ self.HINT = self.tr('Hint')
self.src = src
self.vLayout = QtWidgets.QVBoxLayout()
@@ -43,6 +44,7 @@ def __init__(self, src, start, end = None, *args, **kwargs):
font = QtGui.QFont()
font.setFamily('Courier')
font.setFixedPitch(True)
+
self.snippet.setFont(font)
self.snippet.setReadOnly(True)
self.snippet.setOffset(start[1]-1)
@@ -109,16 +111,15 @@ def setHints(self, hints):
for hint in hints:
item = QtWidgets.QLabel(self)
- item.setText(self.tr('Hint: ') + hint)
+ item.setText('' + self.HINT + ': ' + hint)
self.hints.addWidget(item)
-class SyntaxError(Notification):
- def __init__(self, *args, **kwargs):
+class InvalidSyntax(Notification):
+ def __init__(self, rule, *args, **kwargs):
super().__init__(*args, **kwargs)
- # TODO
hints = [
- self.tr('did you forget something while typing the %s
?') % 'TODO',
+ self.tr('did you forget something while typing the %s
?') % rule.__name__,
]
self.setSeverity(Severity.ERROR)
diff --git a/learnbot_dsl/learnbotCode/Parser.py b/learnbot_dsl/learnbotCode/Parser.py
index 56a86cd2..0ac216c3 100755
--- a/learnbot_dsl/learnbotCode/Parser.py
+++ b/learnbot_dsl/learnbotCode/Parser.py
@@ -72,7 +72,11 @@ class bcolors:
UNDERLINE = '\033[4m'
class Node:
+ last_stmt = None
+
def __init__(self, src, start, tokens):
+ global last_parsed
+
end = tokens[-1]
del tokens[-1]
@@ -95,6 +99,14 @@ def typecheck(self, ctx):
def used_vars(self):
return set()
+ @classmethod
+ def set_last_statement(cls, last):
+ cls.last_stmt = last
+
+ @classmethod
+ def last_statement(cls, last):
+ return cls.last_stmt
+
KEYWORDS = (
Keyword('def')
| Keyword('=')
@@ -233,19 +245,8 @@ def used_vars(self):
return {var for arg in self.args
for var in arg.used_vars}
- """
- @staticmethod
- def parse_failed(src, location, expr, error):
- print('+--------------+')
- print('| Parse error! |')
- print('+--------------+')
- print(f' line {lineno(location, src)}')
- print(f' col {col(location, src)}')
- raise ParseFatalException
- """
-
CALL = (
- Suppress(Literal('function'))
+ Suppress(Literal('function')).addParseAction(lambda: Node.set_last_statement(Call))
- Suppress(DOT)
- IDENTIFIER
- OPAR
@@ -278,7 +279,7 @@ def used_vars(self):
for var in arg.used_vars}
SIMPLECALL = (Group(
- IDENTIFIER
+ IDENTIFIER.addParseAction(lambda: Node.set_last_statement(SimpleCall))
+ OPAR
- Group(Optional(delimitedList(OPERATION)))
- CPAR
@@ -440,7 +441,7 @@ def used_vars(self):
VAR = (
INDENT
+ IDENTIFIER
- + (ASSIGN | PLUA | MINA | DIVA | MULA)
+ + (ASSIGN | PLUA | MINA | DIVA | MULA).addParseAction(lambda: Node.set_last_statement(Var))
- OPERATION
+ ENDLOC
).setParseAction(Var)
@@ -553,31 +554,31 @@ def used_vars(self):
ELSEIF << (
INDENT
- + Suppress(Literal('elif'))
+ + Suppress(Literal('elif')).addParseAction(lambda: Node.set_last_statement(ElseIf))
- OPERATION
- COLON
- LINES
+ ENDLOC
-).setParseAction(ElseIf).setResultsName('ELSEIF')
+).setParseAction(ElseIf)
ELSE << (
INDENT
- + Suppress(Literal('else'))
+ + Suppress(Literal('else')).addParseAction(lambda: Node.set_last_statement(Else))
- COLON
- LINES
+ ENDLOC
-).setParseAction(Else).setResultsName('ELSE')
+).setParseAction(Else)
IF = (
INDENT
- + Suppress(Literal('if'))
+ + Suppress(Literal('if')).addParseAction(lambda: Node.set_last_statement(If))
- OPERATION
- COLON
- LINES
- Group(ZeroOrMore(ELSEIF) + Optional(ELSE))
- END
+ ENDLOC
-).setParseAction(If).setResultsName('IF')
+).setParseAction(If)
"""-----------------LOOP----------------------------"""
class While(Node):
@@ -616,7 +617,7 @@ def used_vars(self):
BLOQUEWHILE = (
INDENT
- + Suppress(Literal('while'))
+ + Suppress(Literal('while')).addParseAction(lambda: Node.set_last_statement(While))
- OPERATION
- COLON
- LINES
@@ -690,7 +691,7 @@ def typecheck(self, ctx):
BLOQUEWHENCOND = (
INDENT
- + Suppress(Literal('when'))
+ + Suppress(Literal('when')).addParseAction(lambda: Node.set_last_statement(When))
- IDENTIFIER
- Optional(
Suppress(ASSIGN)
@@ -720,14 +721,14 @@ def to_python(self, gen, *_):
return f'state_{self.name} = False'
ACTIVATE = (
- Suppress(Literal('activate'))
- + IDENTIFIER
+ Suppress(Literal('activate')).addParseAction(lambda: Node.set_last_statement(Activate))
+ - IDENTIFIER
+ ENDLOC
).setParseAction(Activate)
DEACTIVATE = (
- Suppress(Literal('activate'))
- + IDENTIFIER
+ Suppress(Literal('deactivate')).addParseAction(lambda: Node.set_last_statement(Deactivate))
+ - IDENTIFIER
+ ENDLOC
).setParseAction(Deactivate)
@@ -779,7 +780,7 @@ def used_vars(self):
for var in node.used_vars}
DEF = (
- Suppress(Literal('def'))
+ Suppress(Literal('def')).addParseAction(lambda: Node.set_last_statement(Def))
- IDENTIFIER
- OPAR
- CPAR
@@ -801,7 +802,7 @@ def to_python(self, gen, *_):
return ''
IMPORT = (
- Suppress(Literal('import'))
+ Suppress(Literal('import')).addParseAction(lambda: Node.set_last_statement(Import))
- STRING
+ ENDLOC
).setParseAction(Import)
@@ -829,7 +830,7 @@ def used_vars(self):
for var in node.used_vars}
MAIN = (
- Suppress(Literal('main'))
+ Suppress(Literal('main')).addParseAction(lambda: Node.set_last_statement(Main))
- COLON
- LINES
- END
@@ -1082,15 +1083,26 @@ def parserLearntBotCode(inputFile, outputFile, client_name):
f.write(text)
return header + text, notifications
- except (ParseException, ParseSyntaxException) as pe:
+ except ParseSyntaxException as pe:
traceback.print_exc()
+ print("=================================")
+ print("ParseSyntaxException 1")
+ print("=================================")
+ print(pe.__dict__)
+
notifications.append(InvalidSyntax(
src = code,
start = (pe.lineno, pe.col, pe.loc)
))
+ return None, notifications
+ except ParseException as pe:
+ traceback.print_exc()
- finally:
+ notifications.append(InvalidSyntax(
+ src = code,
+ start = (pe.lineno, pe.col, pe.loc)
+ ))
return None, notifications
def parserLearntBotCodeFromCode(code, name_client):
@@ -1120,14 +1132,22 @@ def parserLearntBotCodeFromCode(code, name_client):
))
return header + text, notifications
- except (ParseException, ParseSyntaxException) as pe:
+ except ParseSyntaxException as pe:
+ traceback.print_exc()
+
+ notifications.append(InvalidSyntax(
+ src = code,
+ start = (pe.lineno, pe.col, pe.loc),
+ rule = Node.last_statement()
+ ))
+ return None, notifications
+ except ParseException as pe:
traceback.print_exc()
notifications.append(InvalidSyntax(
src = code,
- start = (pe.lineno, pe.col, pe.loc)
+ start = (pe.lineno, pe.col, pe.loc),
+ rule = Node.last_statement()
))
-
- finally:
return None, notifications
if __name__ == "__main__":
@@ -1135,12 +1155,11 @@ def parserLearntBotCodeFromCode(code, name_client):
main:
- function x()
+ x = 2
end
"""
try:
- """
print("Original source code")
print("====================")
print()
@@ -1178,7 +1197,6 @@ def parserLearntBotCodeFromCode(code, name_client):
print()
print(mismatches)
print()
- """
parserLearntBotCodeFromCode(textprueba, "robots")
except Exception as pe:
print(pe.line)
diff --git a/learnbot_dsl/learnbotCode/languages/t_en.qm b/learnbot_dsl/learnbotCode/languages/t_en.qm
index bbaeb429..e33e9f10 100644
Binary files a/learnbot_dsl/learnbotCode/languages/t_en.qm and b/learnbot_dsl/learnbotCode/languages/t_en.qm differ
diff --git a/learnbot_dsl/learnbotCode/languages/t_en.ts b/learnbot_dsl/learnbotCode/languages/t_en.ts
index 2f78d23e..114c99c0 100644
--- a/learnbot_dsl/learnbotCode/languages/t_en.ts
+++ b/learnbot_dsl/learnbotCode/languages/t_en.ts
@@ -1,6 +1,5 @@
-
-
+
Dialog
@@ -444,6 +443,19 @@
+
+ InvalidSyntax
+
+
+ did you forget something while typing the <code>%s</code>?
+
+
+
+
+ Invalid syntax
+
+
+
LearnBlock
@@ -1252,18 +1264,18 @@
Notification
-
- at %s:%sâ%s:%s
+
+ at %s:%sâ%s:%s
-
+
at %s:%s
-
- <b>Hint:</b>
+
+ Hint
@@ -1280,38 +1292,25 @@
-
- SyntaxError
-
-
- did you forget something while typing the <code>%s</code>?
-
-
-
-
- Invalid syntax
-
-
-
TypeMismatch
-
+
Type mismatch: expected %s, got %s
-
+
check the marked expression: does it really return a value of type <code>%s</code>?
-
+
did you make a typo while writing the expression? Check the operators!
-
+
be careful with operator precedence!
diff --git a/learnbot_dsl/learnbotCode/languages/t_es.qm b/learnbot_dsl/learnbotCode/languages/t_es.qm
index 83f00497..5c925e56 100644
Binary files a/learnbot_dsl/learnbotCode/languages/t_es.qm and b/learnbot_dsl/learnbotCode/languages/t_es.qm differ
diff --git a/learnbot_dsl/learnbotCode/languages/t_es.ts b/learnbot_dsl/learnbotCode/languages/t_es.ts
index 7d740d30..9450cafd 100644
--- a/learnbot_dsl/learnbotCode/languages/t_es.ts
+++ b/learnbot_dsl/learnbotCode/languages/t_es.ts
@@ -1,6 +1,5 @@
-
-
+
Dialog
@@ -476,6 +475,19 @@
+
+ InvalidSyntax
+
+
+ did you forget something while typing the <code>%s</code>?
+ ¿has olvidado algo al escribir el <code>%s</code>?
+
+
+
+ Invalid syntax
+ Sintaxis inválida
+
+
LearnBlock
@@ -1487,19 +1499,24 @@
Notification
-
- at %s:%sâ%s:%s
+
+ at %s:%sâ%s:%s
entre %s:%sâ%s:%s
-
+
at %s:%s
en %s:%s
<b>Hint:</b>
- <b>Pista:</b>
+ <b>Pista:</b>
+
+
+
+ Hint
+ Pista
@@ -1520,33 +1537,33 @@
did you forget something while typing the <code>%s</code>?
- ¿has olvidado algo al escribir el <code>%s</code>?
+ ¿has olvidado algo al escribir el <code>%s</code>?
Invalid syntax
- Sintaxis inválida
+ Sintaxis inválida
TypeMismatch
-
+
Type mismatch: expected %s, got %s
Tipos incompatibles: se esperaba un %s, pero se obtuvo un %s
-
+
check the marked expression: does it really return a value of type <code>%s</code>?
comprueba la expresión resaltada: ¿seguro que devuelve un valor de tipo <code>%s</code>?
-
+
did you make a typo while writing the expression? Check the operators!
¿has cometido algún error al escribir la expresión? ¡Comprueba los operadores!
-
+
be careful with operator precedence!
¡ten cuidado con la precedencia de operadores!
@@ -1717,7 +1734,7 @@ to load the updates close and reopen the program.
Select configuration file
-
+ Seleccionar fichero de configuración