Selaa lähdekoodia

renames `Node >> atPosition:` to `Node >> navigationNodeAt:ifAbsent:`

Nicolas Petton 10 vuotta sitten
vanhempi
commit
9270d8dd40
6 muutettua tiedostoa jossa 77 lisäystä ja 73 poistoa
  1. 42 40
      src/Compiler-AST.js
  2. 6 6
      src/Compiler-AST.st
  3. 13 7
      src/Compiler-Tests.js
  4. 3 3
      src/Compiler-Tests.st
  5. 8 13
      src/Helios-Workspace.js
  6. 5 4
      src/Helios-Workspace.st

+ 42 - 40
src/Compiler-AST.js

@@ -65,46 +65,6 @@ referencedClasses: []
 }),
 }),
 globals.Node);
 globals.Node);
 
 
-smalltalk.addMethod(
-smalltalk.method({
-selector: "atPosition:",
-protocol: 'accessing',
-fn: function (aPoint){
-var self=this;
-var children;
-return smalltalk.withContext(function($ctx1) { 
-var $3,$2,$1;
-var $early={};
-try {
-children=_st(self._allNodes())._select_((function(each){
-return smalltalk.withContext(function($ctx2) {
-return _st(_st(each)._isNavigationNode())._and_((function(){
-return smalltalk.withContext(function($ctx3) {
-return _st(each)._inPosition_(aPoint);
-}, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)})}));
-}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
-_st(children)._ifEmpty_((function(){
-throw $early=[nil];
-}));
-$1=_st(_st(_st(children)._asArray())._sort_((function(a,b){
-return smalltalk.withContext(function($ctx2) {
-$3=_st(a)._positionStart();
-$ctx2.sendIdx["positionStart"]=1;
-$2=_st($3)._dist_(aPoint);
-$ctx2.sendIdx["dist:"]=1;
-return _st($2).__lt_eq(_st(_st(b)._positionStart())._dist_(aPoint));
-}, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1,4)})})))._first();
-return $1;
-}
-catch(e) {if(e===$early)return e[0]; throw e}
-}, function($ctx1) {$ctx1.fill(self,"atPosition:",{aPoint:aPoint,children:children},globals.Node)})},
-args: ["aPoint"],
-source: "atPosition: aPoint\x0a\x09\x22Answer the navigation node in the receiver's tree at aPoint \x0a\x09or nil if no navigation node was found.\x0a\x09\x0a\x09See `node >> isNaviationNode`\x22\x0a\x09\x0a\x09| children |\x0a\x09\x0a\x09children := self allNodes select: [ :each | \x0a\x09\x09each isNavigationNode and: [ each inPosition: aPoint ] ].\x0a\x09\x0a\x09children ifEmpty: [ ^ nil ].\x0a\x09\x0a\x09^ (children asArray sort: [ :a :b | \x0a\x09\x09(a positionStart dist: aPoint) <= \x0a\x09\x09(b positionStart dist: aPoint) ]) first",
-messageSends: ["select:", "allNodes", "and:", "isNavigationNode", "inPosition:", "ifEmpty:", "first", "sort:", "asArray", "<=", "dist:", "positionStart"],
-referencedClasses: []
-}),
-globals.Node);
-
 smalltalk.addMethod(
 smalltalk.addMethod(
 smalltalk.method({
 smalltalk.method({
 selector: "inPosition:",
 selector: "inPosition:",
@@ -389,6 +349,48 @@ referencedClasses: []
 }),
 }),
 globals.Node);
 globals.Node);
 
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "navigationNodeAt:ifAbsent:",
+protocol: 'accessing',
+fn: function (aPoint,aBlock){
+var self=this;
+var children;
+return smalltalk.withContext(function($ctx1) { 
+var $1,$4,$3,$2;
+var $early={};
+try {
+children=_st(self._allNodes())._select_((function(each){
+return smalltalk.withContext(function($ctx2) {
+return _st(_st(each)._isNavigationNode())._and_((function(){
+return smalltalk.withContext(function($ctx3) {
+return _st(each)._inPosition_(aPoint);
+}, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)})}));
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
+_st(children)._ifEmpty_((function(){
+return smalltalk.withContext(function($ctx2) {
+$1=_st(aBlock)._value();
+throw $early=[$1];
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)})}));
+$2=_st(_st(_st(children)._asArray())._sort_((function(a,b){
+return smalltalk.withContext(function($ctx2) {
+$4=_st(a)._positionStart();
+$ctx2.sendIdx["positionStart"]=1;
+$3=_st($4)._dist_(aPoint);
+$ctx2.sendIdx["dist:"]=1;
+return _st($3).__lt_eq(_st(_st(b)._positionStart())._dist_(aPoint));
+}, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1,4)})})))._first();
+return $2;
+}
+catch(e) {if(e===$early)return e[0]; throw e}
+}, function($ctx1) {$ctx1.fill(self,"navigationNodeAt:ifAbsent:",{aPoint:aPoint,aBlock:aBlock,children:children},globals.Node)})},
+args: ["aPoint", "aBlock"],
+source: "navigationNodeAt: aPoint ifAbsent: aBlock\x0a\x09\x22Answer the navigation node in the receiver's tree at aPoint \x0a\x09or nil if no navigation node was found.\x0a\x09\x0a\x09See `node >> isNaviationNode`\x22\x0a\x09\x0a\x09| children |\x0a\x09\x0a\x09children := self allNodes select: [ :each | \x0a\x09\x09each isNavigationNode and: [ each inPosition: aPoint ] ].\x0a\x09\x0a\x09children ifEmpty: [ ^ aBlock value ].\x0a\x09\x0a\x09^ (children asArray sort: [ :a :b | \x0a\x09\x09(a positionStart dist: aPoint) <= \x0a\x09\x09(b positionStart dist: aPoint) ]) first",
+messageSends: ["select:", "allNodes", "and:", "isNavigationNode", "inPosition:", "ifEmpty:", "value", "first", "sort:", "asArray", "<=", "dist:", "positionStart"],
+referencedClasses: []
+}),
+globals.Node);
+
 smalltalk.addMethod(
 smalltalk.addMethod(
 smalltalk.method({
 smalltalk.method({
 selector: "nextChild",
 selector: "nextChild",

+ 6 - 6
src/Compiler-AST.st

@@ -26,7 +26,11 @@ allNodes
 	^ allNodes
 	^ allNodes
 !
 !
 
 
-atPosition: aPoint
+method
+	^ self parent ifNotNil: [ :node | node method ]
+!
+
+navigationNodeAt: aPoint ifAbsent: aBlock
 	"Answer the navigation node in the receiver's tree at aPoint 
 	"Answer the navigation node in the receiver's tree at aPoint 
 	or nil if no navigation node was found.
 	or nil if no navigation node was found.
 	
 	
@@ -37,17 +41,13 @@ atPosition: aPoint
 	children := self allNodes select: [ :each | 
 	children := self allNodes select: [ :each | 
 		each isNavigationNode and: [ each inPosition: aPoint ] ].
 		each isNavigationNode and: [ each inPosition: aPoint ] ].
 	
 	
-	children ifEmpty: [ ^ nil ].
+	children ifEmpty: [ ^ aBlock value ].
 	
 	
 	^ (children asArray sort: [ :a :b | 
 	^ (children asArray sort: [ :a :b | 
 		(a positionStart dist: aPoint) <= 
 		(a positionStart dist: aPoint) <= 
 		(b positionStart dist: aPoint) ]) first
 		(b positionStart dist: aPoint) ]) first
 !
 !
 
 
-method
-	^ self parent ifNotNil: [ :node | node method ]
-!
-
 nextChild
 nextChild
 	"Answer the next node after aNode.
 	"Answer the next node after aNode.
 	Recurse into the possible children of the receiver to answer the next node to be evaluated"
 	Recurse into the possible children of the receiver to answer the next node to be evaluated"

+ 13 - 7
src/Compiler-Tests.js

@@ -284,8 +284,10 @@ $ctx1.sendIdx["parse:"]=1;
 $3=node;
 $3=node;
 $4=(2).__at((4));
 $4=(2).__at((4));
 $ctx1.sendIdx["@"]=1;
 $ctx1.sendIdx["@"]=1;
-$2=_st($3)._nodeAtPosition_($4);
-$ctx1.sendIdx["nodeAtPosition:"]=1;
+$2=_st($3)._navigationNodeAt_ifAbsent_($4,(function(){
+return nil;
+}));
+$ctx1.sendIdx["navigationNodeAt:ifAbsent:"]=1;
 $1=_st($2)._source();
 $1=_st($2)._source();
 self._assert_equals_($1,"self");
 self._assert_equals_($1,"self");
 $ctx1.sendIdx["assert:equals:"]=1;
 $ctx1.sendIdx["assert:equals:"]=1;
@@ -294,18 +296,22 @@ $ctx1.sendIdx["parse:"]=2;
 $7=node;
 $7=node;
 $8=(2).__at((7));
 $8=(2).__at((7));
 $ctx1.sendIdx["@"]=2;
 $ctx1.sendIdx["@"]=2;
-$6=_st($7)._nodeAtPosition_($8);
-$ctx1.sendIdx["nodeAtPosition:"]=2;
+$6=_st($7)._navigationNodeAt_ifAbsent_($8,(function(){
+return nil;
+}));
+$ctx1.sendIdx["navigationNodeAt:ifAbsent:"]=2;
 $5=_st($6)._selector();
 $5=_st($6)._selector();
 $ctx1.sendIdx["selector"]=1;
 $ctx1.sendIdx["selector"]=1;
 self._assert_equals_($5,"ifTrue:");
 self._assert_equals_($5,"ifTrue:");
 $ctx1.sendIdx["assert:equals:"]=2;
 $ctx1.sendIdx["assert:equals:"]=2;
 node=self._parse_("foo\x0a\x09self foo; bar; baz");
 node=self._parse_("foo\x0a\x09self foo; bar; baz");
-self._assert_equals_(_st(_st(node)._nodeAtPosition_((2).__at((8))))._selector(),"foo");
+self._assert_equals_(_st(_st(node)._navigationNodeAt_ifAbsent_((2).__at((8)),(function(){
+return nil;
+})))._selector(),"foo");
 return self}, function($ctx1) {$ctx1.fill(self,"testNodeAtPosition",{node:node},globals.ASTPositionTest)})},
 return self}, function($ctx1) {$ctx1.fill(self,"testNodeAtPosition",{node:node},globals.ASTPositionTest)})},
 args: [],
 args: [],
-source: "testNodeAtPosition\x0a\x09| node |\x0a\x09\x0a\x09node := self parse: 'yourself\x0a\x09^ self'.\x0a\x09\x0a\x09self assert: (node nodeAtPosition: 2@4) source equals: 'self'.\x0a\x09\x0a\x09node := self parse: 'foo\x0a\x09true ifTrue: [ 1 ]'.\x0a\x09\x0a\x09self assert: (node nodeAtPosition: 2@7) selector equals: 'ifTrue:'.\x0a\x09\x0a\x09node := self parse: 'foo\x0a\x09self foo; bar; baz'.\x0a\x09\x0a\x09self assert: (node nodeAtPosition: 2@8) selector equals: 'foo'",
-messageSends: ["parse:", "assert:equals:", "source", "nodeAtPosition:", "@", "selector"],
+source: "testNodeAtPosition\x0a\x09| node |\x0a\x09\x0a\x09node := self parse: 'yourself\x0a\x09^ self'.\x0a\x09\x0a\x09self assert: (node navigationNodeAt: 2@4 ifAbsent: [ nil ]) source equals: 'self'.\x0a\x09\x0a\x09node := self parse: 'foo\x0a\x09true ifTrue: [ 1 ]'.\x0a\x09\x0a\x09self assert: (node navigationNodeAt: 2@7 ifAbsent: [ nil ]) selector equals: 'ifTrue:'.\x0a\x09\x0a\x09node := self parse: 'foo\x0a\x09self foo; bar; baz'.\x0a\x09\x0a\x09self assert: (node navigationNodeAt: 2@8 ifAbsent: [ nil ]) selector equals: 'foo'",
+messageSends: ["parse:", "assert:equals:", "source", "navigationNodeAt:ifAbsent:", "@", "selector"],
 referencedClasses: []
 referencedClasses: []
 }),
 }),
 globals.ASTPositionTest);
 globals.ASTPositionTest);

+ 3 - 3
src/Compiler-Tests.st

@@ -114,17 +114,17 @@ testNodeAtPosition
 	node := self parse: 'yourself
 	node := self parse: 'yourself
 	^ self'.
 	^ self'.
 	
 	
-	self assert: (node nodeAtPosition: 2@4) source equals: 'self'.
+	self assert: (node navigationNodeAt: 2@4 ifAbsent: [ nil ]) source equals: 'self'.
 	
 	
 	node := self parse: 'foo
 	node := self parse: 'foo
 	true ifTrue: [ 1 ]'.
 	true ifTrue: [ 1 ]'.
 	
 	
-	self assert: (node nodeAtPosition: 2@7) selector equals: 'ifTrue:'.
+	self assert: (node navigationNodeAt: 2@7 ifAbsent: [ nil ]) selector equals: 'ifTrue:'.
 	
 	
 	node := self parse: 'foo
 	node := self parse: 'foo
 	self foo; bar; baz'.
 	self foo; bar; baz'.
 	
 	
-	self assert: (node nodeAtPosition: 2@8) selector equals: 'foo'
+	self assert: (node navigationNodeAt: 2@8 ifAbsent: [ nil ]) selector equals: 'foo'
 ! !
 ! !
 
 
 ASTParsingTest subclass: #CodeGeneratorTest
 ASTParsingTest subclass: #CodeGeneratorTest

+ 8 - 13
src/Helios-Workspace.js

@@ -653,13 +653,12 @@ smalltalk.addMethod(
 smalltalk.method({
 smalltalk.method({
 selector: "onCtrlClickAt:",
 selector: "onCtrlClickAt:",
 protocol: 'reactions',
 protocol: 'reactions',
-fn: function (aPosition){
+fn: function (aPoint){
 var self=this;
 var self=this;
 var ast,node;
 var ast,node;
 function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
 function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
 function $Error(){return globals.Error||(typeof Error=="undefined"?nil:Error)}
 function $Error(){return globals.Error||(typeof Error=="undefined"?nil:Error)}
 return smalltalk.withContext(function($ctx1) { 
 return smalltalk.withContext(function($ctx1) { 
-var $1;
 var $early={};
 var $early={};
 try {
 try {
 ast=_st((function(){
 ast=_st((function(){
@@ -668,20 +667,16 @@ return _st($Smalltalk())._parse_(_st(self._editor())._getValue());
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}))._on_do_($Error(),(function(error){
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}))._on_do_($Error(),(function(error){
 throw $early=[self];
 throw $early=[self];
 }));
 }));
-node=_st(ast)._nodeAtPosition_(aPosition);
-$1=node;
-if(($receiver = $1) == nil || $receiver == null){
-return self;
-} else {
-$1;
-};
+node=_st(ast)._navigationNodeAt_ifAbsent_(aPoint,(function(){
+throw $early=[nil];
+}));
 self._navigateTo_(_st(node)._navigationLink());
 self._navigateTo_(_st(node)._navigationLink());
 return self}
 return self}
 catch(e) {if(e===$early)return e[0]; throw e}
 catch(e) {if(e===$early)return e[0]; throw e}
-}, function($ctx1) {$ctx1.fill(self,"onCtrlClickAt:",{aPosition:aPosition,ast:ast,node:node},globals.HLCodeWidget)})},
-args: ["aPosition"],
-source: "onCtrlClickAt: aPosition\x0a\x09| ast node |\x0a\x09\x0a\x09ast := [ Smalltalk parse: self editor getValue ] \x0a\x09\x09on: Error \x0a\x09\x09do: [ :error | ^ self ].\x0a\x09\x0a\x09node := (ast nodeAtPosition: aPosition).\x0a\x09node ifNil: [ ^ self ].\x0a\x09\x0a\x09self navigateTo: node navigationLink",
-messageSends: ["on:do:", "parse:", "getValue", "editor", "nodeAtPosition:", "ifNil:", "navigateTo:", "navigationLink"],
+}, function($ctx1) {$ctx1.fill(self,"onCtrlClickAt:",{aPoint:aPoint,ast:ast,node:node},globals.HLCodeWidget)})},
+args: ["aPoint"],
+source: "onCtrlClickAt: aPoint\x0a\x09| ast node |\x0a\x09\x0a\x09ast := [ Smalltalk parse: self editor getValue ] \x0a\x09\x09on: Error \x0a\x09\x09do: [ :error | ^ self ].\x0a\x09\x0a\x09node := ast \x0a\x09\x09navigationNodeAt: aPoint \x0a\x09\x09ifAbsent: [ ^ nil ].\x0a\x09\x09\x0a\x09self navigateTo: node navigationLink",
+messageSends: ["on:do:", "parse:", "getValue", "editor", "navigationNodeAt:ifAbsent:", "navigateTo:", "navigationLink"],
 referencedClasses: ["Smalltalk", "Error"]
 referencedClasses: ["Smalltalk", "Error"]
 }),
 }),
 globals.HLCodeWidget);
 globals.HLCodeWidget);

+ 5 - 4
src/Helios-Workspace.st

@@ -266,16 +266,17 @@ onChange
 	self updateState
 	self updateState
 !
 !
 
 
-onCtrlClickAt: aPosition
+onCtrlClickAt: aPoint
 	| ast node |
 	| ast node |
 	
 	
 	ast := [ Smalltalk parse: self editor getValue ] 
 	ast := [ Smalltalk parse: self editor getValue ] 
 		on: Error 
 		on: Error 
 		do: [ :error | ^ self ].
 		do: [ :error | ^ self ].
 	
 	
-	node := (ast nodeAtPosition: aPosition).
-	node ifNil: [ ^ self ].
-	
+	node := ast 
+		navigationNodeAt: aPoint 
+		ifAbsent: [ ^ nil ].
+		
 	self navigateTo: node navigationLink
 	self navigateTo: node navigationLink
 !
 !