Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions assets/highlighting-tests/batch.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ REM --- String, Variable, Label, Command, Operator, Number, Delimiter, Comment -
:: Label
:Start


:: Variable assignment and usage
set "VAR1=Hello"
set VAR2=World
Expand All @@ -14,6 +15,9 @@ set "STR=Batch ^& CMD!"
:: Arithmetic operation (number, operator)
set /a SUM=5+10

:: Arguments (variable, string)
echo Message from %0, referred to as "%~n0"

:: IF statement (keyword, operator, string, variable)
if "%VAR1%"=="Hello" (
echo %VAR1%, %VAR2%! %STR%
Expand Down
10 changes: 10 additions & 0 deletions assets/highlighting-tests/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ Reference: ![Logo][logo-ref]
echo "Hello, world" | tr a-z A-Z
```

```batch
@echo off

if not "%~1"=="" (
echo Hello %~1!
) else (
echo Hi, I'm Batch, nice to meet you!
)
```

```javascript
export function greet(name) {
return `hello ${name}`;
Expand Down
56 changes: 56 additions & 0 deletions crates/lsh/definitions/batch.lsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#[display_name = "Batch"]
#[path = "**/*.cmd"]
#[path = "**/*.bat"]
#[path = "**/*.btm"]


pub fn batch() {
until /$/ {
yield other;

if /::.*/ {
yield comment;
}
else if /(?i:rem)\>\s*(.*)/ {
yield keyword.other;
yield $1 as comment;
}
else if /\^./ { // Escapes
yield markup.italic;
}
else if /%%~[fdpnxsatz]{0,6}[A-Za-z]?|%%[A-Za-z]|\%(?:[0-9]|[\w\s]+\%|\*|~[A-Za-z]*[0-9])|![\w\s]+!/ { // What even is a variable anymore
yield variable;
}
else if /:\w+/ {
yield method; // Most suiting out of the options that I could find that looked good
}
else if /"/ {
until /$/ {
yield string;
if /\^./ {
yield markup.italic;
} else if /%%~[fdpnxsatz]{0,6}[A-Za-z]?|%%[A-Za-z]|\%(?:[0-9]|[\w\s]+\%|\*|~[A-Za-z]*[0-9])|![\w\s]+!/ {
yield variable;
} else if /"/ {
yield string;
break;
}
}
} else if /(?i:for|if|else|call|goto|in|do|exist|not)\>/ {
yield keyword.control;
} else if /(?i:assoc|attrib|break|bcdedit|cacls|cd|chcp|chdir|chkdsk|chkntfs|choice|cls|cmd|color|comp|compact|convert|copy|date|del|dir|diskpart|doskey|driverquery|echo|endlocal|erase|exit|fc|find|findstr|format|fsutil|ftype|gpresult|help|icacls|label|md|mkdir|mklink|mode|more|move|openfiles|path|pause|popd|pushd|print|prompt|pushd|rd|recover|config|ren|rename|replace|rmdir|robocopy|set|setlocal|sc|schtasks|shift|shutdown|sort|start|subst|systeminfo|tasklist|taskkill|time|title|tree|type|ver|verify|vol|xcopy|wmic)\>/ { // Finally got the case insensitivity working properly!
yield keyword.other;
}
else if /(?i:-?(?:0x[\da-fA-F_]+|0b[01_]+|0o[0-7_]+|[\d_]+\.?[\d_]*|\.[\d_]+)(?:e[+-]?[\d_]+)?)n?/ {
if /\w+/ {
// Invalid numeric literal
} else {
yield constant.numeric;
}
} else if /\w+/ {
// Gobble word chars to align the next iteration on a word boundary.
}

yield other;
}
}
10 changes: 10 additions & 0 deletions crates/lsh/definitions/markdown.lsh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ pub fn markdown() {
if /.*/ {}
}
}
} else if /(?i:batch|bat)/ {
loop {
await input;
if /\s*```/ {
return;
} else {
batch();
if /.*/ {}
}
}
} else if /(?i:diff)/ {
loop {
await input;
Expand Down