Commit e979ddaa authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Fix autocompletion and improve state type support

parent 1a05787e
......@@ -263,7 +263,7 @@ class EditableText(QGraphicsTextItem):
try:
# If not the first line of the text, Qt adds u+2029 as 1st char
line = cursor.selectedText().replace(u'\u2029', '')
if line[pos] in string.ascii_letters + '!' + '.' + '_':
if line[pos] in string.ascii_letters + '!' + '.' + '_' + ':':
self.context = line[slice(0, pos + 1)].split()[-1]
else:
self.context = ''
......
This diff is collapsed.
......@@ -481,6 +481,8 @@ class Terminator:
self.via = None
# 'entrypoint' is the string of the entry point (e.g. "foo")
self.entrypoint = None
# If the nextstate is an instance of a type (foo : bar)
self.instance_of = None
# some transitions can be chained, when entering/leaving nested states
self.next_id = -1
# Pointer to the next transition, when using return/connect
......@@ -944,8 +946,8 @@ class CompositeState(Process):
def __init__(self):
super(CompositeState, self).__init__()
self.statename = ''
self.state_entrypoints = []
self.state_exitpoints = []
self.state_entrypoints = set()
self.state_exitpoints = set()
# Special entry and exit procedures (named "entry" and "exit")
self.entry_procedure = None
self.exit_procedure = None
......
......@@ -2726,11 +2726,11 @@ def composite_state(root, parent=None, context=None):
elif child.type == lexer.IN:
# state entry point
for point in child.getChildren():
comp.state_entrypoints.append(point.toString().lower())
comp.state_entrypoints.add(point.toString().lower())
elif child.type == lexer.OUT:
# state exit point
for point in child.getChildren():
comp.state_exitpoints.append(point.toString().lower())
comp.state_exitpoints.add(point.toString().lower())
elif child.type == lexer.TEXTAREA:
textarea, err, warn = text_area(child, context=comp)
if textarea.signals:
......@@ -4675,9 +4675,9 @@ def decision(root, parent, context):
def nextstate(root, context):
''' Parse a NEXTSTATE [VIA State_Entry_Point] - detect various kinds of
errors when trying to enter a nested state '''
next_state_id, via, entrypoint = '', None, None
''' Parse a NEXTSTATE [: type] [VIA State_Entry_Point]
detect various kinds of errors when trying to enter a nested state '''
next_state_id, via, entrypoint, instance_of = '', None, None, None
errors = []
for child in root.getChildren():
if child.type == lexer.ID:
......@@ -4709,8 +4709,13 @@ def nextstate(root, context):
(s=next_state_id, p=entrypoint))
else:
errors.append('"History" NEXTSTATE cannot have a "via" clause')
elif child.type == lexer.TYPE_INSTANCE:
instance_of = child.getChild(0).text
via = get_input_string(root).replace(
'NEXTSTATE', '', 1).strip()
else:
errors.append('NEXTSTATE undefined construct')
errors.append('NEXTSTATE undefined construct: ' +
sdl92Parser.tokenNamesMap[child.type])
if not via:
# check that if the nextstate is nested, it has a START symbol
try:
......@@ -4722,7 +4727,7 @@ def nextstate(root, context):
'START symbol'.format(composite.statename))
except ValueError:
pass
return next_state_id, via, entrypoint, errors
return next_state_id, via, entrypoint, instance_of, errors
def terminator_statement(root, parent, context):
......@@ -4742,7 +4747,8 @@ def terminator_statement(root, parent, context):
lab.terminators = [t]
elif term.type == lexer.NEXTSTATE:
t.kind = 'next_state'
t.inputString, t.via, t.entrypoint, err = nextstate(term, context)
t.inputString, t.via, t.entrypoint, t.instance_of, err = \
nextstate(term, context)
if err:
errors.extend(err)
t.line = term.getChild(0).getLine()
......@@ -5434,7 +5440,7 @@ def parse_pr(files=None, string=None):
for t in process.terminators:
if t.kind != 'next_state':
continue
ns = t.inputString.lower()
ns = t.instance_of or t.inputString.lower()
if not ns in [s.lower() for s in process.mapping.keys()] + ['-']:
t_x, t_y = t.pos_x or 0, t.pos_y or 0
errors.append(['State definition missing: ' + ns.upper(),
......
# $ANTLR 3.5.2 sdl92.g 2020-07-08 14:24:25
# $ANTLR 3.5.2 sdl92.g 2020-07-08 21:02:37
import sys
from antlr3 import *
......
This diff is collapsed.
......@@ -616,8 +616,7 @@ class ProcedureStop(Join):
# in case of syntax error in the symbol text
return
try:
CONTEXT.state_exitpoints = \
set(CONTEXT.state_exitpoints) | set(str(self))
CONTEXT.state_exitpoints.add(str(self))
except AttributeError:
# No state exit points in a procedure
pass
......@@ -1020,10 +1019,17 @@ class State(VerticalSymbol):
elems = str(self).lower().strip().split()
if len(elems) == 2 and elems[1] == 'via':
# Get list of entry point of the nested state
statename = elems[0]
# check if it is an instance
name = elems[0].split(':')
if len(name) == 2:
statename = name[1]
else:
statename = name[0]
for each in CONTEXT.composite_states:
if each.statename == statename:
return each.state_entrypoints
# the entry points may not be defined yet
return set()
else:
return set(state for state in CONTEXT.mapping if state != 'START')
......@@ -1365,8 +1371,8 @@ class StateStart(Start):
def update_completion_list(self, pr_text):
''' Update nested state entry points '''
CONTEXT.state_entrypoints = \
set(CONTEXT.state_entrypoints) | set(str(self))
CONTEXT.state_entrypoints.add(str(self))
# pylint: disable=R0904
class ContinuousSignal(HorizontalSymbol):
......
......@@ -1314,7 +1314,7 @@ nextstate
nextstatebody
: statename via?
: statename (':'! type_inst)? via?
| dash_nextstate
;
......
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