mirror of
				https://github.com/sharkdp/bat.git
				synced 2025-10-29 22:24:35 +00:00 
			
		
		
		
	Add syntax docu, add VimL, CMake, INI, LESS syntax
closes #99 closes #106
This commit is contained in:
		
							
								
								
									
										31
									
								
								assets/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								assets/README.md
									
									
									
									
									
										Normal 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
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								assets/syntaxes/CMake
									
									
									
									
									
										Submodule
									
								
							 Submodule assets/syntaxes/CMake added at ff9a800a4c
									
								
							
							
								
								
									
										1
									
								
								assets/syntaxes/INI
									
									
									
									
									
										Submodule
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								assets/syntaxes/INI
									
									
									
									
									
										Submodule
									
								
							 Submodule assets/syntaxes/INI added at 8dd3e316ad
									
								
							
							
								
								
									
										43
									
								
								assets/syntaxes/INI.sublime-syntax
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								assets/syntaxes/INI.sublime-syntax
									
									
									
									
									
										Normal 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
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								assets/syntaxes/LESS
									
									
									
									
									
										Submodule
									
								
							 Submodule assets/syntaxes/LESS added at 50f4255d77
									
								
							
							
								
								
									
										1
									
								
								assets/syntaxes/VimL
									
									
									
									
									
										Submodule
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								assets/syntaxes/VimL
									
									
									
									
									
										Submodule
									
								
							 Submodule assets/syntaxes/VimL added at b453aff6f7
									
								
							
							
								
								
									
										91
									
								
								assets/syntaxes/VimL.sublime-syntax
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										91
									
								
								assets/syntaxes/VimL.sublime-syntax
									
									
									
									
									
										Normal 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 | ||||
		Reference in New Issue
	
	Block a user