crypto icon indicating copy to clipboard operation
crypto copied to clipboard

Colons after function signatures cause parse failures

Open sjbarag opened this issue 6 years ago • 2 comments

Like #230 and #195, : can be used to turn a function into a oneliner! They look neato and are supported by RBI but not by brs. MWE:

function main() as integer: return 5: end function
$ brs /tmp/231.brs
/tmp/231.brs(1,36-37): Found unexpected token ':'

sjbarag avatar May 06 '19 16:05 sjbarag

@sjbarag Using your provided example, I don't get any errors.

image

Here's a test also proving this already works.

it('supports one-line functions separated by colons', () => {
    let { tokens } = brs.lexer.Lexer.scan(`
        sub main(): print "Hello world!": end sub
    `);
    let { statements, errors } = brs.parser.Parser.parse(tokens);
    expect(errors.length).toEqual(0);
    expect(statements).toMatchSnapshot();
});

TwitchBronBron avatar May 09 '19 10:05 TwitchBronBron

Heck, that's because I posted the wrong snippet :sweat_smile: Looks like the issue is an as type clause before the :. I updated the example in the description inline. Sorry about that!

sjbarag avatar May 09 '19 15:05 sjbarag