DateTime Class

This forum is meant for questions and discussions about the X# language and tools
Post Reply
jacekm23
Posts: 14
Joined: Tue Sep 29, 2015 8:45 am

DateTime Class

Post 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
User avatar
SHirsch
Posts: 281
Joined: Tue Jan 30, 2018 8:23 am

DateTime Class

Post by SHirsch »

Hi Jacek,

DATE is a keyword in X# so try:

Code: Select all

oDT2 := oDT1:@@Date
Stefan
jacekm23
Posts: 14
Joined: Tue Sep 29, 2015 8:45 am

DateTime Class

Post 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
Jamal
Posts: 314
Joined: Mon Jul 03, 2017 7:02 pm

DateTime Class

Post 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.
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

DateTime Class

Post by Chris »

Hmm, interesting idea about intellisense doing this automatically...
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
User avatar
SHirsch
Posts: 281
Joined: Tue Jan 30, 2018 8:23 am

DateTime Class

Post 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
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

DateTime Class

Post 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.
Chris Pyrgas

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