summaryrefslogtreecommitdiff
path: root/tools/dfagen/dfagen
diff options
context:
space:
mode:
authorNicolas Schodet2009-11-22 23:37:53 +0100
committerNicolas Schodet2009-11-22 23:37:53 +0100
commitab8c3aef948e70a75d055174293f28f3146a592e (patch)
treef5313460b0016a1e639396e2658a7dc1993828e7 /tools/dfagen/dfagen
parent11ecac0ab42bba330230759b6250f664f52fee9c (diff)
tools/dfagen: add import support, closes #82
Diffstat (limited to 'tools/dfagen/dfagen')
-rw-r--r--tools/dfagen/dfagen/parser.g29
1 files changed, 28 insertions, 1 deletions
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<<a>>
+ EOF {{ return a }}
+
+ rule automatonsub<<a>>:
+ ATITLE
+ ( comments ) ?
+ automatondef<<a>>
+ EOF
+
+ rule automatondef<<a>>:
+ ( importdef<<a>> ) *
"States:\n"
( statedef {{ a.add_state (statedef) }}
) *
+ ( importdef<<a>> ) *
"Events:\n"
( eventdef {{ a.add_event (eventdef) }}
) *
+ ( importdef<<a>> ) *
( transdef<<a>>
) *
- EOF {{ return a }}
rule statedef: {{ initial = False }}
" " ( "\*" {{ initial = True }}
@@ -70,3 +83,17 @@ parser AutomatonParser:
( COMMENTS {{ c += '\n' + COMMENTS.strip () }}
) * {{ return c }}
+ rule importdef<<a>>:
+ "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)
+