summaryrefslogtreecommitdiff
path: root/tools
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
parent11ecac0ab42bba330230759b6250f664f52fee9c (diff)
tools/dfagen: add import support, closes #82
Diffstat (limited to 'tools')
-rw-r--r--tools/dfagen/dfagen/parser.g29
-rw-r--r--tools/dfagen/doc/dfagen.txt4
-rw-r--r--tools/dfagen/examples/Makefile11
-rw-r--r--tools/dfagen/examples/import.dump.ref58
-rw-r--r--tools/dfagen/examples/import.fsm29
-rw-r--r--tools/dfagen/examples/imported1.fsm16
-rw-r--r--tools/dfagen/examples/imported2.fsm16
-rw-r--r--tools/dfagen/examples/imported3.fsm20
8 files changed, 181 insertions, 2 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)
+
diff --git a/tools/dfagen/doc/dfagen.txt b/tools/dfagen/doc/dfagen.txt
index f3d8e93a..cd6d710b 100644
--- a/tools/dfagen/doc/dfagen.txt
+++ b/tools/dfagen/doc/dfagen.txt
@@ -113,6 +113,10 @@ describe several states which behave the same way::
command -> .
ignored
+If you want to split your automaton definition in several files, you can
+include other files using the import statement. This can be used between
+other sections. The imported file use the same syntax as the main file.
+
Invoking dfagen
===============
diff --git a/tools/dfagen/examples/Makefile b/tools/dfagen/examples/Makefile
index 1f7b3308..ad97b8a4 100644
--- a/tools/dfagen/examples/Makefile
+++ b/tools/dfagen/examples/Makefile
@@ -1,6 +1,6 @@
CFLAGS = -O2 -Wall
-all: ex1 ex2 ex1.png ex2.png ex2_tpl
+all: ex1 ex2 ex1.png ex2.png ex2_tpl import.dump.check
ex1: ex1.o ex1_cb.o
@@ -38,9 +38,18 @@ ex2_tpl: ex2.fsm ex2_tpl.conf
%.png: %.dot
dot -Tpng $< -o $@
+%.dump: %.fsm
+ python ../dfagen.py --dump -d $< > $@
+
+%.check: % %.ref
+ diff $^
+
+import.dump: import.fsm imported1.fsm imported2.fsm imported3.fsm
+
clean:
rm -f ex1 ex1.o ex1_cb.o ex1.c ex1.h ex1_cb_skel.c ex1_cb.h ex1_cb.c
rm -f ex1.dot ex1.png
rm -f ex2 ex2.o ex2_cb.o ex2_robot.o ex2.c ex2.h ex2_cb_skel.c ex2_cb.h ex2_cb.c
rm -f ex2.dot ex2.png
rm -f ex2_tpl_defs.h ex2_tpl_table.h
+ rm -f import.dump
diff --git a/tools/dfagen/examples/import.dump.ref b/tools/dfagen/examples/import.dump.ref
new file mode 100644
index 00000000..6cc359de
--- /dev/null
+++ b/tools/dfagen/examples/import.dump.ref
@@ -0,0 +1,58 @@
+Import
+ Import definitions from other files.
+
+States:
+ I1S1
+ I1S2
+ RS1
+ RS2
+ I2S1
+ I2S2
+ I3S1
+ I3S2
+
+Events:
+ i1e1
+ i1e2
+ i2e1
+ i2e2
+ re1
+ re2
+ i3e1
+ i3e2
+
+I1S1:
+ i1e2 -> I1S2
+
+I1S2:
+ i1e1 -> I1S1
+
+RS1:
+ re2 -> RS2
+ i1e2 -> RS2
+ i2e2 -> RS2
+ i3e2 -> RS2
+
+RS2:
+ re1 -> RS1
+ i1e1 -> RS1
+ i2e1 -> RS1
+ i3e1 -> RS1
+
+I2S1:
+ i2e2 -> I2S2
+
+I2S2:
+ i2e1 -> I2S1
+
+I3S1:
+ i3e2 -> I3S2
+ i2e2 -> I3S2
+ re2 -> I3S2
+
+I3S2:
+ i3e1 -> I3S1
+ i2e1 -> I3S1
+ re1 -> I3S1
+
+
diff --git a/tools/dfagen/examples/import.fsm b/tools/dfagen/examples/import.fsm
new file mode 100644
index 00000000..9d4b5cdf
--- /dev/null
+++ b/tools/dfagen/examples/import.fsm
@@ -0,0 +1,29 @@
+# Import root file.
+Import
+ Import definitions from other files.
+
+import imported1.fsm
+
+States:
+ RS1
+ RS2
+
+import imported2.fsm
+
+Events:
+ re1
+ re2
+
+import imported3.fsm
+
+RS1:
+ re2 -> RS2
+ i1e2 -> RS2
+ i2e2 -> RS2
+ i3e2 -> RS2
+
+RS2:
+ re1 -> RS1
+ i1e1 -> RS1
+ i2e1 -> RS1
+ i3e1 -> RS1
diff --git a/tools/dfagen/examples/imported1.fsm b/tools/dfagen/examples/imported1.fsm
new file mode 100644
index 00000000..fe4ee9ff
--- /dev/null
+++ b/tools/dfagen/examples/imported1.fsm
@@ -0,0 +1,16 @@
+# Imported first file.
+Imported1
+
+States:
+ I1S1
+ I1S2
+
+Events:
+ i1e1
+ i1e2
+
+I1S1:
+ i1e2 -> I1S2
+
+I1S2:
+ i1e1 -> I1S1
diff --git a/tools/dfagen/examples/imported2.fsm b/tools/dfagen/examples/imported2.fsm
new file mode 100644
index 00000000..d9592d3d
--- /dev/null
+++ b/tools/dfagen/examples/imported2.fsm
@@ -0,0 +1,16 @@
+# Imported second file.
+Imported2
+
+States:
+ I2S1
+ I2S2
+
+Events:
+ i2e1
+ i2e2
+
+I2S1:
+ i2e2 -> I2S2
+
+I2S2:
+ i2e1 -> I2S1
diff --git a/tools/dfagen/examples/imported3.fsm b/tools/dfagen/examples/imported3.fsm
new file mode 100644
index 00000000..8115cc62
--- /dev/null
+++ b/tools/dfagen/examples/imported3.fsm
@@ -0,0 +1,20 @@
+# Imported third file.
+Imported3
+
+States:
+ I3S1
+ I3S2
+
+Events:
+ i3e1
+ i3e2
+
+I3S1:
+ i3e2 -> I3S2
+ i2e2 -> I3S2
+ re2 -> I3S2
+
+I3S2:
+ i3e1 -> I3S1
+ i2e1 -> I3S1
+ re1 -> I3S1