rhaiscript / lsp

Language server for Rhai.
Apache License 2.0
43 stars 4 forks source link

Shebang fails with Rhai engine #43

Closed tamasfe closed 2 years ago

tamasfe commented 2 years ago

I pulled in the rhai engine in order to test the compliance of the parser (and later the HIR), but Engine::compile(...) seems to fail if the scripts starts with a shebang line with the error of #! being reserved.

According to the book, eval_file supports shebangs, is this a bug or do I need to strip the line manually before passing the script to compile?

I'm not sure if I should open this in the Rhai repo.

tamasfe commented 2 years ago

/cc @schungx

schungx commented 2 years ago

Yes, the shebang is only handled when reading script files. You'd need to strip it off manually if working with a script in string form.

It may be useful to handle it globally, but it may introduce subtle errors where multiple pieces of texts are joined together in order to form a single script. For example:

Script 1:

print(`This is a shebang:

Script 2:

#! /usr/bin/rhai-run
`);

Rhai currently allows you to specify a slice of strings to join together as a single script via Engine::compile_scripts_with_scope.

What do you think?

tamasfe commented 2 years ago

Alright thanks, it makes perfect sense. I'll just strip it then.