better error message: for instead of foreach

This forum is meant for questions and discussions about the X# language and tools
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

better error message: for instead of foreach

Post by wriedmann »

Hello,

one of my frequent errors when using the "foreach" statement is to write "for" instead of "foreach". i.e. to write

Code: Select all

for oItem as MyItem in oList
next
instead of

Code: Select all

foreach oItem as MyItem in oList
next
In this case the compiler gives a similar error message:

Code: Select all

error XS9002: Parser: unexpected input ....
Would it be possible to specify it better?
Thank you very much!
Wolfgang
P.S. I'm asking here before adding a ticket because I'm not sure if such a request is appropriate
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
FFF
Posts: 1521
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

better error message: for instead of foreach

Post by FFF »

Wolfgang,
not what you asked, but are you aware of this in template.cfg in XIDE:
..
fore,FOREACH c AS IN rNEXTr
forei,FOREACH IMPLIED c IN rNEXTr
...

I know, i use the shortcuts not enough, as i code too little to memorize them, but in this case it might be helpful.

BTW, @Chris: i think i asked for this years ago ;), but the icing on the cake for this would be:
fore <Tab>
myItem <Tab>, Cursor jumps behind the "AS "
myType <Tab>, Cursor jumps behind the "IN "
myCollection <Tab>, Cursor jumps to next line

I just think you and you baby could do this ;-)
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

better error message: for instead of foreach

Post by wriedmann »

Hi Karl,

yes, I'm aware of it. My main problem is that I'm not able to remember all these templates - I'm using only very few of them.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
FFF
Posts: 1521
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

better error message: for instead of foreach

Post by FFF »

wriedmann wrote:Hi Karl,

yes, I'm aware of it. My main problem is that I'm not able to remember all these templates
B)
So i'm not alone...
But, as i wrote, the "multi tab" would enhance the usefullness a lot further...
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

better error message: for instead of foreach

Post by wriedmann »

Hi Karl,

maybe I will add a context menu entry to select a template to insert - that could help.

Wolfgang
P.S. did you knew I'm driving a "poor mans Tesla" now?
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

better error message: for instead of foreach

Post by Chris »

Wolfgang - Yeah, agreed, there are several places where parser errors could become more straightforward. As time passes, more an dmore of them will be improved, it's just not of highest priority. Will log this particular one.

Karl - Every single time I use the FOREACH template, this is exactly what I am also thinking, so it is not that I have forgotten about it :). It's just a lot of work to implement it and it will be useful in only 2-3 templates, but will finally do it in one rainy day!
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

better error message: for instead of foreach

Post by wriedmann »

Hi Chris,

thank you very much!
It is of course a lot of work to prodice useful error messages, but it will be very helpful for people starting with X#, I think.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
FFF
Posts: 1521
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

better error message: for instead of foreach

Post by FFF »

wriedmann wrote:P.S. did you knew I'm driving a "poor mans Tesla" now?
A "3"? Congratulations! Meanwhile i'm at 62,5k km in < 18 months, still grinning everytime i see my car ;-)
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

better error message: for instead of foreach

Post by wriedmann »

Hi Karl,

no, a Renault Zoe. The 3 is still off limits for me, but maybe in a few years <g>.
10.000 km in about 4 months... and very happy with it.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

better error message: for instead of foreach

Post by Chris »

Hi Wolfgang,

The problem is not writing messages, this is the very easy part. The big task is not letting the parser handle those situations in a general way, but provide specialized error identifying and reporting for every single different case.

Btw, congrats for your Zoe! (which means "life" in Greek)
Chris Pyrgas

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