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 diff is collapsed.
......@@ -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()):
......
This diff is collapsed.
This diff is collapsed.
......@@ -478,8 +478,13 @@ floating_label
-> ^(FLOATING_LABEL cif? hyperlink? connector_name transition?)
;
// state is either a full state definition, or a declaration of an instance
state
: state_definition
| state_instance
;
state_definition
: cif?
hyperlink?
STATE statelist via? (e=end | SEMI) // "via" part may be in NEXTSTATE
......@@ -489,6 +494,15 @@ state
;
state_instance
: cif?
hyperlink?
STATE statename ':' type_inst e=end
ENDSTATE statename? f=end
-> ^(STATE cif? hyperlink? $e? statename type_inst)
;
statelist
: ((statename)(',' statename)*)
-> ^(STATELIST statename+)
......
[General]
geometry=@ByteArray(\x1\xd9\xd0\xcb\0\x1\0\0\0\0\x1\x10\0\0\0@\0\0\a2\0\0\x3\xd8\0\0\x1\x13\0\0\0]\0\0\a/\0\0\x3\xd5\0\0\0\0\0\0)
windowState="@ByteArray(\0\0\0\xff\0\0\0\0\xfd\0\0\0\x2\0\0\0\x1\0\0\x2,\0\0\x2\x99\xfc\x2\0\0\0\x1\xfc\0\0\0\x35\0\0\x2\x99\0\0\0y\x1\0\0\x15\xfa\0\0\0\0\x2\0\0\0\x2\xfb\0\0\0\x1c\0\x64\0\x61\0t\0\x61\0t\0y\0p\0\x65\0s\0_\0\x64\0o\0\x63\0k\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\x63\0\xff\xff\xff\xfb\0\0\0\x1a\0\x64\0\x61\0t\0\x61\0\x64\0i\0\x63\0t\0_\0\x64\0o\0\x63\0k\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\x63\0\xff\xff\xff\0\0\0\x3\0\0\x5\xef\0\0\0\x8c\xfc\x1\0\0\0\x1\xfb\0\0\0\xe\0m\0s\0g\0\x44\0o\0\x63\0k\x1\0\0\0.\0\0\x5\xef\0\0\0\x46\0\a\xff\xff\0\0\x3\xbd\0\0\x2\x99\0\0\0\x4\0\0\0\x4\0\0\0\b\0\0\0\b\xfc\0\0\0\x2\0\0\0\0\0\0\0\x1\0\0\0\x16\0S\0\x44\0L\0 \0T\0o\0o\0l\0\x62\0\x61\0r\x3\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\0\0\0\x2\0\0\0\x1\0\0\0\x18\0\x46\0i\0l\0\x65\0 \0T\0o\0o\0l\0\x62\0\x61\0r\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0)"
geometry="@ByteArray(\x1\xd9\xd0\xcb\0\x2\0\0\0\0\x1\r\0\0\0#\0\0\a/\0\0\x3\xbb\0\0\x1\x10\0\0\0@\0\0\a,\0\0\x3\xb8\0\0\0\0\0\0\0\0\a\x80)"
windowState="@ByteArray(\0\0\0\xff\0\0\0\0\xfd\0\0\0\x2\0\0\0\x1\0\0\x2,\0\0\x2\x8e\xfc\x2\0\0\0\x1\xfc\0\0\0<\0\0\x2\x8e\0\0\0\x87\x1\0\0\x1b\xfa\0\0\0\0\x2\0\0\0\x2\xfb\0\0\0\x1c\0\x64\0\x61\0t\0\x61\0t\0y\0p\0\x65\0s\0_\0\x64\0o\0\x63\0k\x1\0\0\0\0\xff\xff\xff\xff\0\0\0k\0\xff\xff\xff\xfb\0\0\0\x1a\0\x64\0\x61\0t\0\x61\0\x64\0i\0\x63\0t\0_\0\x64\0o\0\x63\0k\x1\0\0\0\0\xff\xff\xff\xff\0\0\0k\0\xff\xff\xff\0\0\0\x3\0\0\x5\xea\0\0\0\x8c\xfc\x1\0\0\0\x1\xfb\0\0\0\xe\0m\0s\0g\0\x44\0o\0\x63\0k\x1\0\0\0\x33\0\0\x5\xea\0\0\0\x46\0\a\xff\xff\0\0\x3\xb8\0\0\x2\x8e\0\0\0\x4\0\0\0\x4\0\0\0\b\0\0\0\b\xfc\0\0\0\x2\0\0\0\0\0\0\0\x1\0\0\0\x16\0S\0\x44\0L\0 \0T\0o\0o\0l\0\x62\0\x61\0r\x3\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0\0\0\0\x2\0\0\0\x1\0\0\0\x18\0\x46\0i\0l\0\x65\0 \0T\0o\0o\0l\0\x62\0\x61\0r\x1\0\0\0\0\xff\xff\xff\xff\0\0\0\0\0\0\0\0)"
project og_Ada is
for Languages use ("Ada");
for Source_Dirs use (".");
for Object_Dir use "obj";
for Source_Dirs use (".") & External_As_List ("CODE_PATH", ":");
for Object_Dir use "../obj";
end og_Ada;
\ No newline at end of file
......@@ -26,7 +26,10 @@ test-qgen-gt-c:
$(TESTQGEN_GT_C) $(ROOT_MODEL)
test-ada:
make -f Makefile.og
#make -f Makefile.og
$(OPENGEODE) og.pr --toAda
mono $(ASN1SCC) -Ada -typePrefix asn1Scc -equal dataview-uniq.asn
gnat make og
test-c:
$(OPENGEODE) og.pr --toC
......
......@@ -26,7 +26,10 @@ test-qgen-gt-c:
$(TESTQGEN_GT_C) $(ROOT_MODEL)
test-ada:
make -f Makefile.function2
#make -f Makefile.function2
$(OPENGEODE) function2.pr system_structure.pr --toAda
mono $(ASN1SCC) -Ada -typePrefix asn1Scc -equal dataview-uniq.asn
gnat make function2
test-c:
$(OPENGEODE) function2.pr system_structure.pr --toC
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment