Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
mojo.vim317 linesDownload Raw Back to syntax
1" Vim syntax file2" Language:	Mojo3" Maintainer:	Mahmoud Abduljawad <me@mahmoudajawad.com>4" Last Change:	2023 Sep 095" Credits:	Mahmoud Abduljawad <me@mahmoudajawad.com>6"         	Neil Schemenauer <nas@python.ca>7"		Dmitry Vasiliev8"9"		This is based on Vim Python highlighting10"11"		- introduced highlighting of doctests12"		- updated keywords, built-ins, and exceptions13"		- corrected regular expressions for14"15"		  * functions16"		  * decorators17"		  * strings18"		  * escapes19"		  * numbers20"		  * space error21"22"		- corrected synchronization23"		- more highlighting is ON by default, except24"		- space error highlighting is OFF by default25"26" Optional highlighting can be controlled using these variables.27"28"   let mojo_no_builtin_highlight = 129"   let mojo_no_doctest_code_highlight = 130"   let mojo_no_doctest_highlight = 131"   let mojo_no_exception_highlight = 132"   let mojo_no_number_highlight = 133"   let mojo_space_error_highlight = 134"35" All the options above can be switched on together.36"37"   let mojo_highlight_all = 138"39" The use of Python 2 compatible syntax highlighting can be enforced.40" The straddling code (Python 2 and 3 compatible), up to Python 3.5,41" will be also supported.42"43"   let mojo_use_python2_syntax = 144"45" This option will exclude all modern Python 3.6 or higher features.46"47 48" quit when a syntax file was already loaded.49if exists("b:current_syntax")50  finish51endif52 53" We need nocompatible mode in order to continue lines with backslashes.54" Original setting will be restored.55let s:cpo_save = &cpo56set cpo&vim57 58if exists("mojo_no_doctest_highlight")59  let mojo_no_doctest_code_highlight = 160endif61 62if exists("mojo_highlight_all")63  if exists("mojo_no_builtin_highlight")64    unlet mojo_no_builtin_highlight65  endif66  if exists("mojo_no_doctest_code_highlight")67    unlet mojo_no_doctest_code_highlight68  endif69  if exists("mojo_no_doctest_highlight")70    unlet mojo_no_doctest_highlight71  endif72  if exists("mojo_no_exception_highlight")73    unlet mojo_no_exception_highlight74  endif75  if exists("mojo_no_number_highlight")76    unlet mojo_no_number_highlight77  endif78  let mojo_space_error_highlight = 179endif80 81" These keywords are based on Python syntax highlight, and adds to it struct,82" fn, alias, var, let83"84syn keyword mojoStatement	False None True85syn keyword mojoStatement	as assert break continue del global86syn keyword mojoStatement	lambda nonlocal pass return with yield87syn keyword mojoStatement	class def nextgroup=mojoFunction skipwhite88syn keyword mojoStatement	struct fn nextgroup=mojoFunction skipwhite89syn keyword mojoStatement	alias var let90syn keyword mojoConditional	elif else if91syn keyword mojoRepeat		for while92syn keyword mojoOperator	and in is not or93syn keyword mojoException	except finally raise try94syn keyword mojoInclude		from import95syn keyword mojoAsync		async await96 97" Soft keywords98" These keywords do not mean anything unless used in the right context.99" See https://docs.python.org/3/reference/lexical_analysis.html#soft-keywords100" for more on this.101syn match   mojoConditional   "^\s*\zscase\%(\s\+.*:.*$\)\@="102syn match   mojoConditional   "^\s*\zsmatch\%(\s\+.*:\s*\%(#.*\)\=$\)\@="103 104" Decorators105" A dot must be allowed because of @MyClass.myfunc decorators.106syn match   mojoDecorator	"@" display contained107syn match   mojoDecoratorName	"@\s*\h\%(\w\|\.\)*" display contains=pythonDecorator108 109" Python 3.5 introduced the use of the same symbol for matrix multiplication:110" https://www.python.org/dev/peps/pep-0465/.  We now have to exclude the111" symbol from highlighting when used in that context.112" Single line multiplication.113syn match   mojoMatrixMultiply114      \ "\%(\w\|[])]\)\s*@"115      \ contains=ALLBUT,mojoDecoratorName,mojoDecorator,mojoFunction,mojoDoctestValue116      \ transparent117" Multiplication continued on the next line after backslash.118syn match   mojoMatrixMultiply119      \ "[^\\]\\\s*\n\%(\s*\.\.\.\s\)\=\s\+@"120      \ contains=ALLBUT,mojoDecoratorName,mojoDecorator,mojoFunction,mojoDoctestValue121      \ transparent122" Multiplication in a parenthesized expression over multiple lines with @ at123" the start of each continued line; very similar to decorators and complex.124syn match   mojoMatrixMultiply125      \ "^\s*\%(\%(>>>\|\.\.\.\)\s\+\)\=\zs\%(\h\|\%(\h\|[[(]\).\{-}\%(\w\|[])]\)\)\s*\n\%(\s*\.\.\.\s\)\=\s\+@\%(.\{-}\n\%(\s*\.\.\.\s\)\=\s\+@\)*"126      \ contains=ALLBUT,mojoDecoratorName,mojoDecorator,mojoFunction,mojoDoctestValue127      \ transparent128 129syn match   mojoFunction	"\h\w*" display contained130 131syn match   mojoComment	"#.*$" contains=mojoTodo,@Spell132syn keyword mojoTodo		FIXME NOTE NOTES TODO XXX contained133 134" Triple-quoted strings can contain doctests.135syn region  mojoString matchgroup=mojoQuotes136      \ start=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"137      \ contains=mojoEscape,@Spell138syn region  mojoString matchgroup=mojoTripleQuotes139      \ start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend140      \ contains=mojoEscape,mojoSpaceError,mojoDoctest,@Spell141syn region  mojoRawString matchgroup=mojoQuotes142      \ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"143      \ contains=@Spell144syn region  mojoRawString matchgroup=pythonTripleQuotes145      \ start=+[uU]\=[rR]\z('''\|"""\)+ end="\z1" keepend146      \ contains=pythonSpaceError,mojoDoctest,@Spell147 148syn match   mojoEscape	+\\[abfnrtv'"\\]+ contained149syn match   mojoEscape	"\\\o\{1,3}" contained150syn match   mojoEscape	"\\x\x\{2}" contained151syn match   mojoEscape	"\%(\\u\x\{4}\|\\U\x\{8}\)" contained152" Python allows case-insensitive Unicode IDs: http://www.unicode.org/charts/153syn match   mojoEscape	"\\N{\a\+\%(\s\a\+\)*}" contained154syn match   mojoEscape	"\\$"155 156" It is very important to understand all details before changing the157" regular expressions below or their order.158" The word boundaries are *not* the floating-point number boundaries159" because of a possible leading or trailing decimal point.160" The expressions below ensure that all valid number literals are161" highlighted, and invalid number literals are not.  For example,162"163" - a decimal point in '4.' at the end of a line is highlighted,164" - a second dot in 1.0.0 is not highlighted,165" - 08 is not highlighted,166" - 08e0 or 08j are highlighted,167"168" and so on, as specified in the 'Python Language Reference'.169" https://docs.python.org/reference/lexical_analysis.html#numeric-literals170if !exists("mojo_no_number_highlight")171  " numbers (including complex)172  syn match   mojoNumber	"\<0[oO]\%(_\=\o\)\+\>"173  syn match   mojoNumber	"\<0[xX]\%(_\=\x\)\+\>"174  syn match   mojoNumber	"\<0[bB]\%(_\=[01]\)\+\>"175  syn match   mojoNumber	"\<\%([1-9]\%(_\=\d\)*\|0\+\%(_\=0\)*\)\>"176  syn match   mojoNumber	"\<\d\%(_\=\d\)*[jJ]\>"177  syn match   mojoNumber	"\<\d\%(_\=\d\)*[eE][+-]\=\d\%(_\=\d\)*[jJ]\=\>"178  syn match   mojoNumber179        \ "\<\d\%(_\=\d\)*\.\%([eE][+-]\=\d\%(_\=\d\)*\)\=[jJ]\=\%(\W\|$\)\@="180  syn match   mojoNumber181        \ "\%(^\|\W\)\zs\%(\d\%(_\=\d\)*\)\=\.\d\%(_\=\d\)*\%([eE][+-]\=\d\%(_\=\d\)*\)\=[jJ]\=\>"182endif183 184" The built-ins are added in the same order of appearance in Mojo stdlib docs185" https://docs.modular.com/mojo/lib.html186"187if !exists("mojo_no_builtin_highlight")188  " Built-in functions189  syn keyword mojoBuiltin	slice constrained debug_assert put_new_line print190  syn keyword mojoBuiltin	print_no_newline len range rebind element_type 191  syn keyword mojoBuiltin	ord chr atol isdigit index address string192  " Built-in types193  syn keyword mojoType		Byte ListLiteral CoroutineContext Coroutine DType194  syn keyword mojoType		dtype type invalid bool int8 si8 unit8 ui8 int16 195  syn keyword mojoType		si16 unit16 ui16 int32 si32 uint32 ui32 int64 196  syn keyword mojoType		si64 uint64 ui64 bfloat16 bf16 float16 f16 float32197  syn keyword mojoType		f32 float64 f64 Error FloatLiteral Int Attr SIMD 198  syn keyword mojoType		Int8 UInt8 Int16 UInt16 Int32 UInt32 Int64 UInt64199  syn keyword mojoType		Float16 Float32 Float64 element_type _65x13_type200  syn keyword mojoType		String StringLiteral StringRef Tuple AnyType201  syn keyword mojoType		NoneType None Lifetime202  " avoid highlighting attributes as builtins203  syn match   mojoAttribute	/\.\h\w*/hs=s+1204	\ contains=ALLBUT,mojoBuiltin,mojoFunction,mojoAsync205	\ transparent206endif207 208" From the 'Python Library Reference' class hierarchy at the bottom.209" http://docs.python.org/library/exceptions.html210if !exists("mojo_no_exception_highlight")211  " builtin base exceptions (used mostly as base classes for other exceptions)212  syn keyword mojoExceptions	BaseException Exception213  syn keyword mojoExceptions	ArithmeticError BufferError LookupError214  " builtin exceptions (actually raised)215  syn keyword mojoExceptions	AssertionError AttributeError EOFError216  syn keyword mojoExceptions	FloatingPointError GeneratorExit ImportError217  syn keyword mojoExceptions	IndentationError IndexError KeyError218  syn keyword mojoExceptions	KeyboardInterrupt MemoryError219  syn keyword mojoExceptions	ModuleNotFoundError NameError220  syn keyword mojoExceptions	NotImplementedError OSError OverflowError221  syn keyword mojoExceptions	RecursionError ReferenceError RuntimeError222  syn keyword mojoExceptions	StopAsyncIteration StopIteration SyntaxError223  syn keyword mojoExceptions	SystemError SystemExit TabError TypeError224  syn keyword mojoExceptions	UnboundLocalError UnicodeDecodeError225  syn keyword mojoExceptions	UnicodeEncodeError UnicodeError226  syn keyword mojoExceptions	UnicodeTranslateError ValueError227  syn keyword mojoExceptions	ZeroDivisionError228  " builtin exception aliases for OSError229  syn keyword mojoExceptions	EnvironmentError IOError WindowsError230  " builtin OS exceptions in Python 3231  syn keyword mojoExceptions	BlockingIOError BrokenPipeError232  syn keyword mojoExceptions	ChildProcessError ConnectionAbortedError233  syn keyword mojoExceptions	ConnectionError ConnectionRefusedError234  syn keyword mojoExceptions	ConnectionResetError FileExistsError235  syn keyword mojoExceptions	FileNotFoundError InterruptedError236  syn keyword mojoExceptions	IsADirectoryError NotADirectoryError237  syn keyword mojoExceptions	PermissionError ProcessLookupError TimeoutError238  " builtin warnings239  syn keyword mojoExceptions	BytesWarning DeprecationWarning FutureWarning240  syn keyword mojoExceptions	ImportWarning PendingDeprecationWarning241  syn keyword mojoExceptions	ResourceWarning RuntimeWarning242  syn keyword mojoExceptions	SyntaxWarning UnicodeWarning243  syn keyword mojoExceptions	UserWarning Warning244endif245 246if exists("mojo_space_error_highlight")247  " trailing whitespace248  syn match   mojoSpaceError	display excludenl "\s\+$"249  " mixed tabs and spaces250  syn match   mojoSpaceError	display " \+\t"251  syn match   mojoSpaceError	display "\t\+ "252endif253 254" Do not spell doctests inside strings.255" Notice that the end of a string, either ''', or """, will end the contained256" doctest too.  Thus, we do *not* need to have it as an end pattern.257if !exists("mojo_no_doctest_highlight")258  if !exists("mojo_no_doctest_code_highlight")259    syn region mojoDoctest260	  \ start="^\s*>>>\s" end="^\s*$"261	  \ contained contains=ALLBUT,mojoDoctest,mojoFunction,@Spell262    syn region mojoDoctestValue263	  \ start=+^\s*\%(>>>\s\|\.\.\.\s\|"""\|'''\)\@!\S\++ end="$"264	  \ contained265  else266    syn region mojoDoctest267	  \ start="^\s*>>>" end="^\s*$"268	  \ contained contains=@NoSpell269  endif270endif271 272" Sync at the beginning of class, function, or method definition.273syn sync match mojoSync grouphere NONE "^\%(def\|class\)\s\+\h\w*\s*[(:]"274 275" The default highlight links.  Can be overridden later.276hi def link mojoStatement		Statement277hi def link mojoConditional		Conditional278hi def link mojoRepeat			Repeat279hi def link mojoOperator		Operator280hi def link mojoException		Exception281hi def link mojoInclude			Include282hi def link mojoAsync			Statement283hi def link mojoDecorator		Define284hi def link mojoDecoratorName		Function285hi def link mojoFunction		Function286hi def link mojoComment			Comment287hi def link mojoTodo			Todo288hi def link mojoString			String289hi def link mojoRawString		String290hi def link mojoQuotes			String291hi def link mojoTripleQuotes		mojoQuotes292hi def link mojoEscape			Special293if !exists("mojo_no_number_highlight")294  hi def link mojoNumber		Number295endif296if !exists("mojo_no_builtin_highlight")297  hi def link mojoBuiltin		Function298  hi def link mojoType			Type299endif300if !exists("mojo_no_exception_highlight")301  hi def link mojoExceptions		Structure302endif303if exists("mojo_space_error_highlight")304  hi def link mojoSpaceError		Error305endif306if !exists("mojo_no_doctest_highlight")307  hi def link mojoDoctest		Special308  hi def link mojoDoctestValue	Define309endif310 311let b:current_syntax = "mojo"312 313let &cpo = s:cpo_save314unlet s:cpo_save315 316" vim:set sw=2 sts=2 ts=8 noet:317 
codekingpro/portable-devtools · Team Ai