summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorNicolas Schodet2009-12-18 01:11:28 +0100
committerNicolas Schodet2009-12-18 01:11:28 +0100
commit7df762056280a338a2ec349015403b6f506a0dbf (patch)
tree5133f200d44d64c79ea8a180a958874e47f31f03 /tools
parentf7649b3c8164f05f112bcff245087c0722075478 (diff)
tools/dfagen: add origin to states, events and branches, refs #102
Diffstat (limited to 'tools')
-rw-r--r--tools/dfagen/dfagen/automaton.py10
-rw-r--r--tools/dfagen/dfagen/parser.g37
-rw-r--r--tools/dfagen/examples/import.dump.ref6
-rw-r--r--tools/dfagen/examples/imported1.fsm1
-rw-r--r--tools/dfagen/examples/imported2.fsm1
-rw-r--r--tools/dfagen/examples/imported3.fsm1
6 files changed, 38 insertions, 18 deletions
diff --git a/tools/dfagen/dfagen/automaton.py b/tools/dfagen/dfagen/automaton.py
index c24fe1e6..63a701f6 100644
--- a/tools/dfagen/dfagen/automaton.py
+++ b/tools/dfagen/dfagen/automaton.py
@@ -1,9 +1,10 @@
class Event:
"""Event definition."""
- def __init__ (self, name, comments = ''):
+ def __init__ (self, name, comments = '', origin = None):
self.name = name
self.comments = comments
+ self.origin = origin
pass
def __str__ (self):
@@ -15,10 +16,11 @@ class Event:
class State:
"""State definition."""
- def __init__ (self, name, comments = '', initial = False):
+ def __init__ (self, name, comments = '', initial = False, origin = None):
self.name = name
self.comments = comments
self.initial = initial
+ self.origin = origin
self.transitions = { }
self.transitions_list = [ ]
self.attributes = None
@@ -73,11 +75,13 @@ class Transition:
class TransitionBranch:
- def __init__ (self, event, name = None, to = None, comments = ''):
+ def __init__ (self, event, name = None, to = None, comments = '',
+ origin = None):
self.event = event
self.name = name
self.to = to
self.comments = comments
+ self.origin = origin
self.attributes = None
def __str__ (self):
diff --git a/tools/dfagen/dfagen/parser.g b/tools/dfagen/dfagen/parser.g
index 1e19bcc4..e8bc95df 100644
--- a/tools/dfagen/dfagen/parser.g
+++ b/tools/dfagen/dfagen/parser.g
@@ -13,35 +13,38 @@ parser AutomatonParser:
token ATTR: "\w([\w =]*\w)?"
token IMPORT: "[\w./]+"
- rule automaton: ATITLE {{ a = Automaton (ATITLE.strip ()) }}
+ rule automaton: ATITLE {{ name = ATITLE.strip (); a = Automaton (name) }}
( comments {{ a.comments = comments }}
) ?
- automatondef<<a>>
+ automatondef<<a, name>>
EOF {{ return a }}
rule automatonsub<<a>>:
- ATITLE
- ( comments ) ?
- automatondef<<a>>
+ ATITLE {{ name = ATITLE.strip () }}
+ ( comments {{ a.comments += "\n" + name + ":\n" + comments }}
+ ) ?
+ automatondef<<a, name>>
EOF
- rule automatondef<<a>>:
+ rule automatondef<<a, origin>>:
( importdef<<a>> ) *
"States:\n"
- ( statedef {{ a.add_state (statedef) }}
+ ( statedef<<origin>>
+ {{ a.add_state (statedef) }}
) *
( importdef<<a>> ) *
"Events:\n"
- ( eventdef {{ a.add_event (eventdef) }}
+ ( eventdef<<origin>>
+ {{ a.add_event (eventdef) }}
) *
( importdef<<a>> ) *
- ( transdef<<a>>
+ ( transdef<<a, origin>>
) *
- rule statedef: {{ initial = False }}
+ rule statedef<<origin>>: {{ initial = False }}
" " ( "\*" {{ initial = True }}
) ?
- STATE {{ s = State (STATE, initial = initial) }}
+ STATE {{ s = State (STATE, initial = initial, origin = origin) }}
( "\s*\[\s*"
ATTR {{ s.attributes = ATTR }}
"\s*\]" ) ?
@@ -50,14 +53,17 @@ parser AutomatonParser:
) ?
{{ return s }}
- rule eventdef: " " EVENT {{ e = Event (EVENT) }}
+ rule eventdef<<origin>>:
+ " " EVENT {{ e = Event (EVENT, origin = origin) }}
"\n"
( comments {{ e.comments = comments }}
) ?
{{ return e }}
- rule transdef<<a>>: transsl<<a>>
- ( trans<<a>> {{ for s in transsl: s.add_branch (trans) }}
+ rule transdef<<a, origin>>:
+ transsl<<a>>
+ ( trans<<a, origin>>
+ {{ for s in transsl: s.add_branch (trans) }}
) *
rule transsl<<a>>: {{ sl = [ ] }}
@@ -66,7 +72,8 @@ parser AutomatonParser:
) *
":\n" {{ return sl }}
- rule trans<<a>>: " " EVENT {{ t = TransitionBranch (a.events[EVENT]) }}
+ rule trans<<a, origin>>:
+ " " EVENT {{ t = TransitionBranch (a.events[EVENT], origin = origin) }}
( ":\s*" QUALIFIER {{ t.name = QUALIFIER }}
) ?
"\s*->\s*"
diff --git a/tools/dfagen/examples/import.dump.ref b/tools/dfagen/examples/import.dump.ref
index 6cc359de..78874cd8 100644
--- a/tools/dfagen/examples/import.dump.ref
+++ b/tools/dfagen/examples/import.dump.ref
@@ -1,5 +1,11 @@
Import
Import definitions from other files.
+ Imported1:
+ First imported file comment.
+ Imported2:
+ Second imported file comment.
+ Imported3:
+ Third imported file comment.
States:
I1S1
diff --git a/tools/dfagen/examples/imported1.fsm b/tools/dfagen/examples/imported1.fsm
index fe4ee9ff..02627641 100644
--- a/tools/dfagen/examples/imported1.fsm
+++ b/tools/dfagen/examples/imported1.fsm
@@ -1,5 +1,6 @@
# Imported first file.
Imported1
+ First imported file comment.
States:
I1S1
diff --git a/tools/dfagen/examples/imported2.fsm b/tools/dfagen/examples/imported2.fsm
index d9592d3d..cf76b34b 100644
--- a/tools/dfagen/examples/imported2.fsm
+++ b/tools/dfagen/examples/imported2.fsm
@@ -1,5 +1,6 @@
# Imported second file.
Imported2
+ Second imported file comment.
States:
I2S1
diff --git a/tools/dfagen/examples/imported3.fsm b/tools/dfagen/examples/imported3.fsm
index 8115cc62..dfb08948 100644
--- a/tools/dfagen/examples/imported3.fsm
+++ b/tools/dfagen/examples/imported3.fsm
@@ -1,5 +1,6 @@
# Imported third file.
Imported3
+ Third imported file comment.
States:
I3S1