String literal with special symbols inside

This forum is meant for questions and discussions about the X# language and tools
Post Reply
User avatar
Irwin
Posts: 24
Joined: Wed Mar 23, 2022 10:24 am
Location: España

String literal with special symbols inside

Post by Irwin »

Hi there,

I'm getting the error

Code: Select all

XS9002: Parser: unexpected input '{'
in this line of code:

Code: Select all

VAR lcMacro := "IMPLEMENT_OLECREATE(<<class>>, <<external_name>>,
0x{0:X8}, 0x{1:X4}, 0x{2:X4}, 0x{3:X2}, 0x{4:X2}, 0x{5:X2}, 0x{6:X2}, 0x{7:X2}, 0x{8:X2}, 0x{9:X2}, 0x{10:X2});"
Note that is a literal string so its content should not be parsed.

On the other hand, if you try with TEXT/ENDTEXT then it will complains because of the trailing semicolon ;

Code: Select all

TEXT TO lcMacro
IMPLEMENT_OLECREATE(<<class>>, <<external_name>>,
0x{0:X8}, 0x{1:X4}, 0x{2:X4}, 0x{3:X2}, 0x{4:X2}, 0x{5:X2}, 0x{6:X2}, 0x{7:X2}, 0x{8:X2}, 0x{9:X2}, 0x{10:X2});
ENDTEXT
if you quit the trailing semicolon then it compiles ok.


BTW: should I post this issue here or at the github repo?

thanks!
User avatar
Chris
Posts: 4826
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: String literal with special symbols inside

Post by Chris »

Hi Irwin,

For clear bugs in the compiler/runtime etc, please put them directly in git if you can. For issues that need some discussion/explanations etc, better post them here first.

The error with the semicolon inside TEXT...END TEXT is a clear bug I think, the semicolon should be part of the text (that's what you intended to, is that right?)

For the simpler string assignment, this is just a normal expression (and code continuing in the next line should be ended with a semicolon at the end), the correct syntax would be:

VAR lcMacro := "line 1 of text" + ;
"line 2 of text"

But I see that the compiler allows you to omit the end quote of the first line, and still require the ";" symbol (still inside the string), which is very confusing indeed. Will open a report about this and the other issues (after clarifying also the rest).

About the actual contents of the string, what is your intended result? First of all, does VFP allow to use the <<varname>> notation also in "regular" strings, like the one you are using in the VAR declaration? Or is this supported only in TEXT TO commands (as we were assuming).

The currently supported way to do something like this in X# is using interpolated strings, there's documentation about this here: https://www.xsharp.eu/help/new-feat-int ... rings.html

But if VFP allows the <<...>> notation in such strings, then we need to allow it also in X#, for the VFP dialect.

Also about the other clauses inside the string, like "0x{0:X8}", is this something that VFP supports, or are you trying to use the .Net notation for translating strings?
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Irwin
Posts: 24
Joined: Wed Mar 23, 2022 10:24 am
Location: España

Re: String literal with special symbols inside

Post by Irwin »

Hi Chris,

In my case, the content inside TEXT/ENDTEXT should be treated as a literal string because I'm not specifying the TEXTMERGE command to parse what it is between angle brackets <<...>>

For example:

Code: Select all

TEXT TO lcString 
<<hello>>
END TEXT
?lcString // this prints out <<hello>>

VAR hello := "hello world!"
TEXT TO lcString TEXTMERGE
<<hello>>
END TEXT
?lcString // hello world
I believe this behavior doesn't rely on any dialect, right?
User avatar
Chris
Posts: 4826
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: String literal with special symbols inside

Post by Chris »

Hi Irwin,

Indeed, TEXT TO is identical in all dialects (unless Robert has implemented something differently that I am not aware about), since it's something completely new in X#, no other dialect had this, so we implemented it the same way for all. So the current behavior that merges the text no matter if TEXTMERGE is used or not is wrong, will open a ticket for this.

But regarding simple literal strings (c := "abc"), if VFP allows text merging even there, then we will need to implement this only in the VFP dialect and leave the current behavior for all other dialects (for compatibility reasons).
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
robert
Posts: 4464
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: String literal with special symbols inside

Post by robert »

Guys,
There are 3 versions of TEXT .. ENDTEXT.
There is one version for the Core dialect:

Code: Select all

TEXT TO <VariableName> [ADDITIVE]
    TextLines
ENDTEXT
This does need any runtime support.
There a version for all other dialects except FoxPro

Code: Select all

TEXT [INTO <VariableName> [TRIMMED]] |
[INTO <VariableName> WRAP] |
[INTO <VariableName> WRAP <cLineBreak> [TRIMMED]]
  TextLines
ENDTEXT
or

Code: Select all

TEXT [TO PRINTER] | [TO FILE <cFilename>]
  TextLines
ENDTEXT

and finally a version for FoxPro that also supports Textmerge and some other options

Code: Select all

TEXT [TO <VariableName> [ADDITIVE] [TEXTMERGE] [NOSHOW] [FLAGS nValue] [PRETEXT eExpression]]
    TextLines
ENDTEXT
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Chris
Posts: 4826
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: String literal with special symbols inside

Post by Chris »

Robert,

Ah, I had missed that, thanks for the clarification!

So actually TEXTMERGE works correctly in the VFP dialect, and it is actually depending correctly on if SET TEXTMERGE is set to ON or OFF.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply