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

Go deeper into the workaround to support 'token()' #210

Merged
merged 7 commits into from
Jun 11, 2021

Conversation

mjambon
Copy link
Member

@mjambon mjambon commented Jun 10, 2021

We initially hit an error with token(prec.dynamic(1, 'as')) in the tree-sitter-hack grammar, and then we (original author and myself) didn't find another way of writing the grammar. The problem is that token(...) sometimes produces a node and sometimes doesn't, and the previous workaround consisting in creating a named rule for token(...) would make the precedence annotation ineffective.

I had to figure out in which cases a token node is missing and handle these cases accordingly. This results in 3 cases, described and tested in the script tests/inline-token/check-test-output.

The file Name_pattern.ml that was renamed Missing_node.ml for clarity on its purpose. This is where we have the logic for working around missing nodes due to patterns (regexps) or due to the token() construct.

Conclusion: a token(prec.dynamic(/[a-z]+/)) will produce no node in the original CST and a node of type unit in the typed CST, with no way to recover the token unless it has its own rule in the original grammar. Other combinations are handled fine.

@mjambon mjambon requested a review from aryx June 10, 2021 19:31
@mjambon mjambon merged commit 2d5d912 into master Jun 11, 2021
@mjambon mjambon deleted the fix-simplification branch June 11, 2021 01:39
Copy link
Collaborator

@aryx aryx left a comment

Choose a reason for hiding this comment

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

Nice comments, nice tests.

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

Successfully merging this pull request may close these issues.

2 participants