Add syntax docu, add VimL, CMake, INI, LESS syntax

closes #99
closes #106
This commit is contained in:
sharkdp 2018-05-18 19:35:45 +02:00 committed by David Peter
parent 5e3b17e6f7
commit 54a331d162
9 changed files with 181 additions and 0 deletions

12
.gitmodules vendored
View File

@ -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

31
assets/README.md Normal file
View File

@ -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.

Binary file not shown.

1
assets/syntaxes/CMake Submodule

@ -0,0 +1 @@
Subproject commit ff9a800a4ca942edd095de553ca05fba03b02275

1
assets/syntaxes/INI Submodule

@ -0,0 +1 @@
Subproject commit 8dd3e316ada5cc8bffd3982bc2a9384345729f34

View File

@ -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

1
assets/syntaxes/LESS Submodule

@ -0,0 +1 @@
Subproject commit 50f4255d778320ce6a542e996ba8645266460b4f

1
assets/syntaxes/VimL Submodule

@ -0,0 +1 @@
Subproject commit b453aff6f783769b6b895986da605a2db0db7379

View File

@ -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