Browse Source

parser: keywordSend with optional tail

consistent with binarySend and unarySend
simplifies a bit (keywordSend enough, no need for keywordSend / binarySend)
Herbert Vojčík 8 years ago
parent
commit
27bb184612
2 changed files with 59 additions and 60 deletions
  1. 50 56
      support/parser.js
  2. 9 4
      support/parser.pegjs

+ 50 - 56
support/parser.js

@@ -282,13 +282,10 @@ $globals.SmalltalkParser = (function() {
                                      ._selector_(selector.join(""))
                                      ._arguments_(args);
                          },
-        peg$c119 = function(receiver, tail) {
-                             return tail._valueForReceiver_(receiver);
-                         },
-        peg$c120 = ";",
-        peg$c121 = { type: "literal", value: ";", description: "\";\"" },
-        peg$c122 = function(mess) {return mess;},
-        peg$c123 = function(send, messages) {
+        peg$c119 = ";",
+        peg$c120 = { type: "literal", value: ";", description: "\";\"" },
+        peg$c121 = function(mess) {return mess;},
+        peg$c122 = function(send, messages) {
                              var cascade = [];
                              cascade.push(send);
                              for(var i = 0; i < messages.length; i++) {
@@ -300,21 +297,21 @@ $globals.SmalltalkParser = (function() {
                                     ._receiver_(send._receiver())
                                     ._nodes_(cascade);
                          },
-        peg$c124 = "<",
-        peg$c125 = { type: "literal", value: "<", description: "\"<\"" },
-        peg$c126 = ">>",
-        peg$c127 = { type: "literal", value: ">>", description: "\">>\"" },
-        peg$c128 = function() {return ">";},
-        peg$c129 = /^[^>]/,
-        peg$c130 = { type: "class", value: "[^>]", description: "[^>]" },
-        peg$c131 = ">",
-        peg$c132 = { type: "literal", value: ">", description: "\">\"" },
-        peg$c133 = function(val) {
+        peg$c123 = "<",
+        peg$c124 = { type: "literal", value: "<", description: "\"<\"" },
+        peg$c125 = ">>",
+        peg$c126 = { type: "literal", value: ">>", description: "\">>\"" },
+        peg$c127 = function() {return ">";},
+        peg$c128 = /^[^>]/,
+        peg$c129 = { type: "class", value: "[^>]", description: "[^>]" },
+        peg$c130 = ">",
+        peg$c131 = { type: "literal", value: ">", description: "\">\"" },
+        peg$c132 = function(val) {
                              return $globals.JSStatementNode._new()
                                     ._position_((line()).__at(column()))
                                     ._source_(val.join(""))
                          },
-        peg$c134 = function(pattern, sequence) {
+        peg$c133 = function(pattern, sequence) {
                               return $globals.MethodNode._new()
                                      ._position_((line()).__at(column()))
                                      ._source_(text())
@@ -322,9 +319,9 @@ $globals.SmalltalkParser = (function() {
                                      ._arguments_(pattern[1])
                                      ._nodes_([sequence]);
                          },
-        peg$c135 = function(send) { return send._selector() === "->" },
-        peg$c136 = function(send) { return [send._receiver(), send._arguments()[0]]; },
-        peg$c137 = function(first, others) { return first.concat.apply(first, others); },
+        peg$c134 = function(send) { return send._selector() === "->" },
+        peg$c135 = function(send) { return [send._receiver(), send._arguments()[0]]; },
+        peg$c136 = function(first, others) { return first.concat.apply(first, others); },
 
         peg$currPos          = 0,
         peg$reportedPos      = 0,
@@ -2211,9 +2208,6 @@ $globals.SmalltalkParser = (function() {
         s0 = peg$parsecascade();
         if (s0 === peg$FAILED) {
           s0 = peg$parsekeywordSend();
-          if (s0 === peg$FAILED) {
-            s0 = peg$parsebinarySend();
-          }
         }
       }
 
@@ -3360,9 +3354,12 @@ $globals.SmalltalkParser = (function() {
       s1 = peg$parsebinarySend();
       if (s1 !== peg$FAILED) {
         s2 = peg$parsekeywordMessage();
+        if (s2 === peg$FAILED) {
+          s2 = peg$c41;
+        }
         if (s2 !== peg$FAILED) {
           peg$reportedPos = s0;
-          s1 = peg$c119(s1, s2);
+          s1 = peg$c115(s1, s2);
           s0 = s1;
         } else {
           peg$currPos = s0;
@@ -3417,20 +3414,17 @@ $globals.SmalltalkParser = (function() {
       s1 = peg$parsews();
       if (s1 !== peg$FAILED) {
         s2 = peg$parsekeywordSend();
-        if (s2 === peg$FAILED) {
-          s2 = peg$parsebinarySend();
-        }
         if (s2 !== peg$FAILED) {
           s3 = [];
           s4 = peg$currPos;
           s5 = peg$parsews();
           if (s5 !== peg$FAILED) {
             if (input.charCodeAt(peg$currPos) === 59) {
-              s6 = peg$c120;
+              s6 = peg$c119;
               peg$currPos++;
             } else {
               s6 = peg$FAILED;
-              if (peg$silentFails === 0) { peg$fail(peg$c121); }
+              if (peg$silentFails === 0) { peg$fail(peg$c120); }
             }
             if (s6 !== peg$FAILED) {
               s7 = peg$parsews();
@@ -3438,7 +3432,7 @@ $globals.SmalltalkParser = (function() {
                 s8 = peg$parsemessage();
                 if (s8 !== peg$FAILED) {
                   peg$reportedPos = s4;
-                  s5 = peg$c122(s8);
+                  s5 = peg$c121(s8);
                   s4 = s5;
                 } else {
                   peg$currPos = s4;
@@ -3463,11 +3457,11 @@ $globals.SmalltalkParser = (function() {
               s5 = peg$parsews();
               if (s5 !== peg$FAILED) {
                 if (input.charCodeAt(peg$currPos) === 59) {
-                  s6 = peg$c120;
+                  s6 = peg$c119;
                   peg$currPos++;
                 } else {
                   s6 = peg$FAILED;
-                  if (peg$silentFails === 0) { peg$fail(peg$c121); }
+                  if (peg$silentFails === 0) { peg$fail(peg$c120); }
                 }
                 if (s6 !== peg$FAILED) {
                   s7 = peg$parsews();
@@ -3475,7 +3469,7 @@ $globals.SmalltalkParser = (function() {
                     s8 = peg$parsemessage();
                     if (s8 !== peg$FAILED) {
                       peg$reportedPos = s4;
-                      s5 = peg$c122(s8);
+                      s5 = peg$c121(s8);
                       s4 = s5;
                     } else {
                       peg$currPos = s4;
@@ -3499,7 +3493,7 @@ $globals.SmalltalkParser = (function() {
           }
           if (s3 !== peg$FAILED) {
             peg$reportedPos = s0;
-            s1 = peg$c123(s2, s3);
+            s1 = peg$c122(s2, s3);
             s0 = s1;
           } else {
             peg$currPos = s0;
@@ -3532,72 +3526,72 @@ $globals.SmalltalkParser = (function() {
 
       s0 = peg$currPos;
       if (input.charCodeAt(peg$currPos) === 60) {
-        s1 = peg$c124;
+        s1 = peg$c123;
         peg$currPos++;
       } else {
         s1 = peg$FAILED;
-        if (peg$silentFails === 0) { peg$fail(peg$c125); }
+        if (peg$silentFails === 0) { peg$fail(peg$c124); }
       }
       if (s1 !== peg$FAILED) {
         s2 = [];
         s3 = peg$currPos;
-        if (input.substr(peg$currPos, 2) === peg$c126) {
-          s4 = peg$c126;
+        if (input.substr(peg$currPos, 2) === peg$c125) {
+          s4 = peg$c125;
           peg$currPos += 2;
         } else {
           s4 = peg$FAILED;
-          if (peg$silentFails === 0) { peg$fail(peg$c127); }
+          if (peg$silentFails === 0) { peg$fail(peg$c126); }
         }
         if (s4 !== peg$FAILED) {
           peg$reportedPos = s3;
-          s4 = peg$c128();
+          s4 = peg$c127();
         }
         s3 = s4;
         if (s3 === peg$FAILED) {
-          if (peg$c129.test(input.charAt(peg$currPos))) {
+          if (peg$c128.test(input.charAt(peg$currPos))) {
             s3 = input.charAt(peg$currPos);
             peg$currPos++;
           } else {
             s3 = peg$FAILED;
-            if (peg$silentFails === 0) { peg$fail(peg$c130); }
+            if (peg$silentFails === 0) { peg$fail(peg$c129); }
           }
         }
         while (s3 !== peg$FAILED) {
           s2.push(s3);
           s3 = peg$currPos;
-          if (input.substr(peg$currPos, 2) === peg$c126) {
-            s4 = peg$c126;
+          if (input.substr(peg$currPos, 2) === peg$c125) {
+            s4 = peg$c125;
             peg$currPos += 2;
           } else {
             s4 = peg$FAILED;
-            if (peg$silentFails === 0) { peg$fail(peg$c127); }
+            if (peg$silentFails === 0) { peg$fail(peg$c126); }
           }
           if (s4 !== peg$FAILED) {
             peg$reportedPos = s3;
-            s4 = peg$c128();
+            s4 = peg$c127();
           }
           s3 = s4;
           if (s3 === peg$FAILED) {
-            if (peg$c129.test(input.charAt(peg$currPos))) {
+            if (peg$c128.test(input.charAt(peg$currPos))) {
               s3 = input.charAt(peg$currPos);
               peg$currPos++;
             } else {
               s3 = peg$FAILED;
-              if (peg$silentFails === 0) { peg$fail(peg$c130); }
+              if (peg$silentFails === 0) { peg$fail(peg$c129); }
             }
           }
         }
         if (s2 !== peg$FAILED) {
           if (input.charCodeAt(peg$currPos) === 62) {
-            s3 = peg$c131;
+            s3 = peg$c130;
             peg$currPos++;
           } else {
             s3 = peg$FAILED;
-            if (peg$silentFails === 0) { peg$fail(peg$c132); }
+            if (peg$silentFails === 0) { peg$fail(peg$c131); }
           }
           if (s3 !== peg$FAILED) {
             peg$reportedPos = s0;
-            s1 = peg$c133(s2);
+            s1 = peg$c132(s2);
             s0 = s1;
           } else {
             peg$currPos = s0;
@@ -3647,7 +3641,7 @@ $globals.SmalltalkParser = (function() {
             s4 = peg$parsews();
             if (s4 !== peg$FAILED) {
               peg$reportedPos = s0;
-              s1 = peg$c134(s1, s3);
+              s1 = peg$c133(s1, s3);
               s0 = s1;
             } else {
               peg$currPos = s0;
@@ -3686,7 +3680,7 @@ $globals.SmalltalkParser = (function() {
       s1 = peg$parsebinarySend();
       if (s1 !== peg$FAILED) {
         peg$reportedPos = peg$currPos;
-        s2 = peg$c135(s1);
+        s2 = peg$c134(s1);
         if (s2) {
           s2 = peg$c112;
         } else {
@@ -3694,7 +3688,7 @@ $globals.SmalltalkParser = (function() {
         }
         if (s2 !== peg$FAILED) {
           peg$reportedPos = s0;
-          s1 = peg$c136(s1);
+          s1 = peg$c135(s1);
           s0 = s1;
         } else {
           peg$currPos = s0;
@@ -3783,7 +3777,7 @@ $globals.SmalltalkParser = (function() {
         }
         if (s2 !== peg$FAILED) {
           peg$reportedPos = s0;
-          s1 = peg$c137(s1, s2);
+          s1 = peg$c136(s1, s2);
           s0 = s1;
         } else {
           peg$currPos = s0;

+ 9 - 4
support/parser.pegjs

@@ -102,7 +102,7 @@ keywordPattern = pairs:(ws key:keyword ws arg:identifier {return {key:key, arg:a
 binaryPattern  = ws selector:binarySelector ws arg:identifier {return [selector, [arg]];}
 unaryPattern   = ws selector:unarySelector {return [selector, []];}
 
-expression     = assignment / cascade / keywordSend / binarySend
+expression     = assignment / cascade / keywordSend
 
 expressionList = ws "." ws expression:expression {return expression;}
 expressions    = first:expression others:expressionList* { return [first].concat(others); }
@@ -228,13 +228,18 @@ keywordMessage = pairs:keywordPair+ {
                              ._arguments_(args);
                  }
 
-keywordSend    = receiver:binarySend tail:keywordMessage {
-                     return tail._valueForReceiver_(receiver);
+keywordSend    = receiver:binarySend tail:keywordMessage? {
+                     if(tail) {
+                         return tail._valueForReceiver_(receiver);
+                     }
+                     else {
+                         return receiver;
+                     }
                  }
 
 message        = binaryMessage / unaryMessage / keywordMessage
 
-cascade        = ws send:(keywordSend / binarySend) messages:(ws ";" ws mess:message {return mess;})+ {
+cascade        = ws send:keywordSend messages:(ws ";" ws mess:message {return mess;})+ {
                      var cascade = [];
                      cascade.push(send);
                      for(var i = 0; i < messages.length; i++) {