Explorar o código

- Removed String>>#asParser* methods
- Added SequenceableCollection>>reversed and concrete implementations in subclasses

Nicolas Petton %!s(int64=12) %!d(string=hai) anos
pai
achega
08f87c1367
Modificáronse 3 ficheiros con 92 adicións e 90 borrados
  1. 33 33
      js/Kernel.deploy.js
  2. 45 45
      js/Kernel.js
  3. 14 12
      st/Kernel.st

+ 33 - 33
js/Kernel.deploy.js

@@ -3056,6 +3056,17 @@ return self;}
 }),
 smalltalk.SequenceableCollection);
 
+smalltalk.addMethod(
+'_reversed',
+smalltalk.method({
+selector: 'reversed',
+fn: function (){
+var self=this;
+smalltalk.send(self, "_subclassResponsibility", []);
+return self;}
+}),
+smalltalk.SequenceableCollection);
+
 
 
 smalltalk.addClass('String', smalltalk.SequenceableCollection, [], 'Kernel');
@@ -3296,39 +3307,6 @@ return self;}
 }),
 smalltalk.String);
 
-smalltalk.addMethod(
-'_asParser',
-smalltalk.method({
-selector: 'asParser',
-fn: function (){
-var self=this;
-return smalltalk.send(smalltalk.send((smalltalk.PPStringParser || PPStringParser), "_new", []), "_string_", [self]);
-return self;}
-}),
-smalltalk.String);
-
-smalltalk.addMethod(
-'_asChoiceParser',
-smalltalk.method({
-selector: 'asChoiceParser',
-fn: function (){
-var self=this;
-return smalltalk.send((smalltalk.PPChoiceParser || PPChoiceParser), "_withAll_", [smalltalk.send(smalltalk.send(self, "_asArray", []), "_collect_", [(function(each){return smalltalk.send(each, "_asParser", []);})])]);
-return self;}
-}),
-smalltalk.String);
-
-smalltalk.addMethod(
-'_asCharacterParser',
-smalltalk.method({
-selector: 'asCharacterParser',
-fn: function (){
-var self=this;
-return smalltalk.send(smalltalk.send((smalltalk.PPCharacterParser || PPCharacterParser), "_new", []), "_string_", [self]);
-return self;}
-}),
-smalltalk.String);
-
 smalltalk.addMethod(
 '_errorReadOnly',
 smalltalk.method({
@@ -3624,6 +3602,17 @@ return self;
 }),
 smalltalk.String);
 
+smalltalk.addMethod(
+'_reversed',
+smalltalk.method({
+selector: 'reversed',
+fn: function (){
+var self=this;
+return self.split("").reverse().join("");
+return self;}
+}),
+smalltalk.String);
+
 
 smalltalk.addMethod(
 '_streamClass',
@@ -3948,6 +3937,17 @@ return self;}
 }),
 smalltalk.Array);
 
+smalltalk.addMethod(
+'_reversed',
+smalltalk.method({
+selector: 'reversed',
+fn: function (){
+var self=this;
+return self._copy().reverse();
+return self;}
+}),
+smalltalk.Array);
+
 
 
 smalltalk.addClass('RegularExpression', smalltalk.Object, [], 'Kernel');

+ 45 - 45
js/Kernel.js

@@ -4105,6 +4105,21 @@ referencedClasses: []
 }),
 smalltalk.SequenceableCollection);
 
+smalltalk.addMethod(
+'_reversed',
+smalltalk.method({
+selector: 'reversed',
+category: 'converting',
+fn: function (){
+var self=this;
+smalltalk.send(self, "_subclassResponsibility", []);
+return self;},
+source: unescape('reversed%0A%09self%20subclassResponsibility'),
+messageSends: ["subclassResponsibility"],
+referencedClasses: []
+}),
+smalltalk.SequenceableCollection);
+
 
 
 smalltalk.addClass('String', smalltalk.SequenceableCollection, [], 'Kernel');
@@ -4425,51 +4440,6 @@ referencedClasses: []
 }),
 smalltalk.String);
 
