Bläddra i källkod

MPIDE-27: convert trigger body into JS function

The embedded code in trigger bodies is now converted into a function,
and systems and behaviors have property objects attached to them.

Updated docs to reflect changes.
Austin Meagher 10 år sedan
förälder
incheckning
c0ba83b98c
2 ändrade filer med 15 tillägg och 2 borttagningar
  1. 4 2
      docs/parser.md
  2. 11 0
      src/lib/parser/modellang.pegjs

+ 4 - 2
docs/parser.md

@@ -16,6 +16,7 @@ System:
   id: String
   id: String
   body: Array <Sequence & Alternation>
   body: Array <Sequence & Alternation>
   refs: Array <String>
   refs: Array <String>
+  properties: Object
   scope: Scope
   scope: Scope
 ```
 ```
 
 
@@ -25,6 +26,7 @@ Behavior:
   id: String
   id: String
   body: Array <Sequence & Alternation>
   body: Array <Sequence & Alternation>
   refs: Array <String>
   refs: Array <String>
+  properties: Object
   scope: Scope
   scope: Scope
 ```
 ```
 
 
@@ -37,8 +39,8 @@ Interaction:
 ```
 ```
 Trigger:
 Trigger:
   type: "Trigger"
   type: "Trigger"
-  on: Selector
-  do: ?blob?
+  on: Selector | Expression
+  do: Function
 ```
 ```
 
 
 ```
 ```

+ 11 - 0
src/lib/parser/modellang.pegjs

@@ -94,6 +94,15 @@
             });
             });
         }
         }
 
 
+        return functionify(model);
+    };
+
+    var functionify = function functionify(model) {
+        for (var t in model.triggers) {
+            var trigger = model.triggers[t];
+            trigger.do = new Function("self", trigger.do);
+        }
+
         return model;
         return model;
     };
     };
 
 
@@ -131,12 +140,14 @@
             ast.Id.call(this, "System", id);
             ast.Id.call(this, "System", id);
             this.body = body;
             this.body = body;
             this.refs = refs;
             this.refs = refs;
+            this.properties = {};
         },
         },
 
 
         Behavior: function Behavior(id, body, refs) {
         Behavior: function Behavior(id, body, refs) {
             ast.Id.call(this, "Behavior", id);
             ast.Id.call(this, "Behavior", id);
             this.body = body;
             this.body = body;
             this.refs = refs;
             this.refs = refs;
+            this.properties = {};
         },
         },
 
 
         Interaction: function Interaction(type, body) {
         Interaction: function Interaction(type, body) {