From 443535820e9e66deb007730070833ce159b2364a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Corr=C3=AAa=20de=20Oliveira?= Date: Wed, 28 Aug 2024 15:55:26 +0100 Subject: [PATCH] feat(pattern): start writting partner --- lib/Pattern.rakumod | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/Pattern.rakumod b/lib/Pattern.rakumod index 53dcaee..4039af2 100644 --- a/lib/Pattern.rakumod +++ b/lib/Pattern.rakumod @@ -1,4 +1,4 @@ -my class Step is Callable { +my class Step { has Numeric $.min = 1; has Numeric $.max = 1; has Callable @.steps; @@ -15,7 +15,30 @@ my class Step is Callable { } } -class Pattern is Step is Method { - has Str $.source; +my class Or { + has Callable @.options; + multi method add-option(&opt) { + @!options.push: &opt + } + + multi method add-option(@opts) { + @!options.push: $_ for @opts + } + + method CALL-ME(\match, |c) { + # FIXME: what happens if there is no rule as first step? + for @!options { + .(match, |c) + } + } +} + +class Pattern is Method { + has Str $.source; + has Step $.steps handles .= new; + + method CALL-ME(\match, |c) { + $!steps(match, |c) + } }