Crystal: Tuple of tuples fails to parse

Created on 26 Jul 2016  路  3Comments  路  Source: crystal-lang/crystal

{{true, true}, {true, false}} can't be parsed.

feature compiler

Most helpful comment

@RX14 excellent idea!

Now the error given is this:

Syntax error in ./foo.cr:1: expecting token ',', not '}'

If you are nesting tuples or hashes you must write them like this:

    { {x, y}, {z, w} } # Note the space after the first curly brace

because {{...}} is parsed as a macro expression.

{{1, 2}, {3, 4}}
    ^

All 3 comments

This is because {{ ... }} is a macro expression. You need to use a few spaces:

{ {true, true}, {true, false} }

I think this will bite a few people, maybe the compiler should try to detect this and emit an error.

@RX14 excellent idea!

Now the error given is this:

Syntax error in ./foo.cr:1: expecting token ',', not '}'

If you are nesting tuples or hashes you must write them like this:

    { {x, y}, {z, w} } # Note the space after the first curly brace

because {{...}} is parsed as a macro expression.

{{1, 2}, {3, 4}}
    ^
Was this page helpful?
0 / 5 - 0 ratings