Parse Question

Started by johnd, September 04, 2008, 11:27:42 AM

Previous topic - Next topic

johnd

According to the manual when no str-break token is included in parse the function uses "newLISP's internal parsing rules".  Are these described somewhere in the manual?



I've noticed some odd behavior with parse



> (parse {"john d"} " ")

(""john" "d"")

> (parse {"john d"})

("john d")

> (parse {john d})

("john" "d")

>



I was assuming a the break token was a space, but the last two examples are different.



I came across this when I tried to parse a single " without including an explicit str-break.



> (parse {"} " ")

(""")

> (parse {"})



ERR: string token too long in function parse : ""

>



John

cormullion

#1
I think the rules are basically: treat the string as if it were newLISP source code:


>(set 's {(set 't "this is a string") ; a comment})
"(set 't "this is a string") ; a comment"
> (parse s)
("(" "set" "'" "t" "this is a string" ")")


The quote is stripped from the t, and the comment is lost altogether... It's not using spaces, but the components of the language.



I think this:


(parse {john d})

is parsing [john d] and going to return two symbols, whereas :


(parse {"john d"})

is parsing a string that starts and ends with quotation marks - ["john d"] - (you've doubled the string delimiters). If you type this into newLISP:


> "john d"
"john d"
>


- it has parsed as itself.



And your last example is like typing this into the terminal:


> (set t "this)

ERR: string token too long : "this)"
>