-smalltalk.addMethod(
-'_asParser',
-smalltalk.method({
-selector: 'asParser',
-category: 'converting',
-fn: function (){
-var self=this;
-return smalltalk.send(smalltalk.send((smalltalk.PPStringParser || PPStringParser), "_new", []), "_string_", [self]);
-return self;},
-source: unescape('asParser%0A%20%20%20%20%09%5EPPStringParser%20new%20string%3A%20self'),
-messageSends: ["string:", "new"],
-referencedClasses: [smalltalk.nil]
-}),
-smalltalk.String);
-
-smalltalk.addMethod(
-'_asChoiceParser',
-smalltalk.method({
-selector: 'asChoiceParser',
-category: 'converting',
-fn: function (){
-var self=this;
-return smalltalk.send((smalltalk.PPChoiceParser || PPChoiceParser), "_withAll_", [smalltalk.send(smalltalk.send(self, "_asArray", []), "_collect_", [(function(each){return smalltalk.send(each, "_asParser", []);})])]);
-return self;},
-source: unescape('asChoiceParser%0A%20%20%20%20%09%5EPPChoiceParser%20withAll%3A%20%28self%20asArray%20collect%3A%20%5B%3Aeach%20%7C%20each%20asParser%5D%29'),
-messageSends: ["withAll:", "collect:", "asArray", "asParser"],
-referencedClasses: [smalltalk.nil]
-}),
-smalltalk.String);
-
-smalltalk.addMethod(
-'_asCharacterParser',
-smalltalk.method({
-selector: 'asCharacterParser',
-category: 'converting',
-fn: function (){
-var self=this;
-return smalltalk.send(smalltalk.send((smalltalk.PPCharacterParser || PPCharacterParser), "_new", []), "_string_", [self]);
-return self;},
-source: unescape('asCharacterParser%0A%20%20%20%20%09%5EPPCharacterParser%20new%20string%3A%20self'),
-messageSends: ["string:", "new"],
-referencedClasses: [smalltalk.nil]
-}),
-smalltalk.String);
-
 smalltalk.addMethod(
 '_errorReadOnly',
 smalltalk.method({
@@ -4865,6 +4835,21 @@ referencedClasses: []
 }),
 smalltalk.String);
 
+smalltalk.addMethod(
+'_reversed',
+smalltalk.method({
+selector: 'reversed',
+category: 'converting',
+fn: function (){
+var self=this;
+return self.split("").reverse().join("");
+return self;},
+source: unescape('reversed%0A%09%3Creturn%20self.split%28%22%22%29.reverse%28%29.join%28%22%22%29%3E'),
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.String);
+
 
 smalltalk.addMethod(
 '_streamClass',
@@ -5293,6 +5278,21 @@ referencedClasses: []
 }),
 smalltalk.Array);
 
+smalltalk.addMethod(
+'_reversed',
+smalltalk.method({
+selector: 'reversed',
+category: 'converting',
+fn: function (){
+var self=this;
+return self._copy().reverse();
+return self;},
+source: unescape('reversed%0A%09%3Creturn%20self._copy%28%29.reverse%28%29%3E'),
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.Array);
+
 
 
 smalltalk.addClass('RegularExpression', smalltalk.Object, [], 'Kernel');

+ 14 - 12
st/Kernel.st

@@ -1446,6 +1446,12 @@ addLast: anObject
 	self add: anObject
 ! !
 
+!SequenceableCollection methodsFor: 'converting'!
+
+reversed
+	self subclassResponsibility
+! !
+
 !SequenceableCollection methodsFor: 'copying'!
 
 copyFrom: anIndex to: anotherIndex
@@ -1565,18 +1571,6 @@ asNumber
 	<return Number(self)>
 !
 
-asParser
-    	^PPStringParser new string: self
-!
-
-asChoiceParser
-    	^PPChoiceParser withAll: (self asArray collect: [:each | each asParser])
-!
-
-asCharacterParser
-    	^PPCharacterParser new string: self
-!
-
 asJSONObject
 	^self
 !
@@ -1587,6 +1581,10 @@ asLowercase
 
 asUppercase
 	<return self.toUpperCase()>
+!
+
+reversed
+	<return self.split("").reverse().join("")>
 ! !
 
 !String methodsFor: 'copying'!
@@ -1843,6 +1841,10 @@ asJavascript
 
 asJSONObject
 	^self collect: [:each | each asJSONObject]
+!
+
+reversed
+	<return self._copy().reverse()>
 ! !
 
 !Array methodsFor: 'copying'!