sjbarag / brs

An interpreter for the BrightScript language that runs on non-Roku platforms.
MIT License
113 stars 43 forks source link

Colons after function signatures cause parse failures #231

Open sjbarag opened 5 years ago

sjbarag commented 5 years ago

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 ':'
TwitchBronBron commented 5 years ago

@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();
});
sjbarag commented 5 years ago

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!