Skip to content

Commit

Permalink
NORMAL added for loop syntax and multiple setq.
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentToups committed Apr 19, 2012
1 parent 72757bc commit 871526a
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions parenlab.el
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@
"Nil is transcoded to an empty array."
(pl:insertf "[]"))

(defun-match- pl:transcode ('return)
(defun-match pl:transcode ('return)
"Return is transcoded as return."
(pl:insertf "return"))

(defun-match- pl:transcode ((or : (list :)))
(defun-match pl:transcode ((or : (list :)))
"Insert a naked :"
(pl:insertf ":"))

Expand Down Expand Up @@ -149,14 +149,30 @@
(pl:transcode form)
(pl:insertf ")"))

(defun-match pl:transcode ((list 'setq
(defun-match pl:transcode ((list (or 'setq :=)
target
value))
"Set is transcoded to assignment."
(pl:transcode target)
(pl:insertf " = ")
(pl:transcode value))

(defun pl:not-empty (l)
"True when l is a non-empty list."
(and (listp l)
(not (null l))))

(defun-match pl:transcode ((list-rest (or 'setq :=)
target
value
(p #'pl:not-empty others)))
"Set is transcoded to assignment."
(pl:transcode target)
(pl:insertf " = ")
(pl:transcode value)
(pl:insertf "; ")
(recur `(setq ,@others)))

(defun-match pl:transcode ((list 'progn form))
"Progn with a single form is the form itself."
(pl:transcode form))
Expand Down Expand Up @@ -348,6 +364,25 @@ regular, non-functional if statement."
(pl:insertf "end\n")
(indent-region start (point))))

(defun-match pl:transcode ((list-rest 'for (list (p #'symbolp index)
(p #'symbolp value))
expr body))
"Expand a for loop with index expression."
(let ((start (point))
(expr-value (gensym "for-loop-value-")))
(pl:transcode `(setq ,expr-value ,expr))
(pl:insertf ";\n")
(pl:insertf "for ")
(pl:transcode index)
(pl:insertf " = ")
(pl:transcode `(: 1 (length ,expr-value)))
(pl:insertf "\n")
(pl:transcode `(setq ,value (,expr-value ,index)))
(pl:insertf "\n")
(pl:transcode-sequence body)
(pl:insertf "end\n")
(indent-region start (point))))

(defun-match pl:transcode ((list 'literally string))
"Allows you to insert code directly into the output stream."
(pl:insertf string))
Expand Down

0 comments on commit 871526a

Please sign in to comment.