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

Consistent binding forms #33

Open
wenkokke opened this issue Aug 6, 2023 · 4 comments
Open

Consistent binding forms #33

wenkokke opened this issue Aug 6, 2023 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@wenkokke
Copy link
Owner

wenkokke commented Aug 6, 2023

The grammar for special binding forms currently results in inconsistent parse trees and include the opening parentheses in the name. This leads to several usability issues:

This issue tracks those problems, as they share a common cause and solution.

@wenkokke
Copy link
Owner Author

wenkokke commented Aug 6, 2023

The grammar doesn’t support command bindings without a space after the first word, such as:

hello(world):
  …

See #21

@wenkokke
Copy link
Owner Author

wenkokke commented Aug 6, 2023

The parser trees for special binding forms include the opening parenthesis in the name of the binding, as they’re parser as a single token, e.g.,

parrot(click):
  …

…results in a special binding with the name parrot(.

See #31 and #13

@wenkokke wenkokke added the help wanted Extra attention is needed label Aug 6, 2023
@wenkokke
Copy link
Owner Author

wenkokke commented Aug 6, 2023

As mentioned elsewhere, implementing this as an ambiguous grammar with higher priorities for the special binding forms results in strange error correcting behaviour. I believe this is because tree-sitter doesn’t backtrack, and therefore it commits to, e.g., a key binding form whenever it sees something starting with the word “key”, and then error corrects to something strange if we really dealing with a command declaration, e.g., key enter: … gets parsed as a key binding with an erroneous extra word “enter” and a missing argument.

@wenkokke
Copy link
Owner Author

wenkokke commented Aug 6, 2023

The best solution is probably to implement this using lookahead in the parser, i.e., if we see the name of a special binding form at the start of the line, and it has a well formed argument list followed by a colon, we emit the name wrapped in a special_binding token.

Implementing this in the lexer requires modifying scanner.cc to add the special binding logic on top of the matches header logic, and probably requires writing a basic lexing framework—using nested if statements we would end up having to nest as deep as the length of the longest special binding name, which is currently settings… which would be a nightmare to write and to maintain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant