Parcourir la source

MPIDE-27: add scopes to top-level systems

To assist in handling scope within the event trace generator, scopes are
attached to systems now. Additionally, some error checking was added to
scopes to alert the user of an invalid scope.

Some formatting changes.
Austin Meagher il y a 10 ans
Parent
commit
6a58abc686
1 fichiers modifiés avec 20 ajouts et 6 suppressions
  1. 20 6
      src/lib/parser/modellang.pegjs

+ 20 - 6
src/lib/parser/modellang.pegjs

@@ -141,6 +141,7 @@
             this.body = body;
             this.refs = refs;
             this.properties = {};
+            this.scope = { min:1, max:1 };
         },
 
         Behavior: function Behavior(id, body, refs) {
@@ -242,9 +243,9 @@ interaction_type
 
 system_item_selector "Selector"
     = !{ ast.selector = true; }
-    _ pre:("{" c:embedded_code "}" { return c; })? _
+    _ pre:( "{" c:embedded_code "}" { return c; } )? _
     sys:system_id ":" _ pattern:behavior_pattern
-    _ post:("{" c:embedded_code "}" { return c; })? _
+    _ post:( "{" c:embedded_code "}" { return c; } )? _
     { ast.selector = false; return new ast.Selector(sys, pattern, pre, post); }
 
 system_item_selector_sans "Selector"
@@ -253,15 +254,28 @@ system_item_selector_sans "Selector"
     { ast.selector = false; return new ast.Selector(sys, pattern); }
 
 behavior_pattern "Behavior Pattern"
-    = (alternation / sequence)+
+    = ( alternation / sequence )+
 
 alternation
     = head:behavior_pattern_item tail:( _PIPE_ item:behavior_pattern_item { return item; } )+
-    { return new ast.Alternation([head].concat(tail)); }
+    {
+        var body = [head].concat(tail);
+        for (var i = 0; i < body.length; i++) {
+            if (body[i].scope.max && body[i].scope.min > body[i].scope.max)
+                ast.errors.push(err("ERROR: Scope (" + body[i].id + ") lower bound exceeds its upper bound"));
+        }
+        return new ast.Alternation(body);
+    }
 
 sequence
     = body:behavior_pattern_item+
-    { return new ast.Sequence(body); }
+    {
+        for (var i = 0; i < body.length; i++) {
+            if (body[i].scope.max && body[i].scope.min > body[i].scope.max)
+                ast.errors.push(err("ERROR: Scope (" + body[i].id + ") lower bound exceeds its upper bound"));
+        }
+        return new ast.Sequence(body);
+    }
 
 behavior_pattern_item
     = _ i:group q:quantifier? _
@@ -292,7 +306,7 @@ init "Init Block"
     { return new ast.Init(system, body); }
 
 embedded_code
-    = [^{}]* ( "{" embedded_code "}")? [^{}]*
+    = [^{}]* ( "{" embedded_code "}" )? [^{}]*
     { return text().trim(); }
 
 behavior_id = id:ID { return id; }