From 7df762056280a338a2ec349015403b6f506a0dbf Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Fri, 18 Dec 2009 01:11:28 +0100 Subject: tools/dfagen: add origin to states, events and branches, refs #102 --- tools/dfagen/dfagen/automaton.py | 10 +++++++--- tools/dfagen/dfagen/parser.g | 37 +++++++++++++++++++++-------------- tools/dfagen/examples/import.dump.ref | 6 ++++++ tools/dfagen/examples/imported1.fsm | 1 + tools/dfagen/examples/imported2.fsm | 1 + tools/dfagen/examples/imported3.fsm | 1 + 6 files changed, 38 insertions(+), 18 deletions(-) (limited to 'tools') 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<> + automatondef<> EOF {{ return a }} rule automatonsub<>: - ATITLE - ( comments ) ? - automatondef<> + ATITLE {{ name = ATITLE.strip () }} + ( comments {{ a.comments += "\n" + name + ":\n" + comments }} + ) ? + automatondef<> EOF - rule automatondef<>: + rule automatondef<>: ( importdef<> ) * "States:\n" - ( statedef {{ a.add_state (statedef) }} + ( statedef<> + {{ a.add_state (statedef) }} ) * ( importdef<> ) * "Events:\n" - ( eventdef {{ a.add_event (eventdef) }} + ( eventdef<> + {{ a.add_event (eventdef) }} ) * ( importdef<> ) * - ( transdef<> + ( transdef<> ) * - rule statedef: {{ initial = False }} + rule statedef<>: {{ 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<>: + " " EVENT {{ e = Event (EVENT, origin = origin) }} "\n" ( comments {{ e.comments = comments }} ) ? {{ return e }} - rule transdef<>: transsl<> - ( trans<> {{ for s in transsl: s.add_branch (trans) }} + rule transdef<>: + transsl<> + ( trans<> + {{ for s in transsl: s.add_branch (trans) }} ) * rule transsl<>: {{ sl = [ ] }} @@ -66,7 +72,8 @@ parser AutomatonParser: ) * ":\n" {{ return sl }} - rule trans<>: " " EVENT {{ t = TransitionBranch (a.events[EVENT]) }} + rule trans<>: + " " 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 -- cgit v1.2.3