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

Support non-standard features. #3

Open
Darksecond opened this issue Jun 3, 2021 · 2 comments
Open

Support non-standard features. #3

Darksecond opened this issue Jun 3, 2021 · 2 comments

Comments

@Darksecond
Copy link

I would love support for both the import keyword and array syntax ([...]).

Both are non-standard but pretty common; ideally I would like a configuration option to turn on; however I don't know if this is possible.

@danman113
Copy link
Owner

danman113 commented Jun 3, 2021

Hey, thanks for the suggestion!

I'm generally hesitant to add non-standard features to lox-language, as AFAIK, there are no other lox syntax highlighters on the VS Code Extensions Marketplace. As such I want it to be as close to "standards compliant" as possible and to work pretty well for everyone making their way through the book.

However I am open to the idea of adding non-standard features if they are sufficiently common in both usage and implementation, forming a kind of "community standard".

Here are my thoughts regarding the particular keywords/syntax you want added:

Import Keyword

Seems like it would be straightforward to add, I could just designate it a support.function.builtin.lox. The only downside of adding it is:

  1. It's behavior is simply non-standard and not in the keywords list as such:
  2. It could "break" existing programs as people could use import as a variable name.

If enough people added an import keyword to their language I would add it. (Frankly it's not how I would implement modules: I would use the more lua,node-like require syntax as it could be added as a builtin and achieve similar functionality without needing any tooling updates).

A quick scan through the lox implementations list didn't yield any implementations that used an import keyword, but if you can find a couple that use it in a similar way I'll add it.

Array Syntax

Seems a lot more tricky. Not only is it harder to add (although frankly still pretty easy depending on what we want the behavior to look like. After all JS arrays have already been implemented in VS Code), but as it's a much larger feature than an import keyword, there's way more room for implementation inconsistencies. Just because two implementations may use bracket syntax for initialization, that doesn't mean they use a similar syntax for indexing and vice versa.

Configuration

ideally I would like a configuration option to turn on; however I don't know if this is possible.

It definitely seems tricky. A quick google search gives me the impression that VS Code doesn't officially support any dynamic syntax highlighting. Although we may be able to do it using decorators, it seems more like a hack rather than something officially supported. You're welcome to try to implement it, I would be more than happy to add import if it was an optional feature.

Forking Guide

What this issue comes down to is that as Crafting Interpreters is ultimately a guide on how to make your own, personalized programming language, there is no one-size-fits-all syntax highlighter that will work on all lox language variations. This extension is mostly geared to help people write programs as they work through the contents of the book, not as they add features outside the scope of the book.

That said the book and I both want to encourage people to add cool new features to their language. Although the Lox Language extension won't be able to fit everyone's needs, it would be a great starting point for people to write their own syntax highlighters. One way to solve both your needs, and potentially the needs of other lox implementers (loxers?) would be to write a guide on how fork Lox Language and add features like the ones you requested. Would that interest you?

@Darksecond
Copy link
Author

I think a forking guide would be an excellent idea; instead of adding non-standard features, that not everybody might want in their current form. Ideally I would not want to make this plugin more complex than it needs to be, so I'd rather not add 'complex' Decorators.

I think a forking guide would be in the spirit of lox and would be a rather excellent idea. Let me know if you need any help on it, reviewing, testing or otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants