Page 1 of 1

Parse Question

Posted: Thu Sep 04, 2008 6:27 pm
by 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

Posted: Thu Sep 04, 2008 8:44 pm
by cormullion
I think the rules are basically: treat the string as if it were newLISP source code:

Code: Select all

>(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:

Code: Select all

(parse {john d}) 
is parsing [john d] and going to return two symbols, whereas :

Code: Select all

(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:

Code: Select all

> "john d"
"john d"
>
- it has parsed as itself.

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

Code: Select all

> (set t "this)

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