Skip to content

Instantly share code, notes, and snippets.

@Vftdan
Last active Feb 9, 2021
Embed
What would you like to do?
Lambda expression vim syntax
" Vim syntax file
if !exists("main_syntax")
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
let main_syntax = 'lambda'
endif
if version < 508
command! -nargs=+ LambdaHiLink highlight link <args>
else
command! -nargs=+ LambdaHiLink highlight default link <args>
endif
syn match lambdaError /\v\(\s*\)|[λ.\(\)]/
syn match lambdaConst /[0-9]/ containedin=lambdaIdentShort,lambdaIdentLong
syn match lambdaIdentShort /\v[^ .\\λ\(\)\=\[\]]|([.\\λ\(]|^)@<=\s*(\=|≡)/
syn region lambdaIdentLong matchgroup=lambdaNoise start='{' end='}'
syn match lambdaAssign /\v[\.\( \r\n\t]@<=\s*\zs(\=|≡)/
syn match lambdaSubstError /\]/ contained
syn region lambdaSubst matchgroup=lambdaSubstBracket start=/\[/ end=/\]/ contains=lambdaSubstLeft containedin=@lambdaExprNoErr
syn region lambdaSubstLeft start=/./ end=/\ze\\\s*[^\\]\+\]/ contains=@lambdaExpr,lambdaSubstError contained nextgroup=lambdaSubstRight
syn region lambdaSubstRight matchgroup=lambdaSubstSlash start=/\\/ matchgroup=lambdaSubstBracket end=/\ze\]/ contains=@lambdaIdent contained
syn region lambdaSKITransform matchgroup=lambdaSKITransformBracket start=/\(T\|elim\.\s*[^ ]\s*\)\[/ end=/\]/ contains=@lambdaExprNoErr containedin=@lambdaExprNoErr transparent
syn region lambdaArgs matchgroup=lambdaLamda start=/\v\\/ matchgroup=lambdaDot end=/\V./ contains=@lambdaIdent contained
syn region lambdaBracketed matchgroup=lambdaParenthesis start=/\v\(\ze\s*[^ )]/ end=/\V)/ contains=@lambdaExpr
" )/
" This comment stops incorrect highlighting caused by very magic
syn region lambdaFunction start=/\v\ze(\\|λ)\s*([^ \r\n\t\).][^\r\n.]{-})?\.\s*[^ \r\n\t\)]+/ end=/\ze\v([\)\]\=]|$)/ contains=lambdaArgs,@lambdaExpr transparent
syn cluster lambdaExpr contains=@lambdaExprNoErr,lambdaError
syn cluster lambdaExprNoErr contains=lambdaBracketed,@lambdaIdent,lambdaFunction
syn cluster lambdaIdent contains=lambdaIdentShort,lambdaIdentLong
syn region lambdaLineComment start=/--/ skip=/\\\n/ end=/\ze$/
syn region lambdaBlockComment start=/{-/ skip=/\\./ end=/-}/ contains=lambdaBlockComment
LambdaHiLink lambdaAssign Statement
LambdaHiLink lambdaSKITransformBracket Statement
LambdaHiLink lambdaLamda PreProc
LambdaHiLink lambdaDot PreProc
LambdaHiLink lambdaParenthesis Delimiter
LambdaHiLink lambdaIdentShort Identifier
LambdaHiLink lambdaIdentLong Identifier
LambdaHiLink lambdaNoise Noise
LambdaHiLink lambdaConst Constant
LambdaHiLink lambdaSubstError lambdaError
LambdaHiLink lambdaError Error
LambdaHiLink lambdaLineComment Comment
LambdaHiLink lambdaBlockComment Comment
LambdaHiLink lambdaSubstBracket PreProc
LambdaHiLink lambdaSubstSlash PreProc
delcommand LambdaHiLink
setlocal matchpairs=(:),{:},[:],λ:.
setlocal commentstring=--%s
let b:current_syntax = "lambda"
if main_syntax ==# 'lambda'
unlet main_syntax
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment