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 @@ ...@@ -8,7 +8,7 @@
The "Connection" class is the mother class, all other connectors must The "Connection" class is the mother class, all other connectors must
inherit from it and possibly redefine some functions or shape. 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 Designed and implemented by Maxime Perrotin
...@@ -52,6 +52,8 @@ class Connection(QGraphicsPathItem): ...@@ -52,6 +52,8 @@ class Connection(QGraphicsPathItem):
self.setCacheMode(QGraphicsItem.DeviceCoordinateCache) self.setCacheMode(QGraphicsItem.DeviceCoordinateCache)
# When the child moves, the connection may need to adjust the end point # When the child moves, the connection may need to adjust the end point
self.child.moved.connect(self.child_moved) self.child.moved.connect(self.child_moved)
# Syntax error indicator
self.syntax_error: Boolean = False
@Slot(float, float) @Slot(float, float)
def child_moved(self, delta_x, delta_y): def child_moved(self, delta_x, delta_y):
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
SDL is the Specification and Description Language (Z100 standard from ITU) 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 Designed and implemented by Maxime Perrotin
......
...@@ -380,7 +380,10 @@ class EditableText(QGraphicsTextItem): ...@@ -380,7 +380,10 @@ class EditableText(QGraphicsTextItem):
if(self.oldSize != self.parent.boundingRect() if(self.oldSize != self.parent.boundingRect()
or self.parent.syntax_error or self.oldText != str(self)): or self.parent.syntax_error or self.oldText != str(self)):
# Call syntax checker from item containing the text (if any) # 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 # Update class completion list
self.scene().update_completion_list(self.parentItem()) self.scene().update_completion_list(self.parentItem())
# Create undo command, including possible CAM # Create undo command, including possible CAM
......
...@@ -171,7 +171,7 @@ class Symbol(QObject, QGraphicsPathItem): ...@@ -171,7 +171,7 @@ class Symbol(QObject, QGraphicsPathItem):
self.movable_points = [] self.movable_points = []
# Flag to indicate a detected syntax error, used to force the # Flag to indicate a detected syntax error, used to force the
# refocus of the text area to make sure user fixes it before saving # 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): def set_valid_pos(self, pos):
''' Hook that can be redefined by sub classes to forbid wrong ''' 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: ...@@ -737,6 +737,8 @@ class State:
# via clause, used for entering nested state with an entry point # via clause, used for entering nested state with an entry point
# 'via' is the string for the renderer (e.g. "hello via foo") # 'via' is the string for the renderer (e.g. "hello via foo")
self.via = None self.via = None
# a state can be an instance of a state stype
self.instance_of = None
def trace(self): def trace(self):
''' Debug output for a STATE symbol ''' ''' Debug output for a STATE symbol '''
......
...@@ -3843,13 +3843,27 @@ def state(root, parent, context): ...@@ -3843,13 +3843,27 @@ def state(root, parent, context):
asterisk_state = False asterisk_state = False
asterisk_input = None asterisk_input = None
st_x, st_y = 0, 0 st_x, st_y = 0, 0
via_stop = None via_stop, inst_stop = None, None
for child in root.getChildren(): for child in root.getChildren():
if child.type == lexer.CIF: if child.type == lexer.CIF:
# Get symbol coordinates # Get symbol coordinates
(state_def.pos_x, state_def.pos_y, (state_def.pos_x, state_def.pos_y,
state_def.width, state_def.height) = cif(child) state_def.width, state_def.height) = cif(child)
st_x, st_y = state_def.pos_x, state_def.pos_y 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: elif child.type == lexer.STATELIST:
# State name(state_def) # State name(state_def)
state_def.inputString = get_input_string(child) state_def.inputString = get_input_string(child)
......
...@@ -783,13 +783,15 @@ class SDL_Scene(QGraphicsScene): ...@@ -783,13 +783,15 @@ class SDL_Scene(QGraphicsScene):
return symb.check_syntax('\n'.join(Pr.generate(symb, recursive=False))) 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 ''' ''' 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) errors = self.syntax_errors(symbol)
if not errors: if not errors:
symbol.syntax_error = False symbol.syntax_error = False
return return False
for view in self.views(): for view in self.views():
errs = [] errs = []
...@@ -816,8 +818,11 @@ class SDL_Scene(QGraphicsScene): ...@@ -816,8 +818,11 @@ class SDL_Scene(QGraphicsScene):
msg_box.setDefaultButton(QMessageBox.Discard) msg_box.setDefaultButton(QMessageBox.Discard)
msg_box.exec_() msg_box.exec_()
# There were syntax errors: force user to fix them # 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.syntax_error = True
symbol.edit_text() return True
#symbol.edit_text()
def global_syntax_check(self, ignore=set()): 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 import sys
from antlr3 import * from antlr3 import *
...@@ -493,8 +493,8 @@ class sdl92Lexer(Lexer): ...@@ -493,8 +493,8 @@ class sdl92Lexer(Lexer):
_type = ASSIG_OP _type = ASSIG_OP
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1444:17: ( ':=' ) # sdl92.g:1463:17: ( ':=' )
# sdl92.g:1444:25: ':=' # sdl92.g:1463:25: ':='
pass pass
self.match(":=") self.match(":=")
...@@ -516,8 +516,8 @@ class sdl92Lexer(Lexer): ...@@ -516,8 +516,8 @@ class sdl92Lexer(Lexer):
_type = L_BRACKET _type = L_BRACKET
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1445:17: ( '{' ) # sdl92.g:1464:17: ( '{' )
# sdl92.g:1445:25: '{' # sdl92.g:1464:25: '{'
pass pass
self.match(123) self.match(123)
...@@ -538,8 +538,8 @@ class sdl92Lexer(Lexer): ...@@ -538,8 +538,8 @@ class sdl92Lexer(Lexer):
_type = R_BRACKET _type = R_BRACKET
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1446:17: ( '}' ) # sdl92.g:1465:17: ( '}' )
# sdl92.g:1446:25: '}' # sdl92.g:1465:25: '}'
pass pass
self.match(125) self.match(125)
...@@ -560,8 +560,8 @@ class sdl92Lexer(Lexer): ...@@ -560,8 +560,8 @@ class sdl92Lexer(Lexer):
_type = L_PAREN _type = L_PAREN
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1447:17: ( '(' ) # sdl92.g:1466:17: ( '(' )
# sdl92.g:1447:25: '(' # sdl92.g:1466:25: '('
pass pass
self.match(40) self.match(40)
...@@ -582,8 +582,8 @@ class sdl92Lexer(Lexer): ...@@ -582,8 +582,8 @@ class sdl92Lexer(Lexer):
_type = R_PAREN _type = R_PAREN
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1448:17: ( ')' ) # sdl92.g:1467:17: ( ')' )
# sdl92.g:1448:25: ')' # sdl92.g:1467:25: ')'
pass pass
self.match(41) self.match(41)
...@@ -604,8 +604,8 @@ class sdl92Lexer(Lexer): ...@@ -604,8 +604,8 @@ class sdl92Lexer(Lexer):
_type = COMMA _type = COMMA
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1449:17: ( ',' ) # sdl92.g:1468:17: ( ',' )
# sdl92.g:1449:25: ',' # sdl92.g:1468:25: ','
pass pass
self.match(44) self.match(44)
...@@ -626,8 +626,8 @@ class sdl92Lexer(Lexer): ...@@ -626,8 +626,8 @@ class sdl92Lexer(Lexer):
_type = SEMI _type = SEMI
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1450:17: ( ';' ) # sdl92.g:1469:17: ( ';' )
# sdl92.g:1450:25: ';' # sdl92.g:1469:25: ';'
pass pass
self.match(59) self.match(59)
...@@ -648,8 +648,8 @@ class sdl92Lexer(Lexer): ...@@ -648,8 +648,8 @@ class sdl92Lexer(Lexer):
_type = DASH _type = DASH
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1451:17: ( '-' ) # sdl92.g:1470:17: ( '-' )
# sdl92.g:1451:25: '-' # sdl92.g:1470:25: '-'
pass pass
self.match(45) self.match(45)
...@@ -670,8 +670,8 @@ class sdl92Lexer(Lexer): ...@@ -670,8 +670,8 @@ class sdl92Lexer(Lexer):
_type = ANY _type = ANY
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1452:17: ( A N Y ) # sdl92.g:1471:17: ( A N Y )
# sdl92.g:1452:25: A N Y # sdl92.g:1471:25: A N Y
pass pass
self.mA() self.mA()
...@@ -699,8 +699,8 @@ class sdl92Lexer(Lexer): ...@@ -699,8 +699,8 @@ class sdl92Lexer(Lexer):
_type = ASTERISK _type = ASTERISK
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1453:17: ( '*' ) # sdl92.g:1472:17: ( '*' )
# sdl92.g:1453:25: '*' # sdl92.g:1472:25: '*'
pass pass
self.match(42) self.match(42)
...@@ -721,8 +721,8 @@ class sdl92Lexer(Lexer): ...@@ -721,8 +721,8 @@ class sdl92Lexer(Lexer):
_type = DCL _type = DCL
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1454:17: ( D C L ) # sdl92.g:1473:17: ( D C L )
# sdl92.g:1454:25: D C L # sdl92.g:1473:25: D C L
pass pass
self.mD() self.mD()
...@@ -750,8 +750,8 @@ class sdl92Lexer(Lexer): ...@@ -750,8 +750,8 @@ class sdl92Lexer(Lexer):
_type = END _type = END
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1455:17: ( E N D ) # sdl92.g:1474:17: ( E N D )
# sdl92.g:1455:25: E N D # sdl92.g:1474:25: E N D
pass pass
self.mE() self.mE()
...@@ -779,8 +779,8 @@ class sdl92Lexer(Lexer): ...@@ -779,8 +779,8 @@ class sdl92Lexer(Lexer):
_type = KEEP _type = KEEP
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1456:17: ( K E E P ) # sdl92.g:1475:17: ( K E E P )
# sdl92.g:1456:25: K E E P # sdl92.g:1475:25: K E E P
pass pass
self.mK() self.mK()
...@@ -811,8 +811,8 @@ class sdl92Lexer(Lexer): ...@@ -811,8 +811,8 @@ class sdl92Lexer(Lexer):
_type = PARAMNAMES _type = PARAMNAMES
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1457:17: ( 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:1457:25: 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 pass
self.mP() self.mP()
...@@ -861,8 +861,8 @@ class sdl92Lexer(Lexer): ...@@ -861,8 +861,8 @@ class sdl92Lexer(Lexer):
_type = SPECIFIC _type = SPECIFIC
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1458:17: ( S P E C I F I C ) # sdl92.g:1477:17: ( S P E C I F I C )
# sdl92.g:1458:25: S P E C I F I C # sdl92.g:1477:25: S P E C I F I C
pass pass
self.mS() self.mS()
...@@ -905,8 +905,8 @@ class sdl92Lexer(Lexer): ...@@ -905,8 +905,8 @@ class sdl92Lexer(Lexer):
_type = GEODE _type = GEODE
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1459:17: ( G E O D E ) # sdl92.g:1478:17: ( G E O D E )
# sdl92.g:1459:25: G E O D E # sdl92.g:1478:25: G E O D E
pass pass
self.mG() self.mG()
...@@ -940,8 +940,8 @@ class sdl92Lexer(Lexer): ...@@ -940,8 +940,8 @@ class sdl92Lexer(Lexer):
_type = HYPERLINK _type = HYPERLINK
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1460:17: ( H Y P E R L I N K ) # sdl92.g:1479: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:25: H Y P E R L I N K
pass pass
self.mH() self.mH()
...@@ -987,8 +987,8 @@ class sdl92Lexer(Lexer): ...@@ -987,8 +987,8 @@ class sdl92Lexer(Lexer):
_type = MKSTRING _type = MKSTRING
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1461:17: ( M K S T R I N G ) # sdl92.g:1480:17: ( M K S T R I N G )
# sdl92.g:1461:25: M K S T R I N G # sdl92.g:1480:25: M K S T R I N G
pass pass
self.mM() self.mM()
...@@ -1031,8 +1031,8 @@ class sdl92Lexer(Lexer): ...@@ -1031,8 +1031,8 @@ class sdl92Lexer(Lexer):
_type = ENDTEXT _type = ENDTEXT
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1462:17: ( E N D T E X T ) # sdl92.g:1481:17: ( E N D T E X T )
# sdl92.g:1462:25: E N D T E X T # sdl92.g:1481:25: E N D T E X T
pass pass
self.mE() self.mE()
...@@ -1072,8 +1072,8 @@ class sdl92Lexer(Lexer): ...@@ -1072,8 +1072,8 @@ class sdl92Lexer(Lexer):
_type = RETURN _type = RETURN
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1463:17: ( R E T U R N ) # sdl92.g:1482:17: ( R E T U R N )
# sdl92.g:1463:25: R E T U R N # sdl92.g:1482:25: R E T U R N
pass pass
self.mR() self.mR()
...@@ -1110,8 +1110,8 @@ class sdl92Lexer(Lexer): ...@@ -1110,8 +1110,8 @@ class sdl92Lexer(Lexer):
_type = RETURNS _type = RETURNS
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1464:17: ( R E T U R N S ) # sdl92.g:1483:17: ( R E T U R N S )
# sdl92.g:1464:25: R E T U R N S # sdl92.g:1483:25: R E T U R N S
pass pass
self.mR() self.mR()
...@@ -1151,8 +1151,8 @@ class sdl92Lexer(Lexer): ...@@ -1151,8 +1151,8 @@ class sdl92Lexer(Lexer):
_type = TIMER _type = TIMER
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1465:17: ( T I M E R ) # sdl92.g:1484:17: ( T I M E R )
# sdl92.g:1465:25: T I M E R # sdl92.g:1484:25: T I M E R
pass pass
self.mT() self.mT()
...@@ -1186,8 +1186,8 @@ class sdl92Lexer(Lexer): ...@@ -1186,8 +1186,8 @@ class sdl92Lexer(Lexer):
_type = PROCESS _type = PROCESS
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1466:17: ( P R O C E S S ) # sdl92.g:1485:17: ( P R O C E S S )
# sdl92.g:1466:25: P R O C E S S # sdl92.g:1485:25: P R O C E S S
pass pass
self.mP() self.mP()
...@@ -1227,8 +1227,8 @@ class sdl92Lexer(Lexer): ...@@ -1227,8 +1227,8 @@ class sdl92Lexer(Lexer):
_type = TYPE _type = TYPE
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1467:17: ( T Y P E ) # sdl92.g:1486:17: ( T Y P E )
# sdl92.g:1467:25: T Y P E # sdl92.g:1486:25: T Y P E
pass pass
self.mT() self.mT()
...@@ -1259,8 +1259,8 @@ class sdl92Lexer(Lexer): ...@@ -1259,8 +1259,8 @@ class sdl92Lexer(Lexer):
_type = ENDPROCESS _type = ENDPROCESS
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1468:17: ( 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:1468:25: 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 pass
self.mE() self.mE()
...@@ -1309,8 +1309,8 @@ class sdl92Lexer(Lexer): ...@@ -1309,8 +1309,8 @@ class sdl92Lexer(Lexer):
_type = START _type = START
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1469:17: ( S T A R T ) # sdl92.g:1488:17: ( S T A R T )
# sdl92.g:1469:25: S T A R T # sdl92.g:1488:25: S T A R T
pass pass
self.mS() self.mS()
...@@ -1344,8 +1344,8 @@ class sdl92Lexer(Lexer): ...@@ -1344,8 +1344,8 @@ class sdl92Lexer(Lexer):
_type = STATE _type = STATE
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1470:17: ( S T A T E ) # sdl92.g:1489:17: ( S T A T E )
# sdl92.g:1470:25: S T A T E # sdl92.g:1489:25: S T A T E
pass pass
self.mS() self.mS()
...@@ -1379,8 +1379,8 @@ class sdl92Lexer(Lexer): ...@@ -1379,8 +1379,8 @@ class sdl92Lexer(Lexer):
_type = TEXT _type = TEXT
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1471:17: ( T E X T ) # sdl92.g:1490:17: ( T E X T )
# sdl92.g:1471:25: T E X T # sdl92.g:1490:25: T E X T
pass pass
self.mT() self.mT()
...@@ -1411,8 +1411,8 @@ class sdl92Lexer(Lexer): ...@@ -1411,8 +1411,8 @@ class sdl92Lexer(Lexer):
_type = PROCEDURE _type = PROCEDURE
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1472:17: ( P R O C E D U R E ) # sdl92.g:1491: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:25: P R O C E D U R E
pass pass
self.mP() self.mP()
...@@ -1458,8 +1458,8 @@ class sdl92Lexer(Lexer): ...@@ -1458,8 +1458,8 @@ class sdl92Lexer(Lexer):
_type = ENDPROCEDURE _type = ENDPROCEDURE
_channel = DEFAULT_CHANNEL _channel = DEFAULT_CHANNEL
# sdl92.g:1473:17: ( 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:1473:25: 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 pass
self.mE() self.mE()
...@@ -1514,8 +1514,8 @@ class sdl92Lexer(Lexer): ...@@ -1514,8 +1514,8 @@ class sdl92Lexer(Lexer):
_type = PROCEDURE_CALL _type = PROCEDURE_CALL
_channel = DEFAULT_CHANNEL