summaryrefslogtreecommitdiffstats
path: root/test/uscxml/test-prolog.scxml
blob: a0a79cb6a5afaf1499f70d5f525fcec619958e59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<scxml datamodel="prolog" name="outer">
  <!-- a nested SCXML interpreter with prolog -->

  <datamodel>
    <data src="" />
    <data id="father">
      bob, jim.
      bob, john.
    </data>
    <data id="">
      mother(martha, jim).
      mother(martha, john).
    </data>
    <data id="household">
      {
        name: "The Bobsons",
        members: ['bob', 'martha', 'jim', 'john']
      }
    </data>
    <data id="childs">
      <child name="jim" father="bob" />
      <child name="john" father="bob" />
    </data>
  </datamodel>
  <state id="start">
    <!-- invoke type="http://www.w3.org/TR/scxml/" autoforward="true">
      <content>
        <scxml datamodel="prolog" name="inner">
          <state id="idle">
            <onentry>
              <log label="Entering inner" />
              <send target="#_parent" event="inner" />
            </onentry>
            <transition target="end" event="foo" />
            <transition type="internal" event="*" target="idle">
              <log label="invoked" expr="event(name(X))." />
            </transition>
          </state>
          <state id="end" final="true" />
        </scxml>
      </content>
    </invoke -->
  
    <state id="s1">
      <onentry>
        <log label="Entering s1" />
        <script>
          :- dynamic ampel/1.
          ampel(false).
          ampel(X) :- retract(ampel(_)), assertz(ampel(X)).
        </script>
        <script type="query">
          ampel(true).
        </script>
        <assign location="">
          retract(father(bob, jim)).
          assert(father(steve, jim)).
          assert(father(bob, jack)).
        </assign>
        <log label="foreach" />
        <foreach array="father(bob, X)"
                 item="child"
                 index="index">
          <log label="index" expr="index(X)" />
          <log label="child" expr="child(X)" />
        </foreach>
      </onentry>
      <transition target="s2"
                  cond="mother(martha, X), father(bob, X), in(s1)"/>
    </state>
    <state id="s2">
      <onentry>
        <log label="Entering s2" />
        <send type="basichttp"
              targetexpr="ioprocessors(basichttp(location(X)))"
              event="foo">
          <content>
            <p>Snippet of XML</p>
          </content>
        </send>
      </onentry>
      <transition 
        target="end"
        event="foo"
        cond="member(element('p',_,_), X), event(data(X))" />
    </state>
  </state>
  <state id="end" final="true" />
</scxml>