Parse Question

Q&A's, tips, howto's
Locked
johnd
Posts: 18
Joined: Mon May 09, 2005 7:54 pm
Location: San Francisco, CA

Parse Question

Post 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

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post 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)"
>

Locked