From 164ac3a34cbac441e82b256c97cb8784ea9d482c Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Mon, 17 Mar 2008 22:53:01 +0100 Subject: * tools/dfagen: - added dfagen. --- tools/dfagen/dfagen/parser.g | 62 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tools/dfagen/dfagen/parser.g (limited to 'tools/dfagen/dfagen/parser.g') diff --git a/tools/dfagen/dfagen/parser.g b/tools/dfagen/dfagen/parser.g new file mode 100644 index 00000000..62f9f4d1 --- /dev/null +++ b/tools/dfagen/dfagen/parser.g @@ -0,0 +1,62 @@ +from dfagen.automaton import * + +%% + +parser AutomatonParser: + ignore: "(#.*?)?\n" + token EOF: "$" + token COMMENTS: " .+?\n" + token STATE: "\w+" + token EVENT: "\w([\w ]*\w)?" + token QUALIFIER: "\w([\w ]*\w)?" + token ATITLE: ".*?\n" + + rule automaton: ATITLE {{ a = Automaton (ATITLE.strip ()) }} + ( comments {{ a.comments = comments }} + ) ? + "States:\n" + ( statedef {{ a.add_state (statedef) }} + ) * + "Events:\n" + ( eventdef {{ a.add_event (eventdef) }} + ) * + ( transdef<> + ) * + EOF {{ return a }} + + rule statedef: " " STATE {{ s = State (STATE) }} + "\n" + ( comments {{ s.comments = comments }} + ) ? + {{ return s }} + + rule eventdef: " " EVENT {{ e = Event (EVENT) }} + "\n" + ( comments {{ e.comments = comments }} + ) ? + {{ return e }} + + rule transdef<>: transsl<> + ( trans<> {{ for s in transsl: s.add_branch (trans) }} + ) * + + rule transsl<>: {{ sl = [ ] }} + STATE {{ sl.append (a.states[STATE]) }} + ( ",\s*" STATE {{ sl.append (a.states[STATE]) }} + ) * + ":\n" {{ return sl }} + + rule trans<>: " " EVENT {{ t = TransitionBranch (a.events[EVENT]) }} + ( ":\s*" QUALIFIER {{ t.name = QUALIFIER }} + ) ? + "\s*->\s*" + ( STATE {{ t.to = a.states[STATE] }} + | "\\." ) + ( comments {{ t.comments = comments }} + ) ? + {{ return t }} + + rule comments: COMMENTS {{ c = COMMENTS.strip () }} + ( COMMENTS {{ c += '\n' + COMMENTS.strip () }} + ) * {{ return c }} + -- cgit v1.2.3