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

Add support for process FPAR in the grammar

parent cb9c88cd
......@@ -36,6 +36,7 @@ import genericSymbols
import logging
from itertools import chain
from singledispatch import singledispatch
from ogParser import type_name
LOG = logging.getLogger(__name__)
......@@ -150,6 +151,18 @@ def _automaton(ast, scene):
pass
else:
top_level_symbols.append(new_state)
# If the source .pr contained FPAR outside a textbox, create one
if ast.parent.fpar:
text_area = ogAST.TextArea()
fpars = ('{} {}'.format(fp['name'],
type_name(fp['type']).replace('-', '_'))
for fp in ast.parent.fpar)
text_area.inputString = ("-- Formal parameters\n"
"fpar {};".format(',\n '.join(fpars)))
text_area.pos_x = scene.itemsBoundingRect().x() - 200
text_area.pos_y = scene.itemsBoundingRect().y()
top_level_symbols.append(render(text_area, scene))
return top_level_symbols
......
......@@ -844,6 +844,10 @@ class Process(object):
# (Includes inner procedures)
self.content = Automaton(parent=self)
# Process formal parameters - list of dict:
# [{'name': str, 'type': str}]
self.fpar = []
# List of timers (strings) declared in the process
self.timers = []
......
......@@ -1052,7 +1052,7 @@ def is_fpar(name, context):
name = name.lower()
if isinstance(context, ogAST.Procedure):
for each in context.fpar:
if each['name'].lower() == name:
if each['name'].lower() == name.lower():
return True
return False
......@@ -2326,7 +2326,7 @@ def text_area_content(root, ta_ast, context):
context.fpar = params
ta_ast.fpar = params
except AttributeError:
errors.append('Only procedures can have an FPAR section')
errors.append('Entity cannot have an FPAR section')
elif child.type == lexer.TIMER:
timers = [timer.text.lower() for timer in child.children]
context.timers.extend(timers)
......@@ -2524,7 +2524,7 @@ def system_definition(root, parent):
textarea, err, warn = text_area(child, context=system)
system.signals.extend(textarea.signals)
if textarea.fpar:
errors.append('FPAR shall be declared only in procedures')
errors.append('FPAR cannot be declared at system level')
if textarea.timers:
errors.append('Timers shall be declared only in a process')
# Update list of ASN.1 files - if any
......@@ -2624,6 +2624,12 @@ def process_definition(root, parent=None, context=None):
elif child.type == lexer.NUMBER_OF_INSTANCES:
# Number of instances - discarded (working on a single process)
pass
elif child.type == lexer.PFPAR:
# Process formal parameters
params, err, warn = fpar(child)
errors.extend(err)
warnings.extend(warn)
process.fpar = params
elif child.type == lexer.PROCEDURE:
proc, content, err, warn = procedure_pre(
child, parent=None, context=process)
......
......@@ -58,6 +58,7 @@ tokens {
FLOATING_LABEL;
FOR;
FPAR;
PFPAR;
GROUND;
HYPERLINK;
IF;
......@@ -220,12 +221,24 @@ process_definition
: PROCESS process_id number_of_instances? REFERENCED end
-> ^(PROCESS process_id number_of_instances? REFERENCED)
| cif? PROCESS process_id number_of_instances? end
pfpar?
(text_area | procedure | composite_state)*
processBody? ENDPROCESS process_id?
end
-> ^(PROCESS cif? process_id number_of_instances? end?
-> ^(PROCESS cif? process_id number_of_instances? end? pfpar?
text_area* procedure* composite_state* processBody?);
// Process formal parameters
pfpar
: FPAR parameters_of_sort
(',' parameters_of_sort)*
end
-> ^(PFPAR parameters_of_sort+);
parameters_of_sort
: variable_id (',' variable_id)* sort
-> ^(PARAM variable_id+ sort);
// procedure: missing the RETURNS statement
// (TODO - but check new SDL2000 syntax that has no RETURNS token)
......
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