From aba77569ac147166bc73415ad65798796f48680a Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Sat, 15 Jun 2024 11:58:30 -0400 Subject: [PATCH] some pure-ludus string manipulation testing --- src/ludus.janet | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/ludus.janet b/src/ludus.janet index fad4bfb..26df90a 100644 --- a/src/ludus.janet +++ b/src/ludus.janet @@ -49,15 +49,37 @@ (set (out :draw) (post :draw)) (-> out j/encode string)) -(comment -# (do +# (comment +(do (def source ` -match :foo with { - :bar -> :baz - :baz -> :quux - "thing {foo}" -> "worste" - 42 -> 23 +fn strip_punctuation { + ("{x},{y}") -> strip_punctuation ("{x}{y}") + ("{x}.{y}") -> strip_punctuation ("{x}{y}") + ("{x};{y}") -> strip_punctuation ("{x}{y}") + ("{x}:{y}") -> strip_punctuation ("{x}{y}") + ("{x}?{y}") -> strip_punctuation ("{x}{y}") + ("{x}!{y}") -> strip_punctuation ("{x}{y}") + (x) -> x } + +fn trim_left { + (" {x}") -> trim_left ("{x}") + ("\n{x}") -> trim_left ("{x}") + ("\t{x}") -> trim_left ("{x}") + (x) -> x +} + +fn trim_right { + ("{x} ") -> trim_right ("{x}") + ("{x}\n") -> trim_right ("{x}") + ("{x}\t") -> trim_right ("{x}") + (x) -> x +} + +fn trim (x) -> do x > trim_left > trim_right + +trim_left (" + foo") `) (def out (-> source ludus