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/parser.g | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'tools/dfagen/dfagen/parser.g') 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*" -- cgit v1.2.3