Commit 1a05787e authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Introduce basic syntax support for state instance

parent a5988689
......@@ -8,7 +8,7 @@
The "Connection" class is the mother class, all other connectors must
inherit from it and possibly redefine some functions or shape.
Copyright (c) 2012-2014 European Space Agency
Copyright (c) 2012-2020 European Space Agency
Designed and implemented by Maxime Perrotin
......@@ -52,6 +52,8 @@ class Connection(QGraphicsPathItem):
self.setCacheMode(QGraphicsItem.DeviceCoordinateCache)
# When the child moves, the connection may need to adjust the end point
self.child.moved.connect(self.child_moved)
# Syntax error indicator
self.syntax_error: Boolean = False
@Slot(float, float)
def child_moved(self, delta_x, delta_y):
......
......@@ -6,7 +6,7 @@
SDL is the Specification and Description Language (Z100 standard from ITU)
Copyright (c) 2012-2019 European Space Agency
Copyright (c) 2012-2020 European Space Agency
Designed and implemented by Maxime Perrotin
......
......@@ -380,7 +380,10 @@ class EditableText(QGraphicsTextItem):
if(self.oldSize != self.parent.boundingRect()
or self.parent.syntax_error or self.oldText != str(self)):
# Call syntax checker from item containing the text (if any)
self.scene().check_syntax(self.parent)
if self.scene().check_syntax(self.parent):
# Keep focus
self.setFocus()
return
# Update class completion list
self.scene().update_completion_list(self.parentItem())
# Create undo command, including possible CAM
......
......@@ -171,7 +171,7 @@ class Symbol(QObject, QGraphicsPathItem):
self.movable_points = []
# Flag to indicate a detected syntax error, used to force the
# refocus of the text area to make sure user fixes it before saving
self.syntax_error: Boolean = False
self.syntax_error: bool = False
def set_valid_pos(self, pos):
''' Hook that can be redefined by sub classes to forbid wrong
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -737,6 +737,8 @@ class State:
# via clause, used for entering nested state with an entry point
# 'via' is the string for the renderer (e.g. "hello via foo")
self.via = None
# a state can be an instance of a state stype
self.instance_of = None
def trace(self):
''' Debug output for a STATE symbol '''
......
......@@ -3843,13 +3843,27 @@ def state(root, parent, context):
asterisk_state = False
asterisk_input = None
st_x, st_y = 0, 0
via_stop = None
via_stop, inst_stop = None, None
for child in root.getChildren():
if child.type == lexer.CIF:
# Get symbol coordinates
(state_def.pos_x, state_def.pos_y,
state_def.width, state_def.height) = cif(child)
st_x, st_y = state_def.pos_x, state_def.pos_y
elif child.type == lexer.ID:
# a single ID is only for state instances
state_def.inputString = get_input_string(child)
state_def.line = child.getLine()
state_def.charPositionInLine = child.getCharPositionInLine()
state_def.statelist = [state_def.inputString]
inst_stop = child.getTokenStopIndex()
elif child.type == lexer.TYPE_INSTANCE:
# Extract the complete string "state: instance"
start = inst_stop
stop = child.getTokenStopIndex()
full_string = token_stream(root).toString(start, stop)
state_def.inputString, state_def.instance_of = \
full_string, state_def.instance_of
elif child.type == lexer.STATELIST:
# State name(state_def)
state_def.inputString = get_input_string(child)
......
......@@ -783,13 +783,15 @@ class SDL_Scene(QGraphicsScene):
return symb.check_syntax('\n'.join(Pr.generate(symb, recursive=False)))
def check_syntax(self, symbol):
def check_syntax(self, symbol) -> bool:
''' Check syntax of a symbol and display a pop-up in case of errors '''
# return True if syntax errors were found
errors = self.syntax_errors(symbol)
if not errors:
symbol.syntax_error = False
return
return False
for view in self.views():
errs = []
......@@ -816,8 +818,11 @@ class SDL_Scene(QGraphicsScene):
msg_box.setDefaultButton(QMessageBox.Discard)
msg_box.exec_()
# There were syntax errors: force user to fix them
# by returning True to the caller (TextInteraction), which
# will keep focus
symbol.syntax_error = True
symbol.edit_text()
return True
#symbol.edit_text()
def global_syntax_check(self, ignore=set()):
......
# $ANTLR 3.5.2 sdl92.g 2020-06-30 17:24:04
# $ANTLR 3.5.2 sdl92.g 2020-07-08 14:24:25
import sys
from antlr3 import *
......@@ -493,8 +493,8 @@ class sdl92Lexer(Lexer):
_type = ASSIG_OP
_channel = DEFAULT_CHANNEL
# sdl92.g:1444:17: ( ':=' )
# sdl92.g:1444:25: ':='
# sdl92.g:1463:17: ( ':=' )
# sdl92.g:1463:25: ':='
pass
self.match(":=")
......@@ -516,8 +516,8 @@ class sdl92Lexer(Lexer):
_type = L_BRACKET
_channel = DEFAULT_CHANNEL
# sdl92.g:1445:17: ( '{' )
# sdl92.g:1445:25: '{'
# sdl92.g:1464:17: ( '{' )
# sdl92.g:1464:25: '{'
pass
self.match(123)
......@@ -538,8 +538,8 @@ class sdl92Lexer(Lexer):
_type = R_BRACKET
_channel = DEFAULT_CHANNEL
# sdl92.g:1446:17: ( '}' )
# sdl92.g:1446:25: '}'
# sdl92.g:1465:17: ( '}' )
# sdl92.g:1465:25: '}'
pass
self.match(125)
......@@ -560,8 +560,8 @@ class sdl92Lexer(Lexer):
_type = L_PAREN
_channel = DEFAULT_CHANNEL
# sdl92.g:1447:17: ( '(' )
# sdl92.g:1447:25: '('
# sdl92.g:1466:17: ( '(' )
# sdl92.g:1466:25: '('
pass
self.match(40)
......@@ -582,8 +582,8 @@ class sdl92Lexer(Lexer):
_type = R_PAREN
_channel = DEFAULT_CHANNEL
# sdl92.g:1448:17: ( ')' )
# sdl92.g:1448:25: ')'
# sdl92.g:1467:17: ( ')' )
# sdl92.g:1467:25: ')'
pass
self.match(41)
......@@ -604,8 +604,8 @@ class sdl92Lexer(Lexer):
_type = COMMA
_channel = DEFAULT_CHANNEL
# sdl92.g:1449:17: ( ',' )
# sdl92.g:1449:25: ','
# sdl92.g:1468:17: ( ',' )
# sdl92.g:1468:25: ','
pass
self.match(44)
......@@ -626,8 +626,8 @@ class sdl92Lexer(Lexer):
_type = SEMI
_channel = DEFAULT_CHANNEL
# sdl92.g:1450:17: ( ';' )
# sdl92.g:1450:25: ';'
# sdl92.g:1469:17: ( ';' )
# sdl92.g:1469:25: ';'
pass
self.match(59)
......@@ -648,8 +648,8 @@ class sdl92Lexer(Lexer):
_type = DASH
_channel = DEFAULT_CHANNEL
# sdl92.g:1451:17: ( '-' )
# sdl92.g:1451:25: '-'
# sdl92.g:1470:17: ( '-' )
# sdl92.g:1470:25: '-'
pass
self.match(45)
......@@ -670,8 +670,8 @@ class sdl92Lexer(Lexer):
_type = ANY
_channel = DEFAULT_CHANNEL
# sdl92.g:1452:17: ( A N Y )
# sdl92.g:1452:25: A N Y
# sdl92.g:1471:17: ( A N Y )
# sdl92.g:1471:25: A N Y
pass
self.mA()
......@@ -699,8 +699,8 @@ class sdl92Lexer(Lexer):
_type = ASTERISK
_channel = DEFAULT_CHANNEL
# sdl92.g:1453:17: ( '*' )
# sdl92.g:1453:25: '*'
# sdl92.g:1472:17: ( '*' )
# sdl92.g:1472:25: '*'
pass
self.match(42)
......@@ -721,8 +721,8 @@ class sdl92Lexer(Lexer):
_type = DCL
_channel = DEFAULT_CHANNEL
# sdl92.g:1454:17: ( D C L )
# sdl92.g:1454:25: D C L
# sdl92.g:1473:17: ( D C L )
# sdl92.g:1473:25: D C L
pass
self.mD()
......@@ -750,8 +750,8 @@ class sdl92Lexer(Lexer):
_type = END
_channel = DEFAULT_CHANNEL
# sdl92.g:1455:17: ( E N D )
# sdl92.g:1455:25: E N D
# sdl92.g:1474:17: ( E N D )
# sdl92.g:1474:25: E N D
pass
self.mE()
......@@ -779,8 +779,8 @@ class sdl92Lexer(Lexer):
_type = KEEP
_channel = DEFAULT_CHANNEL
# sdl92.g:1456:17: ( K E E P )
# sdl92.g:1456:25: K E E P
# sdl92.g:1475:17: ( K E E P )
# sdl92.g:1475:25: K E E P
pass
self.mK()
......@@ -811,8 +811,8 @@ class sdl92Lexer(Lexer):
_type = PARAMNAMES
_channel = DEFAULT_CHANNEL
# sdl92.g:1457:17: ( P A R A M N A M E S )
# sdl92.g:1457:25: P A R A M N A M E S
# sdl92.g:1476:17: ( P A R A M N A M E S )
# sdl92.g:1476:25: P A R A M N A M E S
pass
self.mP()
......@@ -861,8 +861,8 @@ class sdl92Lexer(Lexer):
_type = SPECIFIC
_channel = DEFAULT_CHANNEL
# sdl92.g:1458:17: ( S P E C I F I C )
# sdl92.g:1458:25: S P E C I F I C
# sdl92.g:1477:17: ( S P E C I F I C )
# sdl92.g:1477:25: S P E C I F I C
pass
self.mS()
......@@ -905,8 +905,8 @@ class sdl92Lexer(Lexer):
_type = GEODE
_channel = DEFAULT_CHANNEL
# sdl92.g:1459:17: ( G E O D E )
# sdl92.g:1459:25: G E O D E
# sdl92.g:1478:17: ( G E O D E )
# sdl92.g:1478:25: G E O D E
pass
self.mG()
......@@ -940,8 +940,8 @@ class sdl92Lexer(Lexer):
_type = HYPERLINK
_channel = DEFAULT_CHANNEL
# sdl92.g:1460:17: ( H Y P E R L I N K )
# sdl92.g:1460:25: H Y P E R L I N K
# sdl92.g:1479:17: ( H Y P E R L I N K )
# sdl92.g:1479:25: H Y P E R L I N K
pass
self.mH()
......@@ -987,8 +987,8 @@ class sdl92Lexer(Lexer):
_type = MKSTRING
_channel = DEFAULT_CHANNEL
# sdl92.g:1461:17: ( M K S T R I N G )
# sdl92.g:1461:25: M K S T R I N G
# sdl92.g:1480:17: ( M K S T R I N G )
# sdl92.g:1480:25: M K S T R I N G
pass
self.mM()
......@@ -1031,8 +1031,8 @@ class sdl92Lexer(Lexer):
_type = ENDTEXT
_channel = DEFAULT_CHANNEL
# sdl92.g:1462:17: ( E N D T E X T )
# sdl92.g:1462:25: E N D T E X T
# sdl92.g:1481:17: ( E N D T E X T )
# sdl92.g:1481:25: E N D T E X T
pass
self.mE()
......@@ -1072,8 +1072,8 @@ class sdl92Lexer(Lexer):
_type = RETURN
_channel = DEFAULT_CHANNEL
# sdl92.g:1463:17: ( R E T U R N )
# sdl92.g:1463:25: R E T U R N
# sdl92.g:1482:17: ( R E T U R N )
# sdl92.g:1482:25: R E T U R N
pass
self.mR()
......@@ -1110,8 +1110,8 @@ class sdl92Lexer(Lexer):
_type = RETURNS
_channel = DEFAULT_CHANNEL
# sdl92.g:1464:17: ( R E T U R N S )
# sdl92.g:1464:25: R E T U R N S
# sdl92.g:1483:17: ( R E T U R N S )
# sdl92.g:1483:25: R E T U R N S
pass
self.mR()
......@@ -1151,8 +1151,8 @@ class sdl92Lexer(Lexer):
_type = TIMER
_channel = DEFAULT_CHANNEL
# sdl92.g:1465:17: ( T I M E R )
# sdl92.g:1465:25: T I M E R
# sdl92.g:1484:17: ( T I M E R )
# sdl92.g:1484:25: T I M E R
pass
self.mT()
......@@ -1186,8 +1186,8 @@ class sdl92Lexer(Lexer):
_type = PROCESS
_channel = DEFAULT_CHANNEL
# sdl92.g:1466:17: ( P R O C E S S )
# sdl92.g:1466:25: P R O C E S S
# sdl92.g:1485:17: ( P R O C E S S )
# sdl92.g:1485:25: P R O C E S S
pass
self.mP()
......@@ -1227,8 +1227,8 @@ class sdl92Lexer(Lexer):
_type = TYPE
_channel = DEFAULT_CHANNEL
# sdl92.g:1467:17: ( T Y P E )
# sdl92.g:1467:25: T Y P E
# sdl92.g:1486:17: ( T Y P E )
# sdl92.g:1486:25: T Y P E
pass
self.mT()
......@@ -1259,8 +1259,8 @@ class sdl92Lexer(Lexer):
_type = ENDPROCESS
_channel = DEFAULT_CHANNEL
# sdl92.g:1468:17: ( E N D P R O C E S S )
# sdl92.g:1468:25: E N D P R O C E S S
# sdl92.g:1487:17: ( E N D P R O C E S S )
# sdl92.g:1487:25: E N D P R O C E S S
pass
self.mE()
......@@ -1309,8 +1309,8 @@ class sdl92Lexer(Lexer):
_type = START
_channel = DEFAULT_CHANNEL
# sdl92.g:1469:17: ( S T A R T )
# sdl92.g:1469:25: S T A R T
# sdl92.g:1488:17: ( S T A R T )
# sdl92.g:1488:25: S T A R T
pass
self.mS()
......@@ -1344,8 +1344,8 @@ class sdl92Lexer(Lexer):
_type = STATE
_channel = DEFAULT_CHANNEL
# sdl92.g:1470:17: ( S T A T E )
# sdl92.g:1470:25: S T A T E
# sdl92.g:1489:17: ( S T A T E )
# sdl92.g:1489:25: S T A T E
pass
self.mS()
......@@ -1379,8 +1379,8 @@ class sdl92Lexer(Lexer):
_type = TEXT
_channel = DEFAULT_CHANNEL
# sdl92.g:1471:17: ( T E X T )
# sdl92.g:1471:25: T E X T
# sdl92.g:1490:17: ( T E X T )
# sdl92.g:1490:25: T E X T
pass
self.mT()
......@@ -1411,8 +1411,8 @@ class sdl92Lexer(Lexer):
_type = PROCEDURE
_channel = DEFAULT_CHANNEL
# sdl92.g:1472:17: ( P R O C E D U R E )
# sdl92.g:1472:25: P R O C E D U R E
# sdl92.g:1491:17: ( P R O C E D U R E )
# sdl92.g:1491:25: P R O C E D U R E
pass
self.mP()
......@@ -1458,8 +1458,8 @@ class sdl92Lexer(Lexer):
_type = ENDPROCEDURE
_channel = DEFAULT_CHANNEL
# sdl92.g:1473:17: ( E N D P R O C E D U R E )
# sdl92.g:1473:25: E N D P R O C E D U R E
# sdl92.g:1492:17: ( E N D P R O C E D U R E )
# sdl92.g:1492:25: E N D P R O C E D U R E
pass
self.mE()
......@@ -1514,8 +1514,8 @@ class sdl92Lexer(Lexer):
_type = PROCEDURE_CALL
_channel = DEFAULT_CHANNEL
# sdl92.g:1474:17: ( P R O C E D U R E C A L L )
# sdl92.g:1474:25: P R O C E D U R E C A L L
# sdl92.g:1493:17: ( P R O C E D U R E C A L L )
# sdl92.g:1493:25: P R O C E D U R E C A L L
pass
self.mP()
......@@ -1573,8 +1573,8 @@ class sdl92Lexer(Lexer):
_type = ENDSTATE
_channel = DEFAULT_CHANNEL
# sdl92.g:1475:17: ( E N D S T A T E )
# sdl92.g:1475:25: E N D S T A T E
# sdl92.g:1494:17: ( E N D S T A T E )
# sdl92.g:1494:25: E N D S T A T E
pass
self.mE()
......@@ -1617,8 +1617,8 @@ class sdl92Lexer(Lexer):
_type = INPUT
_channel = DEFAULT_CHANNEL
# sdl92.g:1476:17: ( I N P U T )
# sdl92.g:1476:25: I N P U T
# sdl92.g:1495:17: ( I N P U T )
# sdl92.g:1495:25: I N P U T
pass
self.mI()
......@@ -1652,8 +1652,8 @@ class sdl92Lexer(Lexer):
_type = PROVIDED
_channel = DEFAULT_CHANNEL
# sdl92.g:1477:17: ( P R O V I D E D )
# sdl92.g:1477:25: P R O V I D E D
# sdl92.g:1496:17: ( P R O V I D E D )
# sdl92.g:1496:25: P R O V I D E D
pass
self.mP()
......@@ -1696,8 +1696,8 @@ class sdl92Lexer(Lexer):
_type = PRIORITY
_channel = DEFAULT_CHANNEL
# sdl92.g:1478:17: ( P R I O R I T Y )
# sdl92.g:1478:25: P R I O R I T Y
# sdl92.g:1497:17: ( P R I O R I T Y )
# sdl92.g:1497:25: P R I O R I T Y
pass
self.mP()
......@@ -1740,8 +1740,8 @@ class sdl92Lexer(Lexer):
_type = SAVE
_channel = DEFAULT_CHANNEL
# sdl92.g:1479:17: ( S A V E )
# sdl92.g:1479:25: S A V E
# sdl92.g:1498:17: ( S A V E )
# sdl92.g:1498:25: S A V E
pass
self.mS()
......@@ -1772,8 +1772,8 @@ class sdl92Lexer(Lexer):
_type = NONE
_channel = DEFAULT_CHANNEL
# sdl92.g:1480:17: ( N O N E )
# sdl92.g:1480:25: N O N E
# sdl92.g:1499:17: ( N O N E )
# sdl92.g:1499:25: N O N E
pass
self.mN()
......@@ -1804,8 +1804,8 @@ class sdl92Lexer(Lexer):
_type = FOR
_channel = DEFAULT_CHANNEL
# sdl92.g:1487:17: ( F O R )
# sdl92.g:1487:25: F O R
# sdl92.g:1506:17: ( F O R )
# sdl92.g:1506:25: F O R
pass
self.mF()
......@@ -1833,8 +1833,8 @@ class sdl92Lexer(Lexer):
_type = ENDFOR
_channel = DEFAULT_CHANNEL
# sdl92.g:1488:17: ( E N D F O R )
# sdl92.g:1488:25: E N D F O R
# sdl92.g:1507:17: ( E N D F O R )
# sdl92.g:1507:25: E N D F O R
pass
self.mE()
......@@ -1871,8 +1871,8 @@ class sdl92Lexer(Lexer):
_type = RANGE
_channel = DEFAULT_CHANNEL
# sdl92.g:1489:17: ( R A N G E )
# sdl92.g:1489:25: R A N G E
# sdl92.g:1508:17: ( R A N G E )
# sdl92.g:1508:25: R A N G E
pass
self.mR()
......@@ -1906,8 +1906,8 @@ class sdl92Lexer(Lexer):
_type = NEXTSTATE
_channel = DEFAULT_CHANNEL
# sdl92.g:1490:17: ( N E X T S T A T E )
# sdl92.g:1490:25: N E X T S T A T E
# sdl92.g:1509:17: ( N E X T S T A T E )
# sdl92.g:1509:25: N E X T S T A T E
pass
self.mN()
......@@ -1953,8 +1953,8 @@ class sdl92Lexer(Lexer):
_type = ANSWER
_channel = DEFAULT_CHANNEL
# sdl92.g:1491:17: ( A N S W E R )
# sdl92.g:1491:25: A N S W E R
# sdl92.g:1510:17: ( A N S W E R )
# sdl92.g:1510:25: A N S W E R
pass
self.mA()
......@@ -1991,8 +1991,8 @@ class sdl92Lexer(Lexer):
_type = COMMENT
_channel = DEFAULT_CHANNEL
# sdl92.g:1492:17: ( C O M M E N T )
# sdl92.g:1492:25: C O M M E N T
# sdl92.g:1511:17: ( C O M M E N T )
# sdl92.g:1511:25: C O M M E N T
pass
self.mC()
......@@ -2032,8 +2032,8 @@ class sdl92Lexer(Lexer):
_type = LABEL
_channel = DEFAULT_CHANNEL
# sdl92.g:1493:17: ( L A B E L )
# sdl92.g:1493:25: L A B E L
# sdl92.g:1512:17: ( L A B E L )
# sdl92.g:1512:25: L A B E L
pass
self.mL()
......@@ -2067,8 +2067,8 @@ class sdl92Lexer(Lexer):
_type = STOP
_channel = DEFAULT_CHANNEL
# sdl92.g:1494:17: ( S T O P )
# sdl92.g:1494:25: S T O P
# sdl92.g:1513:17: ( S T O P )
# sdl92.g:1513:25: S T O P
pass
self.mS()
......@@ -2099,8 +2099,8 @@ class sdl92Lexer(Lexer):
_type = IF
_channel = DEFAULT_CHANNEL
# sdl92.g:1495:17: ( I F )
# sdl92.g:1495:25: I F
# sdl92.g:1514:17: ( I F )
# sdl92.g:1514:25: I F
pass
self.mI()
......@@ -2125,8 +2125,8 @@ class sdl92Lexer(Lexer):
_type = THEN
_channel = DEFAULT_CHANNEL
# sdl92.g:1496:17: ( T H E N )
# sdl92.g:1496:25: T H E N
# sdl92.g:1515:17: ( T H E N )
# sdl92.g:1515:25: T H E N
pass
self.mT()
......@@ -2157,8 +2157,8 @@ class sdl92Lexer(Lexer):
_type = ELSE
_channel = DEFAULT_CHANNEL
# sdl92.g:1497:17: ( E L S E )
# sdl92.g:1497:25: E L S E
# sdl92.g:1516:17: ( E L S E )
# sdl92.g:1516:25: E L S E
pass
self.mE()
......@@ -2189,8 +2189,8 @@ class sdl92Lexer(Lexer):
_type = FI
_channel = DEFAULT_CHANNEL
# sdl92.g:1498:17: ( F I )
# sdl92.g:1498:25: F I
# sdl92.g:1517:17: ( F I )
# sdl92.g:1517:25: F I
pass
self.mF()
......@@ -2215,8 +2215,8 @@ class sdl92Lexer(Lexer):
_type = CREATE
_channel = DEFAULT_CHANNEL
# sdl92.g:1499:17: ( C R E A T E )