uben0 / tree-sitter-typst

Tree Sitter grammar for Typst
MIT License
114 stars 10 forks source link

Helix `unreachable src/scanner.c` #20

Closed Ciflire closed 7 months ago

Ciflire commented 9 months ago

Hi, There seems to be an issue in helix (didn't try with other terminal editor such as vim/nvim), i'm guessing it's from the grammar, i tried to deactivate both lsp and formatter, still had the issue, and there is a src/scanner.c file in the repo. I installed the grammar by cloning and symlinking the right files to the right place just as explained in the readme. Updated to master but nothing changed, tried with konsole kitty wezterm and tty. This is the issue, it's popping whenever it's loading the grammar scrscanner

uben0 commented 9 months ago

Yes, it is a debugging check in this grammar. It means the grammar contains a bug, as those print statements are placed whenever a situation should be unreachable.

You can silence those messages by removing in the src/scanner.c the #define DEBUG macro. I am thinking about changing how to report unexpected behaviors. Because those messages are annoying, but in the other hand, they are good bug detectors.

I will comment the #define DEBUG in order to distribute only a silent implementation. I will investigate the bug in question, but I need you to give me the content of the file that causes those prints. I need to be able to reproduce it on my machine.

Ciflire commented 9 months ago

I had no c/cpp compiler, installing one made it so i can update the grammar and resolving this issue. I curious to know how the grammar was still working before i installed a compiler, just giving that error in stdout. So it's fixed for me at this point, but that's still wierd

uben0 commented 9 months ago

I made a commit that removes the print statement.

"No C compiler" yes it is strange, I know Helix ships its officially supported grammars, already compiled. But this grammar is not yet in the official list, but it will starting from the next Helix release.

Can you give the content (if it's not personal) of the main.typ ? Because it is the only way for me to reproduce the bug.

Ciflire commented 9 months ago

test.zip Hopefully you can compile it, if it's not the case just tell me i'll try to put this on a github. There is a template with some macros in it And yes i just have local compiler installations (using nixos and devshells here)

uben0 commented 9 months ago

I tested it and could not reproduce the error messages. But the unreachable code being triggered here strongly reminded me of a bug I fixed two commit ago (ecf8596336857adfcd5f7cbb3b2aa11a67badc37). I tried parsing your document with the version before this fix and I got the exact same error message (unreachable 237 and 1055).

Maybe I'm wrong, but I'm quite confident you are running a version of the parser that came before the fix. If you want to update the parser, then execute again helix --grammar fetch and helix --grammar build. I believe it will fetch the latest version from github.

Tell me if this is fixing the problem.