Christoph Thiede uploaded a new version of Regex-Core to project The Trunk:
http://source.squeak.org/trunk/Regex-Core-ct.62.mcz
==================== Summary ====================
Name: Regex-Core-ct.62
Author: ct
Time: 23 August 2021, 5:27:14.776768 pm
UUID: 3a47183c-32cd-ee44-bf87-01eab0ec2ce5
Ancestors: Regex-Core-mt.61
Fixes copying of cyclic RxmLink structures. This fixes the #testNestedQuantifiers failure from Regex-Tests-Core-ct.17.
Nevertheless, I am not sure whether this is the right solution and whether cyclic RxmLinks are actually healthy, so it might be better if someone could review this ...
=============== Diff against Regex-Core-mt.61 ===============
Item was changed:
----- Method: RxmLink>>copyUsing: (in category 'copying') -----
copyUsing: anIdentityDictionary
"Copy the receiver if it's not present in the argument dictionary, or just return the previously made copy. The rest of the object graph will be copied by #postCopyUsing:."
^anIdentityDictionary
at: self
ifAbsent: [
"It may be tempting to use #at:ifAbsentPut: instead, but the argument block must not modify the receiver, so that wouldn't work."
+ (anIdentityDictionary
- anIdentityDictionary
at: self
+ put: self shallowCopy)
- put: (self shallowCopy
postCopyUsing: anIdentityDictionary;
+ yourself ]!
- yourself) ]!
Christoph Thiede uploaded a new version of Regex-Core to project The Trunk:
http://source.squeak.org/trunk/Regex-Core-ct.69.mcz
==================== Summary ====================
Name: Regex-Core-ct.69
Author: ct
Time: 23 August 2021, 10:32:19.392748 pm
UUID: 03218e64-f6d8-7349-84be-00f61d947856
Ancestors: Regex-Core-mt.61
Adds String >> #escapeRegex to escape special characters in a string before composing it into another regex.
Usage:
':-)' matchesRegex: ':-)' escapeRegex
Supersedes Regex-Core-ct.61. Reuploaded to optimize #escapeString:. Thanks to Levente (ul) for the detailed instructions!
=============== Diff against Regex-Core-mt.61 ===============
Item was added:
+ ----- Method: RxParser class>>escapeString: (in category 'utilities') -----
+ escapeString: aString
+ "Answer a copy of aString which does not contain any unescaped characters. This is the inverse function of String >> #matchesRegex:.
+ NB: Basically, we could simply escape every single character in the string, but this would not produce human-readable outputs."
+
+ | special lastIndex nextIndex |
+ special := self specialCharacters.
+ nextIndex := aString indexOfAnyOf: special startingAt: (lastIndex := 1) ifAbsent: [^ aString].
+ ^ String new: aString size * 11 // 10 "+10%" streamContents: [:stream |
+ [stream
+ next: nextIndex - lastIndex putAll: aString startingAt: lastIndex;
+ nextPut: $\;
+ nextPut: (aString at: nextIndex)]
+ doWhileTrue: [(nextIndex := aString indexOfAnyOf: special startingAt: (lastIndex := nextIndex + 1)) > 0].
+ stream next: aString size - lastIndex + 1 putAll: aString startingAt: lastIndex]!
Item was added:
+ ----- Method: RxParser class>>specialCharacters (in category 'utilities') -----
+ specialCharacters
+
+ ^ '()[]*+?{}.^$:\'!
Item was added:
+ ----- Method: String>>escapeRegex (in category '*Regex-Core') -----
+ escapeRegex
+
+ ^ RxParser escapeString: self!
Christoph Thiede uploaded a new version of Regex-Core to project The Trunk:
http://source.squeak.org/trunk/Regex-Core-ct.76.mcz
==================== Summary ====================
Name: Regex-Core-ct.76
Author: ct
Time: 9 January 2022, 3:50:10.798554 am
UUID: 208ca41a-b09d-854e-b53e-83e0f004f0b4
Ancestors: Regex-Core-mt.61
Eliminates a shadowed variable warning. I have searched the entire package and did not find any other one.
=============== Diff against Regex-Core-mt.61 ===============
Item was changed:
----- Method: RxMatcher>>syntaxBranch: (in category 'double dispatch') -----
syntaxBranch: branchNode
"Double dispatch from the syntax tree.
Branch node is a link in a chain of concatenated pieces.
First build the matcher for the rest of the chain, then make
it for the current piece and hook the rest to it."
| piece branch |
piece := branchNode piece.
branch := branchNode branch ifNil: [ ^piece dispatchTo: self ].
"Optimization: glue a sequence of individual characters into a single string to match."
piece isAtomic ifTrue: [
+ | result next resultStream |
+ resultStream := (String new: 40) writeStream.
+ next := branchNode tryMergingInto: resultStream.
+ result := resultStream contents.
- | result next stream |
- stream := (String new: 40) writeStream.
- next := branchNode tryMergingInto: stream.
- result := stream contents.
result size > 1 ifTrue: [
"worth merging"
^(RxmSubstring new substring: result ignoreCase: ignoreCase)
pointTailTo: (next ifNotNil: [ next dispatchTo: self ]);
yourself ] ].
"No optimization possible or worth it, just concatenate all. "
^(piece dispatchTo: self)
pointTailTo: (branch dispatchTo: self);
yourself!