Originally posted by Mnjul
So now I have a delimiter, and a literal identifier...for the delimiter to show literally, it must be prefixed with the identifier...and for the identifier itself to show literally, it must be typed twice...
indeed, because in that case the first \ is still seen as the 'literal identifier' and the second is seen as just another character which needs to be taken literally.
Originally posted by Mnjul
quite troublesome, huh
not really. You don't need to look at it as three different things or special cases, as they are in fact all the same.
The 'identifier' \ must be seen as an escape character, a character with a special function. As soon as it is encountered it is interpreted as a "command" and the function of the following character is determined by what that character is. (Which is indeed the function \ in other stuff too, eg in C style languages, think about \n, \t, etc...)
If the next character has a special meaning (in the parsing routine), that special meaning is interpreted, otherwise it just takes the next character literal, no matter what character it is.
For your plugin (in case you're going to implement it that is), this means it takes every character literally that comes after it, no matter what character, just that simple. The only special case would be the delimiter. (Unless, you also include \n which will be parsed as a linefeed and \t as a tab... maybe also a suggestion for even extra possebilities?)
To give some examples (and I'll use $
as delimiter just for better visualization of the examples though)
"Oh gosh" "Blah" => needs "Oh gosh$
"Oh gosh$" "Blah" => needs "Oh gosh\$$
"Oh gosh" "$Blah" => needs "Oh gosh$
"Oh \gosh" "\Blah\" => needs "Oh \\gosh$
but the above is nothing special, it is just the same case like:
"Oh gosh" "Blah" => needs "\O\h\ \g\o\s\h$
I use the same, without the delimiter of course, in the HolidayCounter Plugin for defining the shown text and to make a difference between tags and literall text: "(d) days ago I typed \(d)" will be parsed as "5 days ago I typed (d)" because "\(" is just seen as "(" literally and thus the rest of the text "d)" isn't a tag anymore which needs replacing.
Or instead of the delimiter being a single character, you also could make it into a 'special function' for the escape character itself of course (but then the user needs to type 2 characters in everyday use, but it would be consistent with the rest though). But I don't think you want to go that far, though it is nice and consistant with all the rest.... dunno. eg:
\d is parsed as the delimiter
\n is parsed as a linefeed
\t is parsed as a tab
\? (where ? is any other character)
is parsed as taking ? literally
EDIT: In reference to MnJul's reply: all the above was meant as POV from the user though. It is how the user should look at it to understand how it works. That is, he doesn't need to know how it is programmed, but the above explains to him that there are no 'special cases', just 1 rule: "\" interprets anything as literal after it.
So, I didn't realize you could see it in two ways (POV from user and POV of programmer). Though both ways are almost the same in this case.