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

Cobo

  • Autococker
  • Posts: 1362
Feature: Embedded strings
« on: January 05, 2008, 11:24:48 PM »
So you can have stuff like:
Code: [Select]
bind a "name "this is my name"; echo "I changed my name""

Zorchenhimer

  • Autococker
  • Posts: 2614
Re: Feature: Embedded strings
« Reply #1 on: January 06, 2008, 12:21:49 AM »
Do you mean Embedded quotes?

Cobo

  • Autococker
  • Posts: 1362
Re: Feature: Embedded strings
« Reply #2 on: January 06, 2008, 12:23:34 AM »
Yeah, I dont know if Jitspoe finally decided how he would do this.
I think he was going to hardcode some cvars as if they were "

webhead

  • Committee Member
  • Autococker
  • Posts: 1185
Re: Feature: Embedded strings
« Reply #3 on: January 06, 2008, 12:30:03 AM »
or, he could just make it handle quotes like a programming language.
examples:

Code: [Select]
bind a "name 'this is my name'; echo 'I changed my name'"
Code: [Select]
bind a 'name "this is my name"; echo "I changed my name"'
Code: [Select]
bind a "name \"this is my name\"; echo \"I changed my name\""
Code: [Select]
bind a 'name \'this is my name\'; echo \'I changed my name\''
any of those ways.

Zorchenhimer

  • Autococker
  • Posts: 2614
Re: Feature: Embedded strings
« Reply #4 on: January 06, 2008, 12:31:22 AM »
Those'll work too.

Cobo

  • Autococker
  • Posts: 1362
Re: Feature: Embedded strings
« Reply #5 on: January 06, 2008, 12:45:12 AM »
Ok, I remember how he told me he may be doing it, since macro parsing was already implemented it would use a hardcoded cvar, and every time you embeded a string you would add a set of $. like this:
Code: [Select]
bind a $q$name $$q$$this is my name$$q$$; echo $$q$$I changed my name$$q$$ $q$
So when you do the bind, a's command would actually be set to this:
Code: [Select]
name $q$this is my name$q$; echo $q$I changed my name$q$
This is something that DP does already.

webhead

  • Committee Member
  • Autococker
  • Posts: 1185
Re: Feature: Embedded strings
« Reply #6 on: January 06, 2008, 12:52:37 AM »
that's confusing to look at.

Cobo

  • Autococker
  • Posts: 1362
Re: Feature: Embedded strings
« Reply #7 on: January 06, 2008, 12:55:14 AM »
that's confusing to look at.
Exactly what I told him, but you could get used to it pretty easily.

jitspoe

  • Administrator
  • Autococker
  • Posts: 18802
Re: Feature: Embedded strings
« Reply #8 on: January 06, 2008, 12:17:17 PM »
http://dplogin.com/dplogin/featurevote/feature.php?id=10034

bind a "name ""this is my name""; echo ""I changed my name"""

Single quotes wouldn't work, though, because of situaitons like this
bind a "echo 'I can't use this.'"

webhead

  • Committee Member
  • Autococker
  • Posts: 1185
Re: Feature: Embedded strings
« Reply #9 on: January 06, 2008, 02:00:19 PM »
Single quotes wouldn't work, though, because of situaitons like this
bind a "echo 'I can't use this.'"

exactly why i suggested being able to escape quotes (y'know, with a backslash). then it would become:

Code: [Select]
bind a "echo 'I can\'t use this.'"for example.

lekky

  • Autococker
  • Posts: 2449
Re: Feature: Embedded strings
« Reply #10 on: January 06, 2008, 07:00:03 PM »
The escape char would be the obvious choice.

Cobo

  • Autococker
  • Posts: 1362
Re: Feature: Embedded strings
« Reply #11 on: January 06, 2008, 07:13:45 PM »
The escape character wouldnt work.
Here's why:

bind "a" "set \"mycvar\" \"my value\""

DP's parser simply doesnt know when to stop getting the next token. Will it tell you to set "mycvar" to "my value" or set "mycvar my value" to nothing.

This isnt the bets example of why, but it shows why it wouldnt work in dp. It works in languages because after a string you shouldnt have another string after it.

webhead

  • Committee Member
  • Autococker
  • Posts: 1185
Re: Feature: Embedded strings
« Reply #12 on: January 06, 2008, 08:07:35 PM »
i hope you notice that escaped quotes are no worse than that $q$ and $$q$$ mess. the only difference is what characters are used.

Cobo

  • Autococker
  • Posts: 1362
Re: Feature: Embedded strings
« Reply #13 on: January 06, 2008, 08:09:12 PM »
i hope you notice that escaped quotes are no worse than that $q$ and $$q$$ mess. the only difference is what characters are used.
I hope you re-read my last post.

Obviously escape characters are better in every aspect.


I'll try to come up with a better example of why it woudlnt work...

sk89q

  • Global Moderator
  • Autococker
  • Posts: 1049
Re: Feature: Embedded strings
« Reply #14 on: January 06, 2008, 08:18:46 PM »
The escape character wouldnt work.
Here's why:

bind "a" "set \"mycvar\" \"my value\""

DP's parser simply doesnt know when to stop getting the next token. Will it tell you to set "mycvar" to "my value" or set "mycvar my value" to nothing.

Writing a tokenizer with escape sequences is not hard...

Cobo

  • Autococker
  • Posts: 1362
Re: Feature: Embedded strings
« Reply #15 on: January 06, 2008, 08:25:55 PM »
Yep, for something that embeds strings until a certain level.
Imagine having 5 strings embedded in eachother. How does the parser knows when one starts and when one ends?
Thats why I said my example isnt the best.

webhead

  • Committee Member
  • Autococker
  • Posts: 1185
Re: Feature: Embedded strings
« Reply #16 on: January 06, 2008, 08:27:47 PM »
oh it's possible. hard to look at, and probably complicated to code, but possible. computers are smart, they can do it. ;)

say a string starts with " - then the end of the string would be at the next occurence of that character, given that there is no backslash before it.

Cobo

  • Autococker
  • Posts: 1362
Re: Feature: Embedded strings
« Reply #17 on: January 06, 2008, 08:37:18 PM »
alias a " name Cobo; alias b \"name Oboc; alias c \"name Cobo\"\" "

DP parses alias
DP parses a
DP parses " name Cobo; alias b \"name Oboc; alias c \"name Cobo\"\" "

Now when dp parses " name Cobo; alias b \"name Oboc; alias c \"name Cobo\"\" " again it would go like this:
Dp parses name
Dp parses Cobo
DP parses ;
DP parses alias
DP parses b

Now when dp starts parsing \"name Oboc; alias c \"name Cobo\"\" it would go like this:
DP parses a \" this tells him we are in an embedded string.
Dp parses Oboc
Dp parses ;
Dp parses alias
DP parses c

Guess what Dp is going to do next.
Yep, you got it, dp will parse \" and not even the smartest computer will figure out that string shouldnt be over.

webhead

  • Committee Member
  • Autococker
  • Posts: 1185
Re: Feature: Embedded strings
« Reply #18 on: January 06, 2008, 08:44:24 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.

sk89q

  • Global Moderator
  • Autococker
  • Posts: 1049
Re: Feature: Embedded strings
« Reply #19 on: January 06, 2008, 08:49:58 PM »
Cobo, conventional backslash escaping uses multiple backslashes to escape multiple levels of quotes, as webhead has mentioned.

P.S. webhead beat me to the post =|