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

Simplify treatment of rules that are always aliased one way #197

Merged
merged 3 commits into from
Aug 30, 2018

Conversation

maxbrunsfeld
Copy link
Contributor

@maxbrunsfeld maxbrunsfeld commented Aug 30, 2018

Problem

We're using the alias function a lot in several grammars, including tree-sitter-html. It's been really useful, but it has two downsides:

  1. It increases the size of the parse table somewhat because otherwise-identical REDUCE actions can have different alias_sequence_id values.
  2. It causes tokens to appear with different types when they occur within ERROR nodes, because in that case, the aliases are not applied.

The second problem came to my attention when adapting Atom's autocomplete-html package to work with Tree-sitter.

Solution

In this PR, I introduce an internal concept called simple aliases. A grammar symbol is considered to have a simple alias if the symbol is always used with that alias: it's never used without an alias, and it's never used with a different alias.

Simple aliases can be dealt with in a way that is, well, simpler than how we normally implement aliases 😁. This results in a smaller parse table. More importantly though, it causes the rule to always appear with the same name, even when it occurs inside of an ERROR, which makes the syntax tree more consistent and useful overall.

@maxbrunsfeld maxbrunsfeld merged commit 6caa19d into master Aug 30, 2018
@maxbrunsfeld maxbrunsfeld deleted the extract-simple-aliases branch August 30, 2018 17:48
@maxbrunsfeld
Copy link
Contributor Author

This simple changes reduces the ruby parser binary size by 6%.

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

Successfully merging this pull request may close these issues.

1 participant