Page 1 of 1

Useless error

PostPosted: Fri Jun 21, 2013 11:52 am
by Chasm
Hello again. I just spent about an hour finding a ghost compilation error and I thought I'd share it with you.

Try compiling the following code and when it fails, try to find where's the problem (this is just a dummy code I slapped together as a preview for the error):

Code: Select all
"""

Replace this text with a description of your program.

"""



class Program

   """

   This is a program that doesn't do anything useful

   """



   cue init

      """

      rutrum enim sed leo dapibus fermentum. Pellentesque dui ante,

      hendrerit quis augue eu, molestie dictum magna. Cum sociis natoque

      """ s

      .init(800, 124, 'Pellentesque sed leo dapibus fermentum')



   cue init(x as int, y as int, s as String)

      base.init



   def main

      print 'Hello, world!'

      

      # Call function 1

      # No parameters

      .func1

      

      # Quisque viverra sollicitudin nulla non luctus.

      .func2

      

      # Quisque viverra eros diam, a suscipit augue placerat no

      # Curabitur dolor orci, dapibus a libero quis,

      .func3

      

      if 5 == 5

         print 'Hello'

      

      # Then call function 4

      .func4

      

   def func1

      """

   r sagittis. Ut dictum felis sed purus ultrices tempus.

   Donec ultricies mauris urna, eget pretium dolor bibendum eu.    

      """

      

      t = ['a', 'b', 'c']

        for letter in t, print letter

      

   def func2

      """

      Pellentesque rutrum enim sed leo dapibus fermentum. Pellentesque dui ante,

      hendrerit quis augue eu, molestie dictum magna. Cum sociis natoque

      """

      d = {'a': 1, 'b': 2}

        assert d['a'] == 1 and d['b'] == 2

        for key, value in d

            print '[key] = [value]'

      

   def func3

      """

      penatibus et magnis dis parturient montes, nascetur ridiculus mus.

      Duis non sapien felis. Nulla dignissim, sem sed laoreet fermentum,

      """

      letters = {'a', 'b', 'c'}

        assert 'a' in letters

        for letter in letters, print letter

      

   def func4

      """

      urna est malesuada sapien, venenatis consequat neque lacus non nibh.

      Proin tempor rhoncus nunc, eget tristique nibh interdum quis.

      """

      a as int

      b as int

      while a > b, a -= 1



The compiler gives me an unhelpful 'Missing statements. Use "pass" or other statements'. In another program that had the same little problem, I got an error that said: 'The correct local variable syntax is "name as Type" or "name = initValue". Try "the as Loads."'.

The reported line is 42, but the real problem lies on the line 14 (see the mistakenly placed letter 's'?).

Please don't take this as some kind of angry ranting, I just thought I'd put a little more effort into demonstrating what the problem is, I hope it's appreciated :lol:

Re: Useless error

PostPosted: Fri Jun 21, 2013 12:10 pm
by nerdzero
Yeah, this looks like a parser error but only appears when you have multiple doc strings in a file and one somewhere in the middle has some trailing text. Here's a simpler case:

"""
Replace this text with a description of your program.
"""

class Program
"""
This is a program that doesn't do anything useful
"""


cue init
"""
hello
""" parseError!
base.init


def main
"""
Another doc string
"""
print 'Hello, world!'


def foo
print 'foo'


Seems to throw off the Pygments parser as well.

Re: Useless error

PostPosted: Fri Jun 21, 2013 6:14 pm
by Charles
Chasm wrote:Please don't take this as some kind of angry ranting, I just thought I'd put a little more effort into demonstrating what the problem is, I hope it's appreciated :lol:

We want feedback like this so we can keep improving. Thanks for taking the time to share.

Re: Useless error

PostPosted: Sat Jun 22, 2013 7:43 am
by hopscc
It doesnt recognise the end of docstring unless its (optional whitespace, ), the 3 quote trigraph followed by optional whitespace and EOL
So its actually eating all the text up to the next """ ( silently)..

The closing docString pattern needs adjusting ( perhaps to something like <wspace>* """ <anychar>* <eol>)
anything on the line after the closing """ will then be ignored...

The 'correct local variable' message is a fallout for when it cant recognise a statement start but the statements look like they might be a reversed variable and Type decl ( like 'Mytype varname' instead of 'varname as MyType').
Unfortunately this also is what the first 2 words of a start of sentence in a docstring also look like.... :shock:

Some scope for more tokeniser token-recognition tweaking...

Good find. Obscure enough to only happen by accident but when it does the existing messages are of absolutely no help....

Re: Useless error

PostPosted: Sat Jun 22, 2013 7:49 am
by Chasm
Tell me about it. I was searching for it with an axe in my hand. :lol:

Re: Useless error

PostPosted: Sat Jun 22, 2013 8:18 am
by hopscc
Logged on ticket:335.

Winding up the compiler verbosity ( >5 for tokenising output) can sometimes be a sharper tool :) but theres then a lot of output to wade through.
Failing that its back to a binary chop on your source code...