Skip to content

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

Merged
maxbrunsfeld merged 3 commits into
masterfrom
extract-simple-aliases
Aug 30, 2018
Merged

maxbrunsfeld merged 3 commits into
masterfrom
extract-simple-aliases

Conversation

@maxbrunsfeld

@maxbrunsfeld maxbrunsfeld commented Aug 30, 2018 •

Copy link
Copy Markdown
Contributor

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 force-pushed the extract-simple-aliases branch from 6f806d2 to 7fc64ed Compare August 30, 2018 16:57
@queerviolet queerviolet mentioned this pull request Aug 30, 2018
12 tasks done
@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
Copy Markdown
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