jeff-hykin / better-shell-syntax

💾 📦 ♻️ An improvement to the shell syntax for VS Code
MIT License
50 stars 4 forks source link

Heredoc robustness suggestion #89

Closed wdeshazer closed 1 month ago

wdeshazer commented 1 month ago

The Heredoc Regex isn't robust

tput -S <<!
> clear
> cup 10 10
> bold
> !

This heredoc was extracted from the tput man page. It fails to recognize the closing delimiter. I have looked through the shell.tmLanguage.json and believe that the following regex for the heredoc begin and end:

 "repository.heredoc.patterns[].@.begin": "(?:((?<!<)(?:<<-))(?:[ \\t]*+)(\"|')(?:[ \\t]*+)([^\"']+?)(?=\\s|;|&|<|\"|')((?:\\2))(.*))",
"repository.heredoc.patterns[].@.end": "(?:(?:^\\t*)(?:\\3)(?=\\s|;|&|$))",

would be more robust with one that only sought the delimiter \\3. I preserved the further specificity of (?=\\s|;|&|$) although, I don't know if the heredoc strictly requires that per its specification. I'll look that up.

"repository.heredoc.patterns[].@.begin": "(?:((?<!<)(?:<<-))(?:[ \\t]*+)(\"|')(?:[ \\t]*+)([^\"']+?)(?=\\s|;|&|<|\"|')((?:\\2))(.*))",
"repository.heredoc.patterns[].@.end": "(?:\\3)(?=\\s|;|&|$)"

I have a short term question and a long term question. Short term, what is the easiest way to get this in the my environment. Can I overwrite that path in my setting.json. Second, would you prefer to handle this or would you prefer a PR. I read through the documentation and the setup. I would have to work it within my priorities. But I could work this one and Issue #88 if you would like. I have not looked at that one yet, but I'll will soon and attempt to propose a solution rather than just throw an issue at you.

Regards,

Will

wdeshazer commented 1 month ago

Closing the issue. I should have read the Heredoc specification before posting. The > are just prompts for illustrating command line entering of tput commands. I am still affected by #88 though.

wdeshazer commented 1 month ago

Heredoc basic syntax

[COMMAND] <<[-] 'DELIMITER'
  HERE-DOCUMENT
DELIMITER
jeff-hykin commented 1 month ago

(?=\\s|;|&|$)

Stuff like this is purely/generally a hack to get things working in Textmate.

what is the easiest way to get this in the my environment

I thought the contributing.md covers it but I could be wrong so I'll give a TLDR. Fork/clone, install dependencies (ruby, and the textmate_grammar_builder (name might be slightly different) gem), edit the main.rb how you like, run commands/build, then open VS Code command pallet "Debug Extension", it'll open a new VS Code window, open shell code inside that new window, it'll use the new highlighter. Use VS Command pallet "TM Scopes" (or "TM tokens" or something of that nature) and move cursor over parts of the code to debug the labels given at each char.

attempt to propose a solution rather than just throw an issue at you.

Always appreciated. Even when I don't accept a PR, for example when someone edits the .tmLanguage.json directly even though its a generated file, it almost always saves me a good bit a time when actually fixing the problem. So PR's are always welcome.

I will say, Textmate sucks, so fixing simple things are often x10 harder than they should be. Theres a lot of up front cost to learning the quirks of the Textmate parser just to fix something simple.