Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

constructor identifier causes parse issues in brs #613

Closed
sjbarag opened this issue Jan 21, 2021 · 0 comments · Fixed by #614
Closed

constructor identifier causes parse issues in brs #613

sjbarag opened this issue Jan 21, 2021 · 0 comments · Fixed by #614
Labels
bug Any difference between this BrightScript implementation and RBI, or otherwise unexpected behavior lexer Affects this project's lexer (aka scanner)

Comments

@sjbarag
Copy link
Owner

sjbarag commented Jan 21, 2021

Attempting to use the word constructor as an identifier in brs causes parser errors, despite the fact that this is valid in RBI.

sub main()
    constructor = function()
        return {
            foo: "bar"
        }
    end function

    instance = constructor()
    print instance.foo ' => "bar"
end sub

output:

$ bin/cli.js /tmp/mwe.brs 
/tmp/derp.brs(2,4-15): Found unexpected token 'constructor'
/tmp/derp.brs(6,4-16): Expected 'end sub' to terminate sub block
/tmp/derp.brs(8,15-26): Found unexpected token 'constructor'
/tmp/derp.brs(10,0-7): Found unexpected token 'end sub'
Error occurred parsing
@sjbarag sjbarag added bug Any difference between this BrightScript implementation and RBI, or otherwise unexpected behavior lexer Affects this project's lexer (aka scanner) labels Jan 21, 2021
sjbarag added a commit that referenced this issue Jan 21, 2021
By using an identifier in a BrightScript file as an index into that
object, we accidentally leaked non-Token properties on the `KeyWords` JS
object from the lexer, e.g. `return KeyWords["constructor"]`.  Use
`hasOwnProperty()` to check if an identifier is a BrightScript keyword
to avoid returning JavaScript internals as Tokens.

fixes #613
sjbarag added a commit that referenced this issue Jan 21, 2021
By using an identifier in a BrightScript file as an index into that
object, we accidentally leaked non-Token properties on the `KeyWords` JS
object from the lexer, e.g. `return KeyWords["constructor"]`.  Use
`hasOwnProperty()` to check if an identifier is a BrightScript keyword
to avoid returning JavaScript internals as Tokens.

fixes #613
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Any difference between this BrightScript implementation and RBI, or otherwise unexpected behavior lexer Affects this project's lexer (aka scanner)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant