diff --git a/.gitmodules b/.gitmodules index 2ac8634e..af9bf1fa 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,3 +19,15 @@ [submodule "assets/syntaxes/Docker"] path = assets/syntaxes/Docker url = https://github.com/asbjornenge/Docker.tmbundle +[submodule "assets/syntaxes/VimL"] + path = assets/syntaxes/VimL + url = https://github.com/SalGnt/Sublime-VimL +[submodule "assets/syntaxes/INI"] + path = assets/syntaxes/INI + url = https://github.com/clintberry/sublime-text-2-ini +[submodule "assets/syntaxes/CMake"] + path = assets/syntaxes/CMake + url = https://github.com/zyxar/Sublime-CMakeLists +[submodule "assets/syntaxes/LESS"] + path = assets/syntaxes/LESS + url = https://github.com/danro/LESS-sublime diff --git a/assets/README.md b/assets/README.md new file mode 100644 index 00000000..6139e124 --- /dev/null +++ b/assets/README.md @@ -0,0 +1,31 @@ +## Syntax Highlighting in bat + +`bat` uses the [syntect](https://github.com/trishume/syntect) library to highlight source +code. As a basis, syntect uses [Sublime Text](https://www.sublimetext.com/) syntax definitions +in the `.sublime-syntax` format. + +In order to add new syntaxes to `bat`, follow these steps: + +1. Find a Sublime Text syntax for the given language, preferably in a separate Git repository + which can be included as a submodule (under `assets/syntaxes`). + +2. If the Sublime Text syntax is only available as a `.tmLanguage` file, open the file in + Sublime Text and convert it to a `.sublime-syntax` file via *Tools* -> *Developer* -> + *New Syntax from XXX.tmLanguage...*. Save the new file in the `assets/syntaxes` folder. + +3. Run the `create.sh` script. It calls `bat cache --init` to parse all available + `.sublime-syntax` files and serialize them to a `syntaxes.bin` file (in this folder). + +4. Re-compile `bat`. At compilation time, the `syntaxes.bin` file will be stored inside the + `bat` binary. + +### Troubleshooting + +Make sure that the local cache does not interfere with the internally stored syntaxes and +themes (`bat cache --clear`). + +### Manual modifications + +The following files have been manually modified after converting from a `.tmLanguage` file: + +* `VimL.sublime-syntax` => added `.vimrc` file type. diff --git a/assets/syntaxes.bin b/assets/syntaxes.bin index 62dcaebf..7c4abe26 100644 Binary files a/assets/syntaxes.bin and b/assets/syntaxes.bin differ diff --git a/assets/syntaxes/CMake b/assets/syntaxes/CMake new file mode 160000 index 00000000..ff9a800a --- /dev/null +++ b/assets/syntaxes/CMake @@ -0,0 +1 @@ +Subproject commit ff9a800a4ca942edd095de553ca05fba03b02275 diff --git a/assets/syntaxes/INI b/assets/syntaxes/INI new file mode 160000 index 00000000..8dd3e316 --- /dev/null +++ b/assets/syntaxes/INI @@ -0,0 +1 @@ +Subproject commit 8dd3e316ada5cc8bffd3982bc2a9384345729f34 diff --git a/assets/syntaxes/INI.sublime-syntax b/assets/syntaxes/INI.sublime-syntax new file mode 100644 index 00000000..024a3215 --- /dev/null +++ b/assets/syntaxes/INI.sublime-syntax @@ -0,0 +1,43 @@ +%YAML 1.2 +--- +# http://www.sublimetext.com/docs/3/syntax.html +name: INI +file_extensions: + - ini + - INI + - inf + - INF + - reg + - REG + - lng + - cfg + - CFG + - url + - URL + - .editorconfig +scope: source.ini +contexts: + main: + - match: ^\s*(;|#).*$\n? + scope: comment.line.semicolon.ini + captures: + 1: punctuation.definition.comment.ini + - match: '^\s*(\[)(.*?)(\])' + scope: meta.tag.section.ini + captures: + 1: punctuation.definition.section.ini + 2: entity.section.ini + 3: punctuation.definition.section.ini + - match: '^(\s*(["'']?)(.+?)(\2)\s*(=))?\s*((["'']?)(.*?)(\7))\s*(;.*)?$\n?' + scope: meta.declaration.ini + captures: + 1: meta.property.ini + 2: punctuation.definition.quote.ini + 3: keyword.name.ini + 4: punctuation.definition.quote.ini + 5: punctuation.definition.equals.ini + 6: meta.value.ini + 7: punctuation.definition.quote.ini + 8: string.name.value.ini + 9: punctuation.definition.quote.ini + 10: comment.declarationline.semicolon.ini diff --git a/assets/syntaxes/LESS b/assets/syntaxes/LESS new file mode 160000 index 00000000..50f4255d --- /dev/null +++ b/assets/syntaxes/LESS @@ -0,0 +1 @@ +Subproject commit 50f4255d778320ce6a542e996ba8645266460b4f diff --git a/assets/syntaxes/VimL b/assets/syntaxes/VimL new file mode 160000 index 00000000..b453aff6 --- /dev/null +++ b/assets/syntaxes/VimL @@ -0,0 +1 @@ +Subproject commit b453aff6f783769b6b895986da605a2db0db7379 diff --git a/assets/syntaxes/VimL.sublime-syntax b/assets/syntaxes/VimL.sublime-syntax new file mode 100644 index 00000000..a45766f2 --- /dev/null +++ b/assets/syntaxes/VimL.sublime-syntax @@ -0,0 +1,91 @@ +%YAML 1.2 +--- +# http://www.sublimetext.com/docs/3/syntax.html +name: VimL +file_extensions: + - vim + - .vimrc +scope: source.viml +contexts: + main: + - include: comment + - include: string_quoted_double + - include: string_quoted_single + - include: string_regex + - include: inline_comment + - include: number_int + - include: number_hex + - include: keyword + - include: support_function + - include: support_variable + - include: support_type + - include: function_params + - include: function_definition + - include: function_call + - include: function + - include: variable + - include: expr + comment: + - match: ^\s*".*$ + scope: comment.line.quotes.viml + captures: + 1: punctuation.definition.comment.vim + expr: + - match: (\|\||&&|==(\?|#)?|(!|>|<)=(#|\?)?|(=|!)~(#|\?)?|(>|<)(#|\?)is|isnot|\.|\*|\\|%) + scope: storage.function.viml + function: + - match: \b(fu(n|nction)?|end(f|fu|fun|function)?)\b + scope: storage.function.viml + function_call: + - match: '(([sgbwtl]|)?:?[0-9a-zA-Z_#]+)(?=\()' + scope: support.function.any-method + function_definition: + - match: '^\s*(function)\s*!?\s+(?=(s:)?[0-9a-zA-Z_#]+\s*\()' + captures: + 1: storage.function.viml + push: + - meta_scope: meta.function.viml + - match: (\() + captures: + 1: punctuation.definition.parameters.begin.viml + pop: true + - match: "(s:)?[0-9a-zA-Z_#]+" + scope: entity.name.function.viml + function_params: + - match: '-\w+=' + scope: support.type.viml + inline_comment: + - match: '(?!\$)(")(?!\{).*$\n?' + scope: comment.line.quotes.viml + captures: + 1: punctuation.definition.comment.vim + keyword: + - match: \b(if|while|for|try|return|throw|end(if|for|while|try)?|au(g|group)|else(if|)?|do|in|catch|finally|:)\b + scope: keyword.control.viml + number_hex: + - match: "#[0-9a-f]{6}" + scope: constant.numeric.hex + number_int: + - match: '-?\d+' + scope: constant.numeric.integer + string_quoted_double: + - match: '"(\\\\|\\"|\n[^\S\n]*\\|[^\n"])*"' + scope: string.quoted.double.viml + string_quoted_single: + - match: '''(''''|\n[^\S\n]*\\|[^\n''])*''' + scope: string.quoted.single.viml + string_regex: + - match: '/(\\\\|\\/|\n[^\S\n]*\\|[^\n/])*/' + scope: string.regexp.viml + support_function: + - match: \b(set(local|global)?|let|command|filetype|colorscheme|\w*map|\w*a(b|brev)?|syn|exe(c|cute)?|ec(ho|)?|au(tocmd|)?)\b + scope: support.function.viml + support_type: + - match: <.*?> + scope: support.type.viml + support_variable: + - match: '\b(am(enu|)?|(hl|inc)?search|[Bb]uf([Nn]ew[Ff]ile|[Rr]ead)?|[Ff]ile[Tt]ype)\b' + scope: support.variable.viml + variable: + - match: '([sSgGbBwWlLaAvV]:|@|$|&(?!&))\w*' + scope: variable.other.viml