diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-04-01 20:08:36 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-04-01 20:08:36 -0400 |
| commit | dd4c25e6b768e39fbcd437e44f80dc958e1f5869 (patch) | |
| tree | 013c42119866c574980fae7a3323d9ace3eafc0a /examples/patterns/patterns.tm | |
| parent | 57ff9fdfc6b557211052aa275bfcca3e2316a0c6 (diff) | |
Update patterns API and docs
Diffstat (limited to 'examples/patterns/patterns.tm')
| -rw-r--r-- | examples/patterns/patterns.tm | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/examples/patterns/patterns.tm b/examples/patterns/patterns.tm index 8ca5faa2..6afcdc25 100644 --- a/examples/patterns/patterns.tm +++ b/examples/patterns/patterns.tm @@ -10,8 +10,11 @@ lang Pat: return Pat.from_text("$n") extend Text: - func matches_pattern(text:Text, pattern:Pat -> [Text]?): - return inline C : [Text]? { Pattern$matches(_$text, _$pattern); } + func matches_pattern(text:Text, pattern:Pat -> Bool): + return inline C : Bool { Pattern$matches(_$text, _$pattern); } + + func pattern_captures(text:Text, pattern:Pat -> [Text]?): + return inline C : [Text]? { Pattern$captures(_$text, _$pattern); } func replace_pattern(text:Text, pattern:Pat, replacement:Text, backref="@", recursive=yes -> Text): return inline C : Text { Pattern$replace(_$text, _$pattern, _$replacement, _$backref, _$recursive); } @@ -42,11 +45,3 @@ extend Text: func trim_pattern(text:Text, pattern=$Pat"{space}", left=yes, right=yes -> Text): return inline C : Text { Pattern$trim(_$text, _$pattern, _$left, _$right); } - -func main(): - >> "hello world":replace_pattern($Pat/{id}/, "XXX") - >> "hello world":find_patterns($Pat/l/) - - for m in "hello one two three":by_pattern($Pat/{id}/): - >> m - |
