Skip to content

Add support for Batch highlighting#879

Draft
chorgard wants to merge 3 commits into
microsoft:mainfrom
chorgard:add_batch_highlighting
Draft

Add support for Batch highlighting#879
chorgard wants to merge 3 commits into
microsoft:mainfrom
chorgard:add_batch_highlighting

Conversation

@chorgard

@chorgard chorgard commented Jun 18, 2026

Copy link
Copy Markdown

WIP - Only in draft mode currently

Summary

Adds initial Batch syntax highlighting support (definition at crates/lsh/definitions/batch.lsh) and more content under the batch sample file at assets/highlighting-tests/batch.bat. The syntax highlighting now applies to *.bat, *.cmd, and *.btm.

Support for Batch syntax highlighting was also implemented into markdown, adding code to crates/lsh/definitions/markdown.Ish and adding a simple demonstration of this in assets/highlighting-tests/markdown.md

Screenshot

image

These results can be reproduced with cargo build & target\debug\edit.exe assets\highlighting-tests\batch.bat or cargo run -p lsh-bin -- render --input ./assets/highlighting-tests/batch.bat ./crates/lsh/definitions/ (This one not shown in screenshot).
Tested on a Windows 11 Pro machine.

Scope

No dependencies were added; the highlighter only uses the preexisting LSH engine.

The highlighting covers many common Batch features, such as (not limited to):

  • Commands
  • Comments
  • Variables (including delayed expansion)
  • Arguments
  • Strings (& Character escapes)
  • Numeric literals
  • Control keywords

Edit 6/18/26 Pt 1:

  • Fixed false command inclusions ("exe", "ctrl", "acl", etc.)
    • Most likely caused by acronyms stdout-ed by the help command (my source for all of the commands included) that were in capital characters (I sorted through the help command's output for words in all CAPS to get the commands).

Edit 6/18/26 Pt 2:

  • Fixed the keyword & command highlighting RegEx to properly utilize ?i:, effectively halving the associated code.
  • Refined RegExp for all kinds of variables, also adding support for FOR-LOOP variable operations (modifiers) (e.g., %%~nF, %%~dpF)
  • Fixed REM comments not highlighting until at least one whitespace is suffixed (now treated more like the other commands, highlighting normally)
  • Re-formatted the entire batch language definition file to use tabulations instead of inconsistently placed whitespaces for indentation and formatting.

P.S.: This is my first true PR ever! Edit as you need, but please provide constructive criticism; I need it!

@chorgard

Copy link
Copy Markdown
Author

Please fix the command highlighting first, if you do edit. As you could probably tell, I had a very difficult time using ?i:, so I just made a workaround. I'm assuming that nobody writes WoBbLy code.

@chorgard

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@microsoft-github-policy-service agree

@chorgard chorgard marked this pull request as draft June 18, 2026 23:45
@chorgard chorgard marked this pull request as ready for review June 19, 2026 03:06
@chorgard chorgard marked this pull request as draft June 19, 2026 03:06
Make figure out the `?i:` situation and boil down the variable regex, and in doing so, reformat the document.
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