The Trunk: Regex-Core-ul.41.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Regex-Core-ul.41.mcz

commits-2
Levente Uzonyi uploaded a new version of Regex-Core to project The Trunk:
http://source.squeak.org/trunk/Regex-Core-ul.41.mcz

==================== Summary ====================

Name: Regex-Core-ul.41
Author: ul
Time: 23 August 2015, 2:03:57.377 am
UUID: b2a59557-016e-41f5-86ab-3dcd33ce0954
Ancestors: Regex-Core-ul.40

Got rid of the reversal of the OrderedCollections in RxMatcher's markerPositions.

=============== Diff against Regex-Core-ul.40 ===============

Item was changed:
  ----- Method: RxMatcher>>copyStream:to:replacingMatchesWith: (in category 'match enumeration') -----
  copyStream: aStream to: writeStream replacingMatchesWith: aString
  "Copy the contents of <aStream> on the <writeStream>, except for the matches. Replace each match with <aString>."
 
  | searchStart matchStart matchEnd |
  stream := aStream.
  oldMarkerPositions := markerPositions := nil.
  [searchStart := aStream position.
  self proceedSearchingStream: aStream] whileTrue:
+ [matchStart := (self subBeginning: 1) last.
+ matchEnd := (self subEnd: 1) last.
- [matchStart := (self subBeginning: 1) first.
- matchEnd := (self subEnd: 1) first.
  aStream position: searchStart.
  searchStart to: matchStart - 1 do:
  [:ignoredPos | writeStream nextPut: aStream next].
  writeStream nextPutAll: aString.
  aStream position: matchEnd.
  "Be extra careful about successful matches which consume no input.
  After those, make sure to advance or finish if already at end."
  matchEnd = searchStart ifTrue:
  [aStream atEnd
  ifTrue: [^self "rest after end of whileTrue: block is a no-op if atEnd"]
  ifFalse: [writeStream nextPut: aStream next]]].
  aStream position: searchStart.
  [aStream atEnd] whileFalse: [writeStream nextPut: aStream next]!

Item was changed:
  ----- Method: RxMatcher>>copyStream:to:translatingMatchesUsing: (in category 'match enumeration') -----
  copyStream: aStream to: writeStream translatingMatchesUsing: aBlock
  "Copy the contents of <aStream> on the <writeStream>, except for the matches. For each match, evaluate <aBlock> passing the matched substring as the argument.  Expect the block to answer a String, and write the answer to <writeStream> in place of the match."
 
  | searchStart matchStart matchEnd match |
  stream := aStream.
  oldMarkerPositions := markerPositions := nil.
  [searchStart := aStream position.
  self proceedSearchingStream: aStream] whileTrue:
+ [matchStart := (self subBeginning: 1) last.
+ matchEnd := (self subEnd: 1) last.
- [matchStart := (self subBeginning: 1) first.
- matchEnd := (self subEnd: 1) first.
  aStream position: searchStart.
  searchStart to: matchStart - 1 do:
  [:ignoredPos | writeStream nextPut: aStream next].
  match := (String new: matchEnd - matchStart + 1) writeStream.
  matchStart to: matchEnd - 1 do:
  [:ignoredPos | match nextPut: aStream next].
  writeStream nextPutAll: (aBlock value: match contents).
  "Be extra careful about successful matches which consume no input.
  After those, make sure to advance or finish if already at end."
  matchEnd = searchStart ifTrue:
  [aStream atEnd
  ifTrue: [^self "rest after end of whileTrue: block is a no-op if atEnd"]
  ifFalse: [writeStream nextPut: aStream next]]].
  aStream position: searchStart.
  [aStream atEnd] whileFalse: [writeStream nextPut: aStream next]!

Item was changed:
  ----- Method: RxMatcher>>markerPositionAt:add: (in category 'privileged') -----
  markerPositionAt: anIndex add: position
  "Remember position of another instance of the given marker."
 
+ (markerPositions at: anIndex) addLast: position!
- (markerPositions at: anIndex) addFirst: position!

Item was changed:
  ----- Method: RxMatcher>>subexpressions: (in category 'accessing') -----
  subexpressions: subIndex
  "Answer an array of all matches of the subexpression at the given index.
  The answer is always an array; it is empty if there are no matches."
 
  | originalPosition startPositions stopPositions reply |
  originalPosition := stream position.
  startPositions := self subBeginning: subIndex.
  stopPositions := self subEnd: subIndex.
  (startPositions isEmpty or: [stopPositions isEmpty]) ifTrue: [^Array new].
  reply := Array new: startPositions size.
  1 to: reply size do: [ :index |
  | start stop |
  start := startPositions at: index.
  stop := stopPositions at: index.
  stream position: start.
+ reply at: reply size - index + 1 put: (stream next: stop - start) ].
- reply at: index put: (stream next: stop - start) ].
  stream position: originalPosition.
  ^reply!

Item was changed:
  ----- Method: RxMatcher>>tryMatch (in category 'private') -----
  tryMatch
  "Match thyself against the current stream."
 
  | newMarkerPositions |
  newMarkerPositions := oldMarkerPositions.
  oldMarkerPositions := markerPositions.
  markerPositions := newMarkerPositions.
  markerPositions
  ifNil: [
  markerPositions := Array new: markerCount.
  1 to: markerCount do: [ :i |
+ "There are usually 0 or 1 objects to store."
+ markerPositions at: i put: (OrderedCollection new: 2) ] ]
- | collection |
- collection := OrderedCollection new: 2. "There are usually 0 or 1 objects to store."
- collection resetTo: 3. "We'll add elements to the beginning, so make room there."
- markerPositions at: i put: collection ] ]
  ifNotNil: [
  1 to: markerCount do: [ :i |
+ (markerPositions at: i) resetTo: 1 ] ].
- | collection |
- collection := markerPositions at: i.
- collection resetTo: collection capacity + 1 ] ].
  lastResult := startOptimizer
  ifNil: [ matcher matchAgainst: self]
  ifNotNil: [ (startOptimizer canStartMatch: stream peek in: self) and: [ matcher matchAgainst: self ] ].
  "check for duplicates"
  lastResult ifFalse: [ ^false ].
  oldMarkerPositions ifNil: [ ^true ].
  (oldMarkerPositions hasEqualElements: markerPositions) ifFalse: [ ^true ].
+ "this is a duplicate match"
- "this is a duplicate"
  ^ lastResult := false!