Wiki

Ticket #221 (closed defect: fixed)

Opened 7 years ago

Last modified 5 years ago

Error message if place whitespace in methodcall between method name and arglist

Reported by: nevdelap Owned by: Chuck
Priority: minor Milestone:
Component: Cobra Compiler Version: 0.8.0
Keywords: Cc:

Description

If this is a necessary restriction a better error message would be good, but I don't think it should be restricted this way because it prevents aligning things nicely.

class Program

    def main
        a = .someCall   ("abc") and _
            .anotherCall("def")
        print a

    def someCall as bool
        return true

    def anotherCall as bool
        return true

test.cobra(4): error: Unexpected call.

Attachments

methodcall-spaces.patch Download (1.5 KB) - added by hopscc 5 years ago.

Change History

Changed 7 years ago by hopscc

Alternative wspc arrangements for aligning things nicely/vertical alignment

        a =    .someCall("abc") and _ 
            .anotherCall("def")

and

        a = .someCall(   "abc") and _
            .anotherCall("def")

and

        a = .someCall("abc") and _
            .anotherCall("def")

'ID(' is a different token from 'ID <wspc> (' (multiple tokens)
see at CobraTokenizer.cobra lines 82-223.
( Its being recognised/treated as a different language construct).

Changed 7 years ago by nevdelap

The first one is ok in this case just because the method endings are the same, but it's a bogus example.

The second is ugly.

The third one can be very messy depending on the parameters and the lengths of the names, but that's what I've been doing. ie: not aligning vertically for readability. :(

If there are cases where the whitespace after something that could be method before an opening bracket really makes a different construct I can certainly live with it and it's obviously low priority, but I wanted to flag it.

Changed 7 years ago by nevdelap

Also, the first is not possible when they are just calls because they can't have additional whitespace changing their indentation.

   .someCall("abc") # not possible
.anotherCall("def")

Changed 7 years ago by Chuck

The requirement to keep the parenthesis flush with the method name is intentional. It's one of several aspects of Cobra's syntax to make code bases more uniform. I'm sorry, but this won't be changed:

-- The request to do this kind of alignment has only been brought up this one time.

-- I suspect that this case comes up rarely. Most expressions don't exceed one line and most expressions that do probably don't need this sort of alignment.

-- You mentioned that Hops 2nd example is ugly, but I think the same could be said about the example in the description of the ticket.

I agree that the error message could be improved to guide the user to the correct Cobra syntax (we have other such messages already). I will leave the ticket open for that.

Changed 5 years ago by hopscc

Changed 5 years ago by hopscc

  • status changed from new to assigned
  • owner set to Chuck

Add error check for this and test case.

Changed 5 years ago by hopscc

  • summary changed from Not being able to have whitespace between a method name and ( prevents vertical alignment. to Error message if place whitespace in methodcall between method name and arglist

Changed 5 years ago by Charles

  • status changed from assigned to closed
  • resolution set to fixed

Patch applied in changeset:2955

Thanks.

Note: See TracTickets for help on using tickets.