rescript-lang / tree-sitter-rescript

ReScript parser for Tree-Sitter
MIT License
50 stars 15 forks source link

Move inline decorator to scanner #218

Closed aspeddro closed 1 year ago

aspeddro commented 1 year ago

Move inline decorator to scanner.

Inline decorator is decorator without arguments.

@@decorator
@decorator

Decorators with arguments can be specified in grammar.js. This was a limitation because TreeSitter could not determine the end of the rule.

Decorators can now be treated as a comment, can appear anywhere.

This PR also removes some conflicts that were introduced due to decorators. We can also remove some tests with decorators.

nkrkv commented 1 year ago

Absolutely great! Thank you. I like that many conflicts are gone now.

Would you rebase the branch, please?

aspeddro commented 1 year ago

Done

aspeddro commented 1 year ago

Ops, a small error introduced.

'@'
(source_file [0, 0] - [1, 0]
  (ERROR [0, 0] - [1, 0]
    (string_fragment [0, 1] - [1, 0])))

In main branch it's is parsed.

Edit 1:

The parser look at @ an expect a decorator rule.

Edit 2: Fixed in https://github.com/nkrkv/tree-sitter-rescript/pull/218/commits/233734f62375a4eb73a64e506d254addd6a862da

aspeddro commented 1 year ago

~~Highlights updated to not highlight @ in '@' as annotation. https://github.com/nkrkv/tree-sitter-rescript/pull/218/commits/3353315b3973ce630d709e14302143e9382df7d7~~

aspeddro commented 1 year ago

The last commit https://github.com/nkrkv/tree-sitter-rescript/commit/e2af3e7e5873ed1667cf8849ebfa43c7c3c51b55 removed the workaround and fixed the error with characher '@'.

aspeddro commented 1 year ago

Now the scanner will parse the start of the decorator: @ or @@.

nkrkv commented 1 year ago

Brilliant! Thank you!