Hi all,
just a small goody for all those interested: It turns out that, thanks to the great polymorphy in Squeak, regular expressions (as implemented in the Regex package of Trunk originally developed by Vassili Bykov) are not limited to collections that are actually strings. Here is a short counter-example:
To make the example work, only a small number of hard-coded class names have to be adjusted, see the attached changeset, it's really tiny.
Here's another example:
This also allows us to style texts using regexes:
However, if the original text attributes should be preserved, we would need to hack TextStream >> #withAttributes:do: into the copy methods, analogously to Text >> #format:. I guess this limitation could only be resolved by redesigning Text as a collection of TextCharacters, which might be very slow.
Nevertheless, I think this insight opens great possibilities for other forms of parsing. Maybe one could also process binary streams using polymorphic regex patterns, or even process sequences of domain-specific objects. Because RxsPredicate is so generic, you could also simply define custom predicates for these objects. Later, the next step could be adding support for nested collections (RxsNested?) so that you could parse entire trees of objects ... Ah, so beautiful dreams :-)
Best, Christoph regex-polymorphy.2.cs (5K) Download Attachment
Carpe Squeak!
|
Woohoo, nested regular expressions are even easier than I thought!
I'll share my changeset upon request. This is really exciting stuff.
Christoph
Von: Squeak-dev <[hidden email]> im Auftrag von Thiede, Christoph
Gesendet: Mittwoch, 7. April 2021 19:37 Uhr An: Squeak Dev Betreff: [squeak-dev] Regular Expressions are not limited to Strings Hi all,
just a small goody for all those interested: It turns out that, thanks to the great polymorphy in Squeak, regular expressions (as implemented in the Regex package of Trunk originally developed by Vassili Bykov) are not limited to collections that are actually strings. Here is a short counter-example:
To make the example work, only a small number of hard-coded class names have to be adjusted, see the attached changeset, it's really tiny.
Here's another example:
This also allows us to style texts using regexes:
However, if the original text attributes should be preserved, we would need to hack TextStream >> #withAttributes:do: into the copy methods, analogously to Text >> #format:. I guess this limitation could only be resolved by redesigning Text as a collection of TextCharacters, which might be very slow.
Nevertheless, I think this insight opens great possibilities for other forms of parsing. Maybe one could also process binary streams using polymorphic regex patterns, or even process sequences of domain-specific objects. Because RxsPredicate is so generic, you could also simply define custom predicates for these objects. Later, the next step could be adding support for nested collections (RxsNested?) so that you could parse entire trees of objects ... Ah, so beautiful dreams :-)
Best, Christoph
Carpe Squeak!
|
Free forum by Nabble | Edit this page |