xsharp.eu • DateTime Class
Page 1 of 1

DateTime Class

Posted: Thu May 09, 2019 9:26 am
by jacekm23
In CORE mode I am trying to write something like this:

local oDt1 as DateTime
local oDt2 as DateTime

oDt1 := DateTime{...}
oDt2 := Dt1:Date

and I receive this:

error XS9002: Parser: unexpected input ':DATE'
Compilation failed (1 error)

How can I get a date value from oDt1 variable?

I use XIDE.

Regards
Jacek

DateTime Class

Posted: Thu May 09, 2019 9:33 am
by SHirsch
Hi Jacek,

DATE is a keyword in X# so try:

Code: Select all

oDT2 := oDT1:@@Date
Stefan

DateTime Class

Posted: Thu May 09, 2019 9:46 am
by jacekm23
Stefan,

exactly I have:

LOCAL oDt1 AS Nullable<DateTime>
LOCAL oDt2 AS Nullable<DateTime>

and
oDt2 := oDt1:Value:@@Date
works for me.

Thank you
Jacek

DateTime Class

Posted: Thu May 09, 2019 9:57 am
by Jamal
As Stefan said, DATE is a keyword.

Adding a @@ tells the compiler preprocessor (parser) not to touch the word that follows it.

https://www.xsharp.eu/help/x-keywords.html

Dev Team
I think the compile time error should be more explanatory.
Like:
error XS9002: Parser: a keyword is used ':DATE'. Use @@ before keyword. Compilation failed (1 error).

Or maybe X# intellisense can detect such situations and suggest a fix when writing such code.

DateTime Class

Posted: Thu May 09, 2019 11:42 am
by Chris
Hmm, interesting idea about intellisense doing this automatically...

DateTime Class

Posted: Thu May 09, 2019 12:00 pm
by SHirsch
Hi Chris,

I think intellisense should notice that xx:Date is a property and not a keyword.
Also the parser should recognize xx:Date as a property and not the Type DATE.

Regards,
Stefan

DateTime Class

Posted: Thu May 09, 2019 12:22 pm
by Chris
Hi Stefan,

The problem is not that Date is a property and a type, but that DATE is also a keyword, similar to "CLASS", "FUNCTION" etc. And the parser works with rules, which specify in what places a keyword can exist, and there's no rule saying "DATE" can exist after a ":", hence the parser error.

One solution could be to remove DATE from the keywords list, and maybe handle it later resolving it to the Date type. Or make a rule that DATE should not be treated as a keyword after ":". But doing such stuff increases the complexity of the parser and compiler, and of course it is not enough to do it just for DATE, it has to be done for dozens more keywords as well...

But I agree about intellisense, it could indeed identify you are autocompleting an expression with a token that is also a keyword and in this case automatically add the "@@". Btw, the VOXporter already does that, for X#keywords that were not keywords in VO.