Browse Source

Augmented operand parsed and constructed correctly.

Herbert Vojčík 8 years ago
parent
commit
b485e08cf9
4 changed files with 436 additions and 104 deletions
  1. 54 0
      src/Compiler-AST.js
  2. 21 0
      src/Compiler-AST.st
  3. 330 103
      support/parser.js
  4. 31 1
      support/parser.pegjs

+ 54 - 0
src/Compiler-AST.js

@@ -1910,6 +1910,33 @@ $globals.QuasiSendNode);
 
 
 
+$core.addClass('BranchSendNode', $globals.QuasiSendNode, [], 'Compiler-AST');
+$core.addMethod(
+$core.method({
+selector: "valueForReceiver:",
+protocol: 'building',
+fn: function (anObject){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+self._nodes_([$recv($recv(self._nodes())._first())._valueForReceiver_(anObject)]);
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"valueForReceiver:",{anObject:anObject},$globals.BranchSendNode)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["anObject"],
+source: "valueForReceiver: anObject\x0a\x09self nodes: {self nodes first valueForReceiver: anObject}.\x0a\x09^ self",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["nodes:", "valueForReceiver:", "first", "nodes"]
+}),
+$globals.BranchSendNode);
+
+
+
 $core.addClass('CascadeNode', $globals.QuasiSendNode, [], 'Compiler-AST');
 //>>excludeStart("ide", pragmas.excludeIdeData);
 $globals.CascadeNode.comment="I represent an cascade node.";
@@ -1955,6 +1982,33 @@ messageSends: []
 }),
 $globals.CascadeNode);
 
+$core.addMethod(
+$core.method({
+selector: "valueForReceiver:",
+protocol: 'building',
+fn: function (anObject){
+var self=this;
+var nds;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+nds=self._nodes();
+$recv(nds)._at_put_((1),$recv($recv(nds)._first())._valueForReceiver_(anObject));
+self._nodes_(nds);
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"valueForReceiver:",{anObject:anObject,nds:nds},$globals.CascadeNode)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["anObject"],
+source: "valueForReceiver: anObject\x0a\x09| nds |\x0a\x09nds := self nodes.\x0a\x09nds at: 1 put: (nds first valueForReceiver: anObject).\x0a\x09self nodes: nds.\x0a\x09^ self",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["nodes", "at:put:", "valueForReceiver:", "first", "nodes:"]
+}),
+$globals.CascadeNode);
+
 
 
 $core.addClass('SendNode', $globals.QuasiSendNode, ['selector', 'arguments', 'index'], 'Compiler-AST');

+ 21 - 0
src/Compiler-AST.st

@@ -446,12 +446,33 @@ receiver: anObject
 	receiver := anObject
 ! !
 
+QuasiSendNode subclass: #BranchSendNode
+	instanceVariableNames: ''
+	package: 'Compiler-AST'!
+
+!BranchSendNode methodsFor: 'building'!
+
+valueForReceiver: anObject
+	self nodes: {self nodes first valueForReceiver: anObject}.
+	^ self
+! !
+
 QuasiSendNode subclass: #CascadeNode
 	instanceVariableNames: ''
 	package: 'Compiler-AST'!
 !CascadeNode commentStamp!
 I represent an cascade node.!
 
+!CascadeNode methodsFor: 'building'!
+
+valueForReceiver: anObject
+	| nds |
+	nds := self nodes.
+	nds at: 1 put: (nds first valueForReceiver: anObject).
+	self nodes: nds.
+	^ self
+! !
+
 !CascadeNode methodsFor: 'testing'!
 
 isCascadeNode

File diff suppressed because it is too large
+ 330 - 103
support/parser.js


+ 31 - 1
support/parser.pegjs

@@ -164,7 +164,37 @@ block          = '[' params:wsBlockParamList? sequence:wsSequenceWs? ']' {
 
 operand        = literal / reference / subexpression
 
+augment = "(" send:(wsBinaryTail / wsKeywordMessage / wsUnaryTail) messages:(ws ";" mess:wsMessage {return mess;})* ws ")" {
+                     if (messages.length) {
+                         messages.unshift(send);
+                         send = $globals.CascadeNode._new()
+                                ._position_((line()).__at(column()))
+                                ._source_(text())
+                                ._nodes_(messages);
+					 }
+					 return $globals.BranchSendNode._new()
+                            ._position_((line()).__at(column()))
+                            ._source_(text())
+                            ._nodes_([send]);
+                 }
+
+wsAugmentTail      = ws message:augment tail:wsAugmentTail? {
+                     if(tail) {
+                         return tail._valueForReceiver_(message);
+                     }
+                     else {
+                         return message;
+                     }
+                 }
 
+augmentedOperand = operand:operand tail:wsAugmentTail? {
+                     if(tail) {
+                         return tail._valueForReceiver_(operand);
+                     }
+                     else {
+                         return operand;
+                     }
+                 }
 
 wsUnaryMessage   = ws selector:unarySelector !":" {
                      return $globals.SendNode._new()
@@ -182,7 +212,7 @@ wsUnaryTail      = message:wsUnaryMessage tail:wsUnaryTail? {
                      }
                  }
 
-unarySend      = receiver:operand tail:wsUnaryTail? {
+unarySend      = receiver:augmentedOperand tail:wsUnaryTail? {
                      if(tail) {
                          return tail._valueForReceiver_(receiver);
                      }

Some files were not shown because too many files changed in this diff