Skip to content

Commit

Permalink
core: Add support for .? debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
ingydotnet committed Jun 19, 2024
1 parent a60388d commit d40d7a5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions core/src/yamlscript/re.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions core/src/yamlscript/ysreader.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand Down
5 changes: 2 additions & 3 deletions core/test/compiler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,6 @@
- name: Support .? debugging operator
yamlscript: |
!yamlscript/v0
=>: foo.?
=>: foo.?.bar
clojure: |
(__ foo (list P))
SKIP: true
(__ foo (list _DBG) 'bar)

0 comments on commit d40d7a5

Please sign in to comment.