In Xojo this is one way to handle a string with internal double quotes
dim s as string = """xxx"" = "
this resolves to
But in Swift it escapes non-enclosing quote so the same code would be
dim s as string = "\"xxx\" = "
I am trying to figure out a method to convert the Xojo like string to the required Swift String
It can’t be a simple matter fo replacing “” with " because that would screw up a string like
dim s as string = ""
The correct way is parsing it, it means “reading it sequentially following an interpretation logic”
As Rick mentions, you have to parse the quoted literal string: Determine the beginning and ending positions of the string, then replace any double quotes within those positions with the Swift equivalent. You may be able to accomplish this on a global basis using RegEx.
Don’t wisth to sound unappreciative… but that much I knew… it was " interpretation logic" I was hoping to figure out. … but thanks
In the code I have that does properly tokenize Xojo code that would come out as a StringLiteral
And in there with that I know I can rip of the first & last quote
Then replace all the other “” with " and I’m done
I dont know if you have anything that splits the code into tokens like that which would let you take that same kind of approach
Yes,… My tokenizer returns a quoted string (with embedded " ) as a single token.
For some reason I didn’t think that simply removing the enclosing " (1st and last) and then replacing any remaining “” with " would be the answer… I thought there was all kinds of situations with triple, quadruple and other numbers of sequential quote.
I think as long as you replace “” with \" you’ll end up right
That did in fact seem to work… . I did have an issue with the fact that the “text” might go thru the tokenizer more than once… so it had to handle BOTH cases multiple double quotes AND escaped double quotes…
darned discourse dropped my slash in front of the quote
What’s your approach for multi-line?
Will you support : “Here is a
embedding the line-feeds” ?
No, that syntax is not supported it would have to be
Dim S as String = _
"Here is a " + endofline + _
"multi-line sentence" + endofline + _
"embedding the line feeds"
Are you rewriting Xojo?
And your sentence for “embedding” the line break in Xojo needs concatenation of EndOfLine at each EOL.
rewriting Xojo? No…
writing another development system that has some similarities? and hopefully improvements? Yes.
I have already written a proof-of-concept IDE the generates GUI code in Swift, and a partially working one the creates macOS code.
Right now I am working on translator (which is in another thread here)… .That takes BASIC code and attempts to translate it directly to Swift… Its not perfect (yet)… but at this moment only creates about 100 errors when attempting to translate 6000 lines of BASIC.
100 errors (but only 50 are “unique”) may sound like a lot, but considering the 4 days ago it was 900 errors, I think I’m making good progress
That’s a lot of effort, I hope you are doing that for the love of such adventure.
Oh yeah… if I make and money I’ll be happy… if not… I will have learned a ton