Skip to content

Commit

Permalink
pike.vim: Improve preprocessor formatting (more detail).
Browse files Browse the repository at this point in the history
  • Loading branch information
BuGlessRB committed Jan 16, 2018
1 parent 12b5220 commit fd73e56
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 49 deletions.
12 changes: 10 additions & 2 deletions runtime/syntax/autodoc.vim
@@ -1,13 +1,18 @@
" Vim syntax file
" Language: Autodoc
" Maintainer: Stephen R. van den Berg <srb@cuci.nl>
" Last Change: 2018 Jan 09
" Last Change: 2018 Jan 16
" Version: 2.2
" Remark: Included by pike.vim

" Quit when a (custom) syntax file was already loaded
if exists("b:current_syntax")
finish
endif

let s:cpo_save = &cpo
set cpo&vim

syn case match

" A bunch of useful autodoc keywords
Expand Down Expand Up @@ -64,7 +69,10 @@ hi def link autodocAtStmtAcc Identifier
hi def link autodocLink Type
hi def link autodocTodo Todo
hi def link autodocSpaceError Error
hi def link autodocLineStart Comment
hi def link autodocLineStart SpecialComment

let b:current_syntax = "autodoc"

let &cpo = s:cpo_save
unlet s:cpo_save
" vim: ts=8
103 changes: 56 additions & 47 deletions runtime/syntax/pike.vim
@@ -1,13 +1,13 @@
" Vim syntax file
" Language: Pike
" Maintainer: Stephen R. van den Berg <srb@cuci.nl>
" Last Change: 2018 Jan 12
" Version: 2.1

" Derived from the C-syntax; fixed several bugs in the C-syntax
" and extended it with the Pike syntax.
" Includes a highlighter for SQL on multiline strings.
" Includes a highlighter for all types of parenthesis errors, Pike style.
" Last Change: 2018 Jan 16
" Version: 2.2
" Remark: Derived from the C-syntax; fixed several bugs in the C-syntax
" Remark: and extended it with the Pike syntax.
" Remark: Includes a highlighter for all Pike types of parenthesis errors.
" Remark: Includes a highlighter for SQL on multiline strings.
" Remark: Includes a highlighter for any embedded Autodoc format.

" Quit when a (custom) syntax file was already loaded
if exists("b:current_syntax")
Expand All @@ -33,10 +33,9 @@ packadd! matchit
let b:match_words = "({:}\\@1<=),(\\[:]\\@1<=),(<:>\\@1<=),^\s*#\s*\%(if\%(n\?def\)\|else\|el\%(se\)\?if\|endif\)\>"

" A bunch of useful Pike keywords
syn keyword pikeStatement break return continue
syn keyword pikeDebug gauge backtrace describe_backtrace werror _Static_assert static_assert
syn keyword pikeException error catch throw
syn keyword pikeLabel case default
syn keyword pikeLabel case default break return continue
syn keyword pikeConditional if else switch
syn keyword pikeRepeat while for foreach do

Expand Down Expand Up @@ -77,7 +76,7 @@ syn keyword pikeTodo contained TODO FIXME XXX

" Match parengroups: allows for highlighting indices of mappings and
" highlighting semicolons that are out of place due to a paren imbalance
syn cluster pikePreShort contains=pikeDefine,pikePreProc,pikeCppOutWrapper,pikeCppInWrapper
syn cluster pikePreShort contains=pikeDefine,pikePreProc,pikeCppOutWrapper,pikeCppInWrapper,pikePreCondit,pikePreConditMatch
syn cluster pikeExprGroup contains=@pikeMappElm,pikeMappIndex,@pikeStmt,pikeStmts,@pikeExpr,pikeColon,pikeDoublecolon,pikeSemicolon,pikeComma,pikeNest,pikeBadClose,pikeTypeCast
syn match pikeWord transparent display contained /[^()'"[\]{},;:]\+/ contains=ALLBUT,@pikePreProcGroup,@pikeExprGroup
syn match pikeFirstWord transparent display contained /^\s*#[^()'"[\]{},;:]\+/ contains=@pikePreShort
Expand Down Expand Up @@ -123,11 +122,11 @@ if !exists("c_no_cformat")
" Highlight % items in strings.
syn match pikeFormat display "%\%(\d\+\$\)\=[-+' #0*]*\%(\d*\|\*\|\*\d\+\$\)\%(\.\%(\d*\|\*\|\*\d\+\$\)\)\=\%([hlLjzt]\|ll\|hh\)\=\%([aAbdiuoxXDOUfFeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained
syn match pikeFormat display "%%" contained
syn region pikeString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=pikeSpecial,pikeFormat,@Spell keepend
syn region pikeString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=pikeSpecial,pikeDelimiterDQ,pikeFormat,@Spell keepend
syn region pikeMlString start=+#"+ skip=+\\\\\|\\"+ end=+"+ contains=pikeSpecial,pikeFormat,@Spell,pikeEmbeddedString keepend
else
syn region pikeString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=pikeSpecial,@Spell
syn region pikeMlString transparent start=+#"+ skip=+\\\\\|\\"+ end=+"+ contains=pikeSpecial,@Spell,pikeBindings,pikeEmbeddedString keepend
syn region pikeString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=pikeSpecial,pikeDelimiterDQ,@Spell
syn region pikeMlString transparent start=+#"+ skip=+\\\\\|\\"+ end=+"+ contains=pikeSpecial,pikeDelimiterDQ,@Spell,pikeBindings,pikeEmbeddedString keepend
endif

" FIXME This is supposed to match full lines in the multiline pikeMlString
Expand All @@ -136,9 +135,11 @@ syn region pikeEmbeddedString display contained start=+^.*+ end=++ contains=@pik

syn match pikeBindings display contained ":\@1<!:[A-Za-z][_A-Za-z0-9]*"

syn match pikeCharacter "'[^\\]'"
syn match pikeCharacter "'[^']*'" contains=pikeSpecial
syn match pikeCharacter "'[^\\']'" contains=pikeDelimiterSQ
syn match pikeCharacter "'[^']*'" contains=pikeSpecial,pikeDelimiterSQ
syn match pikeSpecialError "'\\[^'\"?\\abefnrtv]'"
syn match pikeDelimiterDQ display +"+ contained
syn match pikeDelimiterSQ display +'+ contained
syn match pikeSpecialCharacter "'\\['\"?\\abefnrtv]'"
syn match pikeSpecialCharacter display "'\\\o\+'"
syn match pikeSpecialCharacter display "'\\x\x*'"
Expand All @@ -159,11 +160,11 @@ syn case ignore
syn match pikeNumbers display transparent "\<\d\|\.\d" contains=pikeNumber,pikeFloat,pikeOctalError,pikeOctal
" Same, but without octal error (for comments)
syn match pikeNumbersCom display contained transparent "\<\d\|\.\d" contains=pikeNumber,pikeFloat,pikeOctal
syn match pikeNumber display contained "\d\+\%(u\=l\{0,2}\|ll\=u\)\>"
syn match pikeNumber display contained "\<\d\+\%(u\=l\{0,2}\|ll\=u\)\>"
"hex number
syn match pikeNumber display contained "0x\x\+\%(u\=l\{0,2}\|ll\=u\)\>"
syn match pikeNumber display contained "\<0x\x\+\%(u\=l\{0,2}\|ll\=u\)\>"
" Flag the first zero of an octal number as something special
syn match pikeOctal display contained "0\o\+\%(u\=l\{0,2}\|ll\=u\)\>" contains=pikeOctalZero
syn match pikeOctal display contained "\<0\o\+\%(u\=l\{0,2}\|ll\=u\)\>" contains=pikeOctalZero
syn match pikeOctalZero display contained "\<0"
syn match pikeFloat display contained "\d\+f"
"floating point number, with dot, optional exponent
Expand Down Expand Up @@ -248,11 +249,12 @@ syn keyword pikeConstant __REAL_BUILD__ _REAL_MAJOR__ __REAL_MINOR__
syn keyword pikeConstant __REAL_VERSION__ __PIKE__ UNDEFINED

" These should actually only be parsed in preprocessor conditionals
syn keyword pikeOperator defined constant efun _Pragma
syn keyword pikeCppOperator contained defined constant efun _Pragma

syn keyword pikeBoolean true false

syn region pikePreCondit start="^\s*\zs#\s*\%(if\%(n\?def\)\?\|el\%(se\)\?if\)\>" skip="\\$" end="$" keepend contains=pikeComment,pikeCommentL,pikeString,pikeCharacter,pikeNumbers,pikeCommentError,pikeSpaceError
syn match pikeCppPrefix display "^\s*\zs#\s*[a-z]\+" contained
syn region pikePreCondit start="^\s*\zs#\s*\%(if\%(n\?def\)\?\|el\%(se\)\?if\)\>" skip="\\$" end="$" transparent keepend contains=pikeString,pikeCharacter,pikeNumbers,pikeCommentError,pikeSpaceError,pikeCppOperator,pikeCppPrefix
syn match pikePreConditMatch display "^\s*\zs#\s*\%(else\|endif\)\>"
if !exists("c_no_if0")
syn cluster pikeCppOutInGroup contains=pikeCppInIf,pikeCppInElse,pikeCppInElse2,pikeCppOutIf,pikeCppOutIf2,pikeCppOutElse,pikeCppInSkip,pikeCppOutSkip
Expand All @@ -275,13 +277,12 @@ if !exists("c_no_if0")
syn region pikeCppOutSkip contained start="^\s*#\s*if\%(n\?def\)\?\>" skip="\\$" end="^\s*#\s*endif\>" contains=pikeSpaceError,pikeCppOutSkip
syn region pikeCppInSkip contained matchgroup=pikeCppInWrapper start="^\s*#\s*\%(if\s\+\%(\d\+\s*\%($\|//\|/\*\||\|&\)\)\@!\|ifn\?def\>\)" skip="\\$" end="^\s*#\s*endif\>" containedin=pikeCppOutElse,pikeCppInIf,pikeCppInSkip contains=TOP,pikePreProc
endif
syn region pikeIncluded display contained start=+"+ skip=+\\\\\|\\"+ end=+"+
syn region pikeIncluded display contained start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=pikeDelimiterDQ keepend
syn match pikeIncluded display contained "<[^>]*>"
syn match pikeInclude display "^\s*\zs#\s*include\>\s*["<]" contains=pikeIncluded
"syn match pikeLineSkip "\\$"
syn cluster pikePreProcGroup contains=pikePreCondit,pikeIncluded,pikeInclude,pikeDefine,pikeUserLabel,pikeSpecial,pikeOctalZero,pikeCppOutWrapper,pikeCppInWrapper,@pikeCppOutInGroup,pikeFormat,pikeNumber,pikeFloat,pikeOctal,pikeOctalError,pikeNumbersCom,pikeString,pikeMlString,pikeCommentSkip,pikeCommentString,pikeComment2String,@pikeCommentGroup,pikeCommentStartError,pikeFirstWord,pikeWord,pikeMappIndex,pikeEmbeddedString,pikeAutodocReal,pikeCommentL,pikeBindings,pikeBadClose,pikeTypeCast
syn region pikeDefine start="^\s*\zs#\s*\%(define\|undef\)\>" skip="\\$" end="$" keepend contains=ALLBUT,@pikePreProcGroup,@Spell
syn region pikePreProc start="^\s*\zs#\s*\%(pragma\|charset\|pike\|require\|string\|line\|warning\|error\)\>" skip="\\$" end="$" keepend contains=ALLBUT,@pikePreProcGroup,@Spell
syn cluster pikePreProcGroup contains=pikeIncluded,pikeInclude,pikeEmbeddedString,pikeAutodocReal,pikeUserLabel,pikeCppOutWrapper,pikeCppInWrapper,@pikeCppOutInGroup,pikeFormat,pikeMlString,pikeCommentStartError,pikeMappIndex,pikeBadClose,pikeWord
syn region pikeDefine start="^\s*\zs#\s*\%(define\|undef\)\>" skip="\\$" end="$" keepend contains=@pikeStmts,@pikeExpr,pikeBadClose
syn region pikePreProc start="^\s*\zs#\s*\%(pragma\|charset\|pike\|require\|string\|line\|warning\|error\)\>" skip="\\$" end="$" transparent keepend contains=pikeString,pikeCharacter,pikeNumbers,pikeCommentError,pikeSpaceError,pikeCppOperator,pikeCppPrefix,@Spell,pikeConstant

syn match pikeAutodocReal display contained "!.*" contains=@pikeAutodoc containedin=pikeComment,pikeCommentL

Expand All @@ -294,6 +295,7 @@ syn match pikeUserCont display "^\s*\zs\%(class\|enum\)\@!\I\i*\s*:[^:]"me=e-1 c
syn match pikeUserCont display ";\s*\zs\%(class\|enum\)\@!\I\i*\s*:[^:]"me=e-1 contains=@pikeLabelGroup

syn match pikeUserLabel display "\I\i*" contained
syn match pikeUserRLabel display "\%(\<\%(break\|continue\)\s\+\)\@10<=\I\i*" contained

syn match pikeMappIndex display contained "[^<()[\]{},;:]\+::\@!" contains=NONE
syn match pikeTypeCast display contained "\[[^,;\]]\+]" contains=NONE
Expand All @@ -311,56 +313,63 @@ exec "syn sync ccomment pikeComment minlines=" . b:c_minlines

" Define the default highlighting.
" Only used when an item doesn't have highlighting yet
hi def link pikeFormat pikeSpecial
hi def link pikeMlString pikeString
hi def link pikeCommentL pikeComment
hi def link pikeCommentStart pikeComment
hi def link pikeFormat SpecialChar
hi def link pikeMlString String
hi def link pikeCommentL Comment
hi def link pikeCommentStart Comment
hi def link pikeLabel Label
hi def link pikeUserLabel Label
hi def link pikeUserLabel Underlined
hi def link pikeUserRLabel Underlined
hi def link pikeConditional Conditional
hi def link pikeRepeat Repeat
hi def link pikeCharacter Character
hi def link pikeSpecialCharacter pikeSpecial
hi def link pikeDelimiterDQ Delimiter
hi def link pikeDelimiterSQ Delimiter
hi def link pikeSpecialCharacter SpecialChar
hi def link pikeNumber Number
hi def link pikeOctal Number
hi def link pikeOctalZero PreProc " link this to Error if you want
hi def link pikeFloat Float
hi def link pikeOctalError pikeError
hi def link pikeCommentError pikeError
hi def link pikeCommentStartError pikeError
hi def link pikeSpaceError pikeError
hi def link pikeSpecialError pikeError
hi def link pikeOctalError Error
hi def link pikeCommentError Error
hi def link pikeCommentStartError Error
hi def link pikeSpaceError Error
hi def link pikeSpecialError Error
hi def link pikeOperator Operator
hi def link pikeCppOperator Operator
hi def link pikeStructure Structure
hi def link pikeTypedef Typedef
hi def link pikeStorageClass StorageClass
hi def link pikeInclude Include
hi def link pikeCppPrefix PreCondit
hi def link pikePreProc PreProc
hi def link pikeDefine Macro
hi def link pikeIncluded pikeString
hi def link pikeIncluded String
hi def link pikeError Error
hi def link pikeDebug Debug
hi def link pikeException Exception
hi def link pikeStatement Statement
hi def link pikeCppInWrapper pikeCppOutWrapper
hi def link pikeCppOutWrapper pikePreCondit
hi def link pikePreConditMatch pikePreCondit
hi def link pikePreCondit PreCondit
hi def link pikeType Type
hi def link pikeConstant Constant
hi def link pikeBoolean Boolean
hi def link pikeCommentString pikeString
hi def link pikeComment2String pikeString
hi def link pikeCommentSkip pikeComment
hi def link pikeCommentString String
hi def link pikeComment2String String
hi def link pikeCommentSkip Comment
hi def link pikeString String
hi def link pikeComment Comment
hi def link pikeSpecial SpecialChar
hi def link pikeTodo Todo
hi def link pikeBadContinuation Error
hi def link pikeCppOutSkip pikeCppOutIf2
hi def link pikeCppInElse2 pikeCppOutIf2
hi def link pikeCppOutIf2 pikeCppOut

hi def link pikeCppInWrapper PreCondit
hi def link pikeCppOutWrapper PreCondit
hi def link pikePreConditMatch PreCondit

hi def link pikeCppOutSkip Comment
hi def link pikeCppInElse2 Comment
hi def link pikeCppOutIf2 Comment
hi def link pikeCppOut Comment

hi def link pikePredef Statement
hi def link pikeBindings Identifier
hi def link pikeMappIndex Identifier
Expand Down

0 comments on commit fd73e56

Please sign in to comment.