From 265f867a718d4bc79d0cd4bce42b04edea08ee88 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Sat, 18 May 2024 18:22:49 -0400 Subject: [PATCH] fix string interpolation --- janet/interpreter.janet | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/janet/interpreter.janet b/janet/interpreter.janet index 1e88f63..5bb3ac1 100644 --- a/janet/interpreter.janet +++ b/janet/interpreter.janet @@ -236,11 +236,14 @@ (set stringify stringify*) +(defn- stringish? [x] (or (string? x) (buffer? x))) + (defn- interpolated [ast ctx] (def terms (ast :data)) + (each term terms (pp term)) (def interpolations (map (fn [x] - (if (string? x) x (stringify (interpret x ctx)))) + (if (stringish? x) x (stringify (interpret x ctx)))) terms)) (string/join interpolations)) @@ -393,28 +396,16 @@ (when (has-errors? parsed) (break (parsed :errors))) (def validated (v/valid parsed)) (when (has-errors? validated) (break (validated :errors))) - # (interpret (parsed :ast) @{}) - (try (interpret (parsed :ast) @{}) - ([e] (print "Ludus panicked!: " - (if (struct? e) (error (e :msg)) (error e))))) + (interpret (parsed :ast) @{}) + # (try (interpret (parsed :ast) @{}) + # ([e] (print "Ludus panicked!: " + # (if (struct? e) (error (e :msg)) (error e))))) ) (do (set source ` -match "foooooo" with { - "f{foo}{bar}{baz}" -> (foo, bar, baz) - _ -> :nope -} +let verb = "love" +"{verb}" `) (run) ) - -(def g @{:0 "f" :1 '(<- (to :2)) :2 "o" :3 -1 - :main '(* :0 :1 :2 :3)}) - -(def f '{:0 "b" :1 (<- (to :2)) :2 (* "" -1) - :main (* :0 :1 :2)}) - -(def h ~(* (<- (to "a")) "a" -1)) - -(peg/match f "barrr")