Commits

Anonymous committed 7888b67

explain **{1}

Comments (0)

Files changed (2)

src/parser/actions.pm

   }
 }
 
-method enters($/) {
+method move($/, $k) {
   my $past := PAST::Stmts.new();
-
-  for $<charlist><character> {
-    my $res := mkcall('enter', mkstr($_));
-    $past.push($res);
-  }
-  make $past;
-}
-
-method exeunts($/) {
-  my $past := PAST::Stmts.new();
-
-  if $<charlist> == 0 {
-    $past.push(mkcall0('exeunt_omnes'));
+  if $<character> {
+    for $<character> {
+      my $res := mkcall($k, mkstr($_));
+      $past.push($res);
+    }
   }
   else {
-    for $<charlist><character> {
-      my $res := mkcall('exit', mkstr($_));
-      $past.push($res);
-    }
+    $past.push(mkcall0('exeunt_omnes'));
   } 
   make $past;
 }
-method exits($/) {
-  make mkcall('exit', mkstr($<character>));
-}
 
 method immediate($/) {
   my $value := 1;

src/parser/grammar.pg

 
 rule events {
   | <line> {*}   #= line
-  | <enters> {*} #= enters
-  | <exeunts> {*}  #= exeunts
-  | <exits> {*}  #= exits
+  | <move> {*}  #= move
 }
 
 rule chardef {
   ['iii' | 'ii' |  'iv' | 'i' | 'vii' | 'vi' | 'v' ]
 }
 
-rule enters {
-  '[' 
-    'enter' <charlist> {*} 
-  ']'
-}
-rule exeunts {
-  '[' 
-   'exeunt' <charlist> {*} 
+rule move {
+  '['
+    [
+    |'enter' <character> ['and' <character>]* {*} #= enter
+    # nqp does not have a flatten function, this enforces
+    # the iterability of a single match 
+    |'exit'  <character>**{1} {*} #= exit
+    |'exeunt' <character> ['and' <character>]+ {*} #= exit
+    |'exeunt' {*} #= exeunt
+    ]
   ']'
 }
 
-rule exits {
- '[' 
-  'exit' <character> {*} 
- ']'
+token description {
+  <-end>*
 }
-token description {
-  <-end>* 
-}