Author Topic: Feature: Embedded strings  (Read 12173 times)

Cobo

  • Autococker
  • Posts: 1362
Re: Feature: Embedded strings
« Reply #20 on: January 06, 2008, 08:51:40 PM »
actually... yes that's true, but in that case you would not use \" around name Cobo.
there are 3 other characters you could use:
'
\'
or even \\" - double escaped ;)

and technically, you could nest quotes to limitless depth by using increasing numbers of backslashes for each depth of nesting.

and that, my friend, is how escaped quotes work.
That kind of defeats the purpose of the neatness of escape characters.
In such case, I believe adding "s is better than adding backslashes.

webhead

  • Committee Member
  • Autococker
  • Posts: 1185
Re: Feature: Embedded strings
« Reply #21 on: January 06, 2008, 09:01:45 PM »
just multiple quote marks in a row?? now THAT's what would confuse the parser.

sk89q

  • Global Moderator
  • Autococker
  • Posts: 1049
Re: Feature: Embedded strings
« Reply #22 on: January 06, 2008, 09:13:08 PM »
Escaping multiple levels can never be neat if you're working with more than one level. Adding ' instead of \ would completely prevent you from being able to use multiple levels of quotes.

Cobo

  • Autococker
  • Posts: 1362
Re: Feature: Embedded strings
« Reply #23 on: January 06, 2008, 09:19:17 PM »
just multiple quote marks in a row?? now THAT's what would confuse the parser.
Hm, I guess you're right there.
But thats what jitspoe said he was going to do, so idk.

Zorchenhimer

  • Autococker
  • Posts: 2614
Re: Feature: Embedded strings
« Reply #24 on: January 06, 2008, 10:22:18 PM »
computers are smart, they can do it. ;)

No, computers are very dumb.  They only do exactly what you tell them to do.  :P

webhead

  • Committee Member
  • Autococker
  • Posts: 1185
Re: Feature: Embedded strings
« Reply #25 on: January 06, 2008, 11:02:35 PM »
 ::) fine, go ahead and pick apart my words. :P

i know that, i guess i should have used the word "capable" in place of "smart".

jitspoe

  • Administrator
  • Autococker
  • Posts: 18802
Re: Feature: Embedded strings
« Reply #26 on: January 07, 2008, 01:18:06 AM »
Writing a tokenizer with escape sequences is not hard...
But writing one that's compatible with the current tokenizer, and all the stuff that depends on it, is.

Double quotes seem to work fine for CSV parsers, and I think they could be implemented without breaking any of the current stuff

bind b "bind c ""say """"hello world"""""""
-> bind c "say ""hello world"""
-> say "hello world"

bind b "bind c \"say \\"hello world\\"\""
-> bind c "say \"hello world\""
-> say "hello world"

Perhaps the escape characters are cleaner, but we'd probably have to set up a full escape code set, with \t, \n, etc.  What if somebody puts \n in their name?  That could cause issues.

Oh, I just remembered something that caused headaches with my previous experiences: variables.

set somevar hello
bind a "say $somevar"
set somevar goodbye

pressing "a" will say "goodbye" as expected.  But what if you wanted it to say hello?  Putting quotes around something will make it absolute.

Also, say you wanted to use a command that cared about parameters?  If you wanted it all in the first parameter, you'd have to put quotes around it, but if you put quotes around it, it won't parse out the variable.

set somevar "string with spaces"
bind a "somecmd $somevar"

Now when you press "a", it will execute:
somecmd (1)string (2)with (3)spaces

When you really wanted
somecmd (1)"string with spaces"

But if you do:
somecmd "$somevar"

you get
somecmd (1)$somevar