Page 1 of 1

Whitespace parsing bug

PostPosted: Thu Feb 21, 2008 4:52 am
by hopscc
0.7.3
If you have a cobra program that uses (or starts with, its not clear) tabs for indentation and insert a line indented to the
correct offset with spaces instead of tabs
you get a non helpful compilation error at the start of the inserted line(s)
e.g
WinForms.cobra(36): error: WinForms.cobra(36,1): error: Expecting an expression.

for an example take WinForms.cobra (its all tab indented) and drop some trace statements into it
(in main, handleclick or init )
using space indentation rather than tabs.

Note that the lines aren't mixing tabs and spaces within the same line
but they are within the program, some lines using Tabs, some using spaces
(not desirable but easy enough to do with multiple program maintainers using different editors or editor settings)

If the compilation error is intended (it shouldnt be - its too easy to do accidentally)
there should be a much better error diagnostic

Re: Whitespace parsing bug

PostPosted: Thu Feb 21, 2008 12:29 pm
by Charles
I'm unable to reproduce the problem. When I add a line that uses spaces instead of tabs, it works fine. Can you email your program as an attachment to contact -at- cobralang -dot- com?

Re: Whitespace parsing bug

PostPosted: Thu Feb 21, 2008 12:45 pm
by Charles
Or you can attach here in the forum--I just fixed attachments.

Re: Whitespace parsing bug

PostPosted: Fri Feb 22, 2008 12:20 am
by hopscc
heres the program as attachment - I also posted it

The commented lines are space indented (uncommenting any of them gives me a compile error on char 1 of that line)
as is the program is tab indented apart from line 39 which is indented with spaces - compilation fails on line 39,1
i.e
C:\home\hops\src\cobra>cobra -t:winexe -r:System.Windows.Forms WinForms.cobra
WinForms.cobra(39): error: WinForms.cobra(39,1): error: Expecting an expression.

Compilation failed - 1 error, 0 warnings
cobra: error: Missing FILE from editor spec.
Run Cobra without options to get full usage information.

Re: Whitespace parsing bug

PostPosted: Fri Feb 22, 2008 12:32 am
by Charles
When I opened your code it looked like:
class Program

def main is shared
print 'hello'
print 'hello with tabs'

Cobra's treatment of indentation is 4 spaces per indentation level, or 1 tab with tabs set to a display width of 4 (to match what space-based code looks like).

And then it says "Expecting an expression" instead of "Unexpected extra indentation" so you couldn't tell. I will fix that for the next release.

Re: Whitespace parsing bug

PostPosted: Fri Feb 22, 2008 1:15 am
by hopscc
Thats probably it then
- my editor is setup to convert input tabs to 8 spaces and display 8 space tabstops and have a 4 space indent just to avoid this mixed tab/spaces sh*t
everything aligns visually for me but not for the compiler - its just the message is wrong.....
sorry wrong call...

Hmm I wonder if its a mistake to have a 4 char tabstop rather than ( the sorta default) 8
either that or the logic disallowing disallowing mixed Tabs and spaces isnt subtle enough....

perhaps what should be disallowed is not mixing Tabs and spaces but mixing Tabs with spaces where number of spaces arent a multiple of 4..... ( for a 4 char tabstop/ default indent)
i.e emit tab/space compiler error message only where there are tabs and spaces and spaces count modulo 4 !=0

that would support any arbitrary setting of Tabstops and corresponding editor indent.....