fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: DateTime Class

DateTime Class 3 months 1 week ago #8980

  jacekm23's Avatar Topic Author jacekm23 Offline Posts: 7
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

Please Log in or Create an account to join the conversation.

Last edit: by jacekm23.

DateTime Class 3 months 1 week ago #8981

  SHirsch's Avatar SHirsch Offline Posts: 116
Hi Jacek,

DATE is a keyword in X# so try:
oDT2 := oDT1:@@Date

Stefan

Please Log in or Create an account to join the conversation.

DateTime Class 3 months 1 week ago #8982

  jacekm23's Avatar Topic Author jacekm23 Offline Posts: 7
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

Please Log in or Create an account to join the conversation.

DateTime Class 3 months 1 week ago #8983

  Jamal's Avatar Jamal Away Posts: 130
As Stefan said, DATE is a keyword.

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

www.xsharp.info/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.

Please Log in or Create an account to join the conversation.

DateTime Class 3 months 1 week ago #8985

  Chris's Avatar Chris Offline Posts: 1269
Hmm, interesting idea about intellisense doing this automatically...
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

DateTime Class 3 months 1 week ago #8986

  SHirsch's Avatar SHirsch Offline Posts: 116
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

Please Log in or Create an account to join the conversation.

DateTime Class 3 months 1 week ago #8987

  Chris's Avatar Chris Offline Posts: 1269
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.
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

  • Page:
  • 1