Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
OpenGEODE
Commits
645660ff
Commit
645660ff
authored
Nov 22, 2015
by
Maxime Perrotin
Browse files
Parse continuous signals and build valid AST
parent
4e740958
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
design/howto
View file @
645660ff
...
@@ -12,8 +12,8 @@ continuous_signal
...
@@ -12,8 +12,8 @@ continuous_signal
hyperlink?
hyperlink?
PROVIDED expression e=end
PROVIDED expression e=end
(PRIORITY p=INT end)?
(PRIORITY p=INT end)?
transition
transition
?
-> ^(PROVIDED cif? hyperlink?
expression
$p? $e? transition)
-> ^(PROVIDED
expression
cif? hyperlink? $p? $e? transition
?
)
;
;
A new token ("PROVIDED") may be needed and must be added at several places
A new token ("PROVIDED") may be needed and must be added at several places
...
@@ -23,7 +23,10 @@ in the ANTLR grammar:
...
@@ -23,7 +23,10 @@ in the ANTLR grammar:
- in the list of tokens (tokens { ... })
- in the list of tokens (tokens { ... })
notes:
notes:
- "cif?" and "hyperlink?" are optional
- "cif" and "hyperlink" are optional
- the "transition" is also optional, to allow partial model saving
- the expression is always the first child, since it does not have a
dedicated token, and is the only mandatory field
- "end" corresponds to the COMMENT part
- "end" corresponds to the COMMENT part
then the new production is added as a child option to the (existing) "state":
then the new production is added as a child option to the (existing) "state":
...
@@ -93,6 +96,45 @@ class State(object):
...
@@ -93,6 +96,45 @@ class State(object):
self.continuous_signals = []
self.continuous_signals = []
Then create the new class, using the same structure as another class of a
Then create the new class, using the same structure as another class of a
feature of the same family.
feature of the same family - here, we inherit from Input. The class is very
simple:
class ContinuousSignal(Input):
''' AST Entry for the Continuous Signal '''
def __init__(self):
''' Difference with Input: trigger is an expression '''
super(ContinuousSignal, self).__init__()
# Expression triggering the transition
self.trigger = None
# Priority (integer)
self.priority = 0
def trace(self):
''' Debug output for a Continuous signal '''
return u'PROVIDED {exp} ({l},{c})'.format(exp=self.inputString,
l=self.line, c=self.charPositionInLine)
We are done with the AST, we can close ogAST.py
4) Back to ogParser.py
Now we can parse the construct and create the AST entries we just defined.
In the state() function, we replace the placeholder we added at step 2:
(...)
elif child.type == lexer.PROVIDED:
# Continuous signal
provided_part, err, warn = continuous_signal(child, state_def,
context)
state_def.continuous_signals.append(provided_part)
warnings.extend(warn)
errors.extend(err)
Then we can implement the continuous_signal function.
def continuous_signal(root, parent, context):
''' Parse a PROVIDED clause in a continuous signal '''
i = ogAST.ContinuousSignal()
(...)
return i, errors, warnings
opengeode/icons.py
View file @
645660ff
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
# Resource object code
# Resource object code
#
#
# Created: Sun Nov 22
08:45
:1
4
2015
# Created: Sun Nov 22
17:13
:1
0
2015
# by: The Resource Compiler for PySide (Qt v4.8.6)
# by: The Resource Compiler for PySide (Qt v4.8.6)
#
#
# WARNING! All changes made in this file will be lost!
# WARNING! All changes made in this file will be lost!
opengeode/ogAST.py
View file @
645660ff
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
See AdaGenerator.py for an example of use.
See AdaGenerator.py for an example of use.
Copyright (c) 2012-201
3
European Space Agency
Copyright (c) 2012-201
5
European Space Agency
Designed and implemented by Maxime Perrotin
Designed and implemented by Maxime Perrotin
...
@@ -611,6 +611,21 @@ class Connect(Input):
...
@@ -611,6 +611,21 @@ class Connect(Input):
return
u
'CONNECT {exp} ({l},{c})'
.
format
(
exp
=
self
.
inputString
,
return
u
'CONNECT {exp} ({l},{c})'
.
format
(
exp
=
self
.
inputString
,
l
=
self
.
line
,
c
=
self
.
charPositionInLine
)
l
=
self
.
line
,
c
=
self
.
charPositionInLine
)
class
ContinuousSignal
(
Input
):
''' AST Entry for the Continuous Signal '''
def
__init__
(
self
):
''' Difference with Input: trigger is an expression '''
super
(
ContinuousSignal
,
self
).
__init__
()
# Expression triggering the transition
self
.
trigger
=
None
# Priority (integer)
self
.
priority
=
0
def
trace
(
self
):
''' Debug output for a Continuous signal '''
return
u
'PROVIDED {exp} ({l},{c})'
.
format
(
exp
=
self
.
inputString
,
l
=
self
.
line
,
c
=
self
.
charPositionInLine
)
class
Start
(
object
):
class
Start
(
object
):
''' AST Entry for the START symbol '''
''' AST Entry for the START symbol '''
...
...
opengeode/ogParser.py
View file @
645660ff
...
@@ -2749,6 +2749,55 @@ def process_definition(root, parent=None, context=None):
...
@@ -2749,6 +2749,55 @@ def process_definition(root, parent=None, context=None):
return
process
,
errors
,
warnings
return
process
,
errors
,
warnings
def
continuous_signal
(
root
,
parent
,
context
):
''' Parse a PROVIDED clause in a continuous signal '''
i
=
ogAST
.
ContinuousSignal
()
warnings
,
errors
=
[],
[]
# Keep track of the number of terminator statements in the transition
# useful if we want to render graphs from the SDL model
terminators
=
len
(
context
.
terminators
)
i
.
trigger
,
err0
,
warn0
=
expression
(
root
.
getChild
(
0
),
context
)
for
child
in
root
.
children
[
1
:]:
if
child
.
type
==
lexer
.
CIF
:
# Get symbol coordinates
i
.
pos_x
,
i
.
pos_y
,
i
.
width
,
i
.
height
=
cif
(
child
)
# # Report errors with symbol coordinates
# errors = [[e, [i.pos_x or 0, i.pos_y or 0], []] for e in errors]
# warnings = [[w, [i.pos_x or 0, i.pos_y or 0], []]
# for w in warnings]
elif
child
.
type
==
lexer
.
INT
:
# Priority
i
.
priority
=
int
(
child
.
text
)
elif
child
.
type
==
lexer
.
TRANSITION
:
trans
,
err
,
warn
=
transition
(
child
,
parent
=
i
,
context
=
context
)
errors
.
extend
(
err
)
warnings
.
extend
(
warn
)
i
.
transition
=
trans
# Associate a reference to the transition to the list of inputs
# The reference is an index to process.transitions table
context
.
transitions
.
append
(
trans
)
i
.
transition_id
=
len
(
context
.
transitions
)
-
1
elif
child
.
type
==
lexer
.
COMMENT
:
i
.
comment
,
_
,
_
=
end
(
child
)
elif
child
.
type
==
lexer
.
HYPERLINK
:
i
.
hyperlink
=
child
.
getChild
(
0
).
toString
()[
1
:
-
1
]
elif
child
.
type
==
0
:
# Syntax error caught by the parser, no need to report again
pass
else
:
warnings
.
append
(
'Unsupported INPUT child type: {}'
.
format
(
child
.
type
))
# At the end of the input parsing, get the the list of terminators that
# follow the input transition by making a diff with the list at process
# level (we counted the number of terminators before parsing the input)
i
.
terminators
=
list
(
context
.
terminators
[
terminators
:])
return
i
,
errors
,
warnings
def
input_part
(
root
,
parent
,
context
):
def
input_part
(
root
,
parent
,
context
):
''' Parse an INPUT - set of TASTE provided interfaces '''
''' Parse an INPUT - set of TASTE provided interfaces '''
i
=
ogAST
.
Input
()
i
=
ogAST
.
Input
()
...
@@ -2958,7 +3007,12 @@ def state(root, parent, context):
...
@@ -2958,7 +3007,12 @@ def state(root, parent, context):
elif
child
.
type
==
lexer
.
HYPERLINK
:
elif
child
.
type
==
lexer
.
HYPERLINK
:
state_def
.
hyperlink
=
child
.
getChild
(
0
).
toString
()[
1
:
-
1
]
state_def
.
hyperlink
=
child
.
getChild
(
0
).
toString
()[
1
:
-
1
]
elif
child
.
type
==
lexer
.
PROVIDED
:
elif
child
.
type
==
lexer
.
PROVIDED
:
sterr
.
append
(
'Continuous signals are not supported yet'
)
# Continuous signal
provided_part
,
err
,
warn
=
continuous_signal
(
child
,
state_def
,
context
)
state_def
.
continuous_signals
.
append
(
provided_part
)
warnings
.
extend
(
warn
)
errors
.
extend
(
err
)
elif
child
.
type
==
0
:
elif
child
.
type
==
0
:
# Parser error, already caught
# Parser error, already caught
pass
pass
...
...
opengeode/sdl92Lexer.py
View file @
645660ff
# $ANTLR 3.1.3 Mar 17, 2009 19:23:44 sdl92.g 2015-11-22
08:45
:1
6
# $ANTLR 3.1.3 Mar 17, 2009 19:23:44 sdl92.g 2015-11-22
17:13
:1
3
import
sys
import
sys
from
antlr3
import
*
from
antlr3
import
*
...
...
opengeode/sdl92Parser.py
View file @
645660ff
This diff is collapsed.
Click to expand it.
sdl92.g
View file @
645660ff
...
@@ -627,8 +627,8 @@ continuous_signal
...
@@ -627,8 +627,8 @@ continuous_signal
hyperlink?
hyperlink?
PROVIDED expression e=end
PROVIDED expression e=end
(PRIORITY p=INT end)?
(PRIORITY p=INT end)?
transition
transition
?
-> ^(PROVIDED cif? hyperlink?
expression
$p? $e? transition)
-> ^(PROVIDED
expression
cif? hyperlink? $p? $e? transition
?
)
;
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment