CafeKrem / PTL

Pharo transformation Language is a transformation model language like ALT tefkat.
MIT License
1 stars 1 forks source link

[Pattern matching] add repetition #16

Open CafeKrem opened 3 years ago

CafeKrem commented 3 years ago

we should a way to express something like this :

pattern := {String repeat: 3 . 100 } asMatcher.
self assert: (pattern match: { '1' . '2' . '3' . 100}) isMatch.
self deny:  (pattern match: { '1' . '2' . 100}) isMatch.
self assert:  (pattern match: { '1' . '2' . '3' . 100 . 100}) isMatch.
self deny:  (pattern match: { 100}) isMatch

maybe use Interval

pattern := {String repeat: #(1 3) . 100} asMatcher "repeat between 1 and 3 times"
self assert: (pattern match: { '1' . '2' . '3' . 100}) isMatch.
self assert:  (pattern match: { '1' . '2' . 100}) isMatch.
self assert:  (pattern match: { '1' . '2' . '3' . 100 . 100}) isMatch.
self deny:  (pattern match: { 100}) isMatch.
self assert: (pattern match: {'1' . 100 }) isMatch
CafeKrem commented 3 years ago

an other case

pattern := { #'@a' . #'@b' } repeat: 2  

is equals to ?

pattern := { #'@a' . #'@b'. #'@a' . #'@b' } 

or

pattern := { #'@a' . #'@b'. #'@a'1 . #'@b1' } 

is it an option ?