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

feat(lex,parse): Add stub try/catch implementation #611

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sjbarag
Copy link
Owner

@sjbarag sjbarag commented Jan 19, 2021

Implementing try/catch/throw takes a good bit of work in the interpreter, so I'm splitting that into two pull requests. This one includes parsing try/catch/end try (without throw), and always executes only the try block to maintain backwards compatibility. It's a weird partial state, but the alternative is a massive pull request that can't be reasonably reviewed or understood.

see #554

RBI 9.4 adds support for error handling via the `try`/`catch` model [1].
Interestingly, `try`, `catch`, and `endtry` are all valid identifiers!
That makes parsing a little bit tougher, but it's not unprecedented in
this language.  Detect `try`/`catch`/throw`/`end try` during lexing and
emit the proper lexemes.

[1] https://developer.roku.com/docs/references/brightscript/language/error-handling.html
see #554
@sjbarag sjbarag added enhancement Any addition to this project's existing capabilities lexer Affects this project's lexer (aka scanner) parser Affects this project's token parser e2e Affects this project's end-to-end test cases (the BrightScript sample files executed during testing) labels Jan 19, 2021
Throwing exceptions and catching them aren't yet supported in `brs`, so
executing only the `try` block seems to be a reasonable "bare minimum"
approach to try/catch support.  Handle `try`, `catch`, and `end try`
lexemes in the parser, emitting TryCatch statements for the interpreter
to execute naïvely.

see #554
Copy link
Collaborator

@alimnios72 alimnios72 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for keeping this PR simple. I just have a noob question below

@@ -94,6 +98,8 @@ export const KeyWords: { [key: string]: L } = {
stop: L.Stop,
sub: L.Sub,
to: L.To,
try: L.Try,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noob question: why are try and endtry keywords but not reserved words while throw is both?

@lvcabral
Copy link
Contributor

lvcabral commented May 2, 2024

Try..Catch and Throw implementation was finished in the Roku Community fork:
https://github.com/rokucommunity/brs/releases/tag/v0.46.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e2e Affects this project's end-to-end test cases (the BrightScript sample files executed during testing) enhancement Any addition to this project's existing capabilities lexer Affects this project's lexer (aka scanner) parser Affects this project's token parser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants