Would it be possible to get a command fnparse?
(fnparse "Lsp_Source_String")
which would use the internal newlisp-parser to generate a list of all function-names (without duplicates) used in "Lsp_Source_String" without any evaluating.
Would return something like this:
("set" "define" .... .... "MyFn" "foo")
Background: To be able to check a Lsp-source before loading, that it does not contain malicious, bad Lisp-code. So a app can store a Lisp-Data-Table and can have a Load-Routine which is not a security hole for bad code. Using the internal parser should provide the speed.
Any ideas?
fnparse to get all used functions
fnparse to get all used functions
Hans-Peter
The internal newlisp parser can be easy exported from newLisp's source code to newlisp's language function (I have this... but better ask Lutz ;-)
It can be used to read s-expression from string into a list.
Next, protecting is a good feature, but it must be issued at run-time, because of 'sym', 'eval', 'fn' etc., without which the lisp code will be poor.
So, this feature must be included in evaluator, as referencing to complete list of allowed symbols for evaluate and for set. No other way will give you a safety.
The bad news is that with dynamic scoping the potential hackers will be glad much either ;-)
It can be used to read s-expression from string into a list.
Next, protecting is a good feature, but it must be issued at run-time, because of 'sym', 'eval', 'fn' etc., without which the lisp code will be poor.
So, this feature must be included in evaluator, as referencing to complete list of allowed symbols for evaluate and for set. No other way will give you a safety.
The bad news is that with dynamic scoping the potential hackers will be glad much either ;-)
WBR, Dmi
Maybe it it better to avoid the lsp-format for data-storage,
but it is so easy to handle with save, source and load.
For my project I use a binary, encrypted file with the lisp-stream inside to store my data. Also the lisp-file has a special string-header for versioning/plausibility check.
Of cource also XML could do such job.
but it is so easy to handle with save, source and load.
For my project I use a binary, encrypted file with the lisp-stream inside to store my data. Also the lisp-file has a special string-header for versioning/plausibility check.
Of cource also XML could do such job.
Hans-Peter
Code: Select all
newLISP v.8.7.0 on linux, execute 'newlisp -h' for more info.
> (macro-string "(set 'a (+ 1 2))")
((set 'a (+ 1 2)))
> ((macro-string "(set 'a (+ 1 2))") 0 0)
set
>
In other words, it parsing, but don't evaluating.
Logically, I think, if we have a function 'string' that can print s-lists, so we must have a function that can read the s-lists back from string source ;-)
WBR, Dmi
If you quote list inside the string, this works:
Fanda
Code: Select all
> (eval-string "'(set 'a (+ 1 2))")
(set 'a (+ 1 2))
> ((eval-string "'(set 'a (+ 1 2))") 0 0)
set
Code: Select all
newLISP v.8.7.0 on linux, execute 'newlisp -h' for more info.
> (eval-string "'a (println 1)")
1
1
It's too dangerous to use evaluation-based techics for reading data.
Many web holes are based on that already...
WBR, Dmi
Would something like this work?
> (define (bob one two) (+ one two))
(lambda (one two) (+ one two))
> (source 'bob)
"(define (bob one two)\r\n (+ one two))\r\n\r\n"
> (fnparse (source 'bob))
("+" "bob" "define")
Code: Select all
(define (fnparse SOURCE)
(letn
( LP "(" ;) left paren
SP " " ; space
LPSP "( " ;) left paren and space
NULL "" ; null string
keep (lambda (L K) (dolist (x L) (if (= (x 0) LP) (push x K))) K)
s (parse (replace LPSP (join (parse SOURCE) SP) LP) SP)
)
;body of letn
(unique (map (fn (x) (replace LP x NULL)) (keep s))) ))
(lambda (one two) (+ one two))
> (source 'bob)
"(define (bob one two)\r\n (+ one two))\r\n\r\n"
> (fnparse (source 'bob))
("+" "bob" "define")