Open ryukinix opened 5 years ago
As we talked in Telegram, I think this can be solved by enclosing the expression in parenthesis (if it's not already) and let the interpreter load it with "read-from-string". Like in the example bellow:
(defun string-parse (str)
(if (and (str:starts-with-p "(" str)
(str:ends-with-p ")" str))
(read-from-string str)
(read-from-string (str:concat "(" str ")"))))
PS.: thanks for the help with cl-str
Interesting! I'll test it.
This expression doesn't works because it should have wrapped parenthesis. In the expression
(and (str:starts-with-p "(" str)
(str:ends-with-p ")" str))
Will return true, but it should not.
But the other cases works, like this one above! Thanks
That's good. You're welcome. I'll keep thinking about it. Maybe we can find a solution for this corner case.
On reddit thread for lisp-inference I read that:
My lexer doesn't works very well for parenthesis.
Your lexer is doing too much work then. Lex the string into a list of symbols and use the shunting-yard algorithm modified to handle unary operators.
The author saw this issue and change his opinion to: the lexer is doing too litle.
We should write proper tests and maybe remove this parse-string function to webapp. I think makes more sense on lisp-inference engine? There is already a src/parser.lisp file.
Discussion related to lexer rewrite: #25
This occurs because my lexer it's just a split by whitespace. I need to fix that.
https://github.com/ryukinix/lisp-inference/blob/3a51c46ff39af6d1ab44597b5a1d81825dadf187/web/webapp.lisp#L37-L41