From ab8c3aef948e70a75d055174293f28f3146a592e Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sun, 22 Nov 2009 23:37:53 +0100 Subject: tools/dfagen: add import support, closes #82 --- tools/dfagen/dfagen/parser.g | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'tools/dfagen/dfagen/parser.g') diff --git a/tools/dfagen/dfagen/parser.g b/tools/dfagen/dfagen/parser.g index e510ed22..1e19bcc4 100644 --- a/tools/dfagen/dfagen/parser.g +++ b/tools/dfagen/dfagen/parser.g @@ -11,19 +11,32 @@ parser AutomatonParser: token QUALIFIER: "\w([\w ]*\w)?" token ATITLE: ".*?\n" token ATTR: "\w([\w =]*\w)?" + token IMPORT: "[\w./]+" rule automaton: ATITLE {{ a = Automaton (ATITLE.strip ()) }} ( comments {{ a.comments = comments }} ) ? + automatondef<> + EOF {{ return a }} + + rule automatonsub<>: + ATITLE + ( comments ) ? + automatondef<> + EOF + + rule automatondef<>: + ( importdef<> ) * "States:\n" ( statedef {{ a.add_state (statedef) }} ) * + ( importdef<> ) * "Events:\n" ( eventdef {{ a.add_event (eventdef) }} ) * + ( importdef<> ) * ( transdef<> ) * - EOF {{ return a }} rule statedef: {{ initial = False }} " " ( "\*" {{ initial = True }} @@ -70,3 +83,17 @@ parser AutomatonParser: ( COMMENTS {{ c += '\n' + COMMENTS.strip () }} ) * {{ return c }} + rule importdef<>: + "import\s+" + IMPORT {{ import_automaton (IMPORT, a) }} + "\n" + +%% + +def import_automaton (import_file, a): + f = open (import_file, 'r') + text = f.read () + f.close () + P = AutomatonParser (AutomatonParserScanner (text)) + return runtime.wrap_error_reporter (P, 'automatonsub', a) + -- cgit v1.2.3