[squeak-dev] The Trunk: Regex-Core-ct.66.mcz
commits at source.squeak.org
commits at source.squeak.org
Wed Oct 5 18:06:22 UTC 2022
Christoph Thiede uploaded a new version of Regex-Core to project The Trunk:
http://source.squeak.org/trunk/Regex-Core-ct.66.mcz
==================== Summary ====================
Name: Regex-Core-ct.66
Author: ct
Time: 23 August 2021, 7:05:38.221768 pm
UUID: 3ede3098-6d93-0049-bd36-5dd0461903d2
Ancestors: Regex-Core-mt.61
Adds convenience selectors for accessing subexpressions (#allSubexpressions and #subexpressionRanges:). The other changes contain some minor refactorings only.
=============== Diff against Regex-Core-mt.61 ===============
Item was added:
+ ----- Method: RxMatcher>>allSubexpressions (in category 'accessing') -----
+ allSubexpressions
+
+ ^ (1 to: self subexpressionCount) collect: [:index |
+ self subexpressions: index]!
Item was changed:
----- Method: RxMatcher>>hookBranchOf:onto: (in category 'private') -----
hookBranchOf: regexNode onto: endMarker
+ "Private - Recurse down the chain of regexes starting at regexNode, compiling their branches and hooking their tails to the endMarker node."
- "Private - Recurse down the chain of regexes starting at
- regexNode, compiling their branches and hooking their tails
- to the endMarker node."
+ | next rest |
+ next := (regexNode branch dispatchTo: self)
+ pointTailTo: endMarker;
+ yourself.
+ regexNode regex ifNil: [
+ "Avoid creating a branch without an alternative."
+ ^ next].
+
+ rest := self hookBranchOf: regexNode regex onto: endMarker.
+ ^ RxmBranch new
+ next: next;
+ alternative: rest;
+ yourself!
- ^regexNode regex
- ifNil: [ "Avoid creating a branch without an alternative."
- ^(regexNode branch dispatchTo: self)
- pointTailTo: endMarker;
- yourself ]
- ifNotNil: [ :regex |
- | rest |
- rest := self hookBranchOf: regex onto: endMarker.
- ^RxmBranch new
- next: ((regexNode branch dispatchTo: self)
- pointTailTo: endMarker;
- yourself);
- alternative: rest;
- yourself ]
- !
Item was changed:
----- Method: RxMatcher>>subBeginning: (in category 'accessing') -----
subBeginning: subIndex
subIndex = 1 ifTrue: [
+ "beginning of root node"
+ ^ (markerPositions at: 1)
+ ifNil: [#()]
+ ifNotNil: [:mp | {mp}] ].
+
+ ^ markerPositions at: subIndex * 2 - 1!
- (markerPositions at: 1)
- ifNil: [ ^#()]
- ifNotNil: [ :mp | ^{ mp } ] ].
- ^markerPositions at: subIndex * 2 - 1!
Item was changed:
----- Method: RxMatcher>>subEnd: (in category 'accessing') -----
subEnd: subIndex
subIndex = 1 ifTrue: [
+ "end of root node"
+ ^ (markerPositions at: 2)
+ ifNil: [#()]
+ ifNotNil: [:mp | {mp}] ].
+
+ ^ markerPositions at: subIndex * 2!
- (markerPositions at: 2)
- ifNil: [ ^#()]
- ifNotNil: [ :mp | ^{ mp } ] ].
- ^markerPositions at: subIndex * 2!
Item was changed:
----- Method: RxMatcher>>subexpression: (in category 'accessing') -----
subexpression: subIndex
"Answer a string that matched the subexpression at the given index.
If there are multiple matches, answer the last one.
If there are no matches, answer nil.
(NB: it used to answer an empty string but I think nil makes more sense)."
+ ^ (self subexpressions: subIndex)
+ ifNotEmpty: [:expressions | expressions last]
+ ifEmpty: [nil]!
- | matches |
- matches := self subexpressions: subIndex.
- ^matches isEmpty ifTrue: [nil] ifFalse: [matches last]!
Item was added:
+ ----- Method: RxMatcher>>subexpressionRanges: (in category 'accessing') -----
+ subexpressionRanges: subIndex
+ "Answer an array of all match ranges of the subexpression at the given index."
+
+ ^ (self subBeginning: subIndex)
+ with: (self subEnd: subIndex)
+ collect: [:start :stop | start to: stop - 1]!
More information about the Squeak-dev
mailing list
|