From d40d7a5ee1feb2915e851b908922e56d42e6c35b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingy=20d=C3=B6t=20Net?= Date: Wed, 19 Jun 2024 11:59:09 -0400 Subject: [PATCH] core: Add support for .? debugging --- core/src/yamlscript/re.clj | 1 + core/src/yamlscript/ysreader.clj | 14 +++++++++++--- core/test/compiler.yaml | 5 ++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/core/src/yamlscript/re.clj b/core/src/yamlscript/re.clj index 531931d8..3f28a1db 100644 --- a/core/src/yamlscript/re.clj +++ b/core/src/yamlscript/re.clj @@ -49,6 +49,7 @@ )") (def spec #"(?:~@|[~@`^])") ; Special token (def quot #"(?:\\')") ; Quote token +(def dotd #"(?:\.\?)") ; Dot debugging with .? (def dotn #"(?:\.-?\d+)") ; Dot operator followed by number (def dots (re #"(?:\.\w+(?:_\w+)+)$tend")) ; Dot operator word with _ allowed (def mnum #"(?:[-+]?\d[-+/*%.:\w]+)") ; Maybe Number token diff --git a/core/src/yamlscript/ysreader.clj b/core/src/yamlscript/ysreader.clj index 507bc076..6c6d99b1 100644 --- a/core/src/yamlscript/ysreader.clj +++ b/core/src/yamlscript/ysreader.clj @@ -47,6 +47,9 @@ (defn is-dot-sym? [token] (re-matches re/dots (str token))) +(defn is-dot-dbg? [token] + (re-matches re/dotd (str token))) + (defn is-operator? [token] (let [t (str token)] (and (re-matches re/osym t) @@ -116,6 +119,7 @@ $narg | # Numbered argument token $dotn | # Dot operator followed by number $dots | # Dot operator word with _ allowed + $dotd | # Dot debugging with .? $osym | # Operator symbol token $anon | # Anonymous fn start token $dstr | # String token @@ -311,6 +315,8 @@ (is-bad-number? token) (die "Invalid number: " token) (is-integer? token) [(Int token) tokens] (is-float? token) [(Flt token) tokens] + (is-dot-dbg? token) (let [tokens (conj tokens ")" "DBG(" ".")] + [nil tokens]) (is-dot-num? token) (let [tokens (cons (subs token 1) tokens)] [(Sym ".") tokens]) (is-dot-sym? token) (let [tokens (cons (Sym (subs token 1)) tokens)] @@ -350,7 +356,8 @@ [token tokens sym] (if (is-symbol-paren? token) (let [sym (subs token 0 (-> token count dec)) - sym (str/replace sym #"::" ".")] + sym (str/replace sym #"::" ".") + sym (if (= "DBG" sym) "_DBG" sym)] ["(" (cons "(" (rest tokens)) (Sym sym)]) [token tokens nil])] (case token @@ -364,8 +371,9 @@ (loop [tokens tokens forms []] (if (seq tokens) - (let [[form tokens] (read-form tokens)] - (recur tokens (conj forms form))) + (let [[form tokens] (read-form tokens) + forms (if form (conj forms form) forms)] + (recur tokens forms)) forms))) (defn read-string [string] diff --git a/core/test/compiler.yaml b/core/test/compiler.yaml index a98052cd..addbb424 100644 --- a/core/test/compiler.yaml +++ b/core/test/compiler.yaml @@ -1075,7 +1075,6 @@ - name: Support .? debugging operator yamlscript: | !yamlscript/v0 - =>: foo.? + =>: foo.?.bar clojure: | - (__ foo (list P)) - SKIP: true + (__ foo (list _DBG) 'bar)