Code formatter
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
Code formatter
I'm going to try to write a code formatter script - something that tidies up the layout of my newlisp scripts. Before I get started, has anyone done anything similar before? Are there algorithms and conventions for code layout that I could borrow or refer to?
I never use code cleaner because they never do what i want, actualy
the code writer is the best cleaner there is ;-)
I actualy never had troubles reading other newlisp code the use of () if indeed
a personal touch ... Cleaning out ;; [text]..etc.. is of no use i think..
What you could do though is follow the way the newlispDoc handles code..
A kind of configuration option for the user.. but then again..will I use it?
My Personal favorite would be a newlisp "Profiler", something that hints
on slow functions or wrong loops...
But then again, I always walk out of line.. ;-)
the code writer is the best cleaner there is ;-)
I actualy never had troubles reading other newlisp code the use of () if indeed
a personal touch ... Cleaning out ;; [text]..etc.. is of no use i think..
What you could do though is follow the way the newlispDoc handles code..
A kind of configuration option for the user.. but then again..will I use it?
My Personal favorite would be a newlisp "Profiler", something that hints
on slow functions or wrong loops...
But then again, I always walk out of line.. ;-)
-- (define? (Cornflakes))
There is one use for code cleaner -- it alarms you when your own assumptions about code structure (based on indentation) differs from lisp one's (based on parentheses). Yes, I have fallen in this trap!newdep wrote:I never use code cleaner because they never do what i want, actualy the code writer is the best cleaner there is ;-)
With newLISP you can grow your lists from the right side!
Hi, Cormullion!
Check http://en.feautec.pp.ru/store/newlisp-edit against two libs that are loaded from en.feautec.pp.ru and the call to INDENT:indent
You can also check it in action by running it ;-)
Check http://en.feautec.pp.ru/store/newlisp-edit against two libs that are loaded from en.feautec.pp.ru and the call to INDENT:indent
You can also check it in action by running it ;-)
WBR, Dmi
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
A small brainteaser that's got me stumped. Given this code:
How do you get the output to be "\n"? In other words, how to stop the backslashes working, if you're unable to change the incoming string...?
The code formatter is working pretty well, but it's tripping up over these. For example, this code (by Lutz):
is output by my formatter like this:
which probably still works, but I want to suppress the backslash expansion (without changing the original code..)
Code: Select all
(set 't "\n"
'result {})
(if (= t "\n")
(push (string t) result -1))
(println result)
The code formatter is working pretty well, but it's tripping up over these. For example, this code (by Lutz):
Code: Select all
(define (confirm-request conf)
(and
(net-receive socket 'recvbuff 256 "\r\n")
(if debug-flag (println recvbuff) true)
(starts-with recvbuff conf)))
(define (net-send-get-result str conf)
(set 'send-str (append str "\r\n"))
(if debug-flag (println "sent: " send-str))
(net-send socket 'send-str)
(if conf (confirm-request conf) true))
Code: Select all
(define (confirm-request conf)
(and
(net-receive socket 'recvbuff 256 "
" )
(if debug-flag
(println recvbuff) true)
(starts-with recvbuff conf)))
(define (net-send-get-result str conf)
(set 'send-str
(append str "
" ))
(if debug-flag
(println "sent: " send-str))
(net-send socket 'send-str)
(if conf
(confirm-request conf) true))
Hmmm... Why do U unable to change incoming string?
In my parser all code is stripped down into a list of lines, and is reassembled after indenting...
The string parsing is done char-by-char with state machine.
In my parser all code is stripped down into a list of lines, and is reassembled after indenting...
Code: Select all
(load "http://en.feautec.pp.ru/store/libs/funlib.lsp")
(load "http://en.feautec.pp.ru/store/indent.lsp")
(set 's (parse (read-file (main-args 2)) "\n"))
(println (join (INDENT:indent s) "\n"))
(exit)
WBR, Dmi
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
Ah yes - I found this in your indent.lsp
I think that's the way! I love all those backslashes.... :\
Thanks!
Code: Select all
(define (string-value s)
(context CON:cur-ctx)
(if (string? INDENT:s)
(append "\""
(dolist (INDENT:l '(("\\" "\\\\") ("\"" "\\\"") ("\n" "\\n")
("\t" "\\t")))
(set 's (replace (INDENT:l 0) INDENT:s (INDENT:l 1))))
"\"")
(string INDENT:s)))
Thanks!