pim.vim (15119B)
1 " Vim syntax file 2 " Language: Modula-2 (PIM) 3 " Maintainer: B.Kowarsch <trijezdci@moc.liamg> 4 " Last Change: 2016 August 22 5 6 " ---------------------------------------------------- 7 " THIS FILE IS LICENSED UNDER THE VIM LICENSE 8 " see https://github.com/vim/vim/blob/master/LICENSE 9 " ---------------------------------------------------- 10 11 " Remarks: 12 " Vim Syntax files are available for the following Modula-2 dialects: 13 " * for the PIM dialect : m2pim.vim (this file) 14 " * for the ISO dialect : m2iso.vim 15 " * for the R10 dialect : m2r10.vim 16 17 " ----------------------------------------------------------------------------- 18 " This syntax description follows the 3rd and 4th editions of N.Wirth's Book 19 " Programming in Modula-2 (aka PIM) plus the following language extensions: 20 " * non-leading, non-trailing, non-consecutive lowlines _ in identifiers 21 " * widely supported non-standard types BYTE, LONGCARD and LONGBITSET 22 " * non-nesting code disabling tags ?< and >? at the start of a line 23 " ----------------------------------------------------------------------------- 24 25 " Parameters: 26 " 27 " Vim's filetype script recognises Modula-2 dialect tags within the first 200 28 " lines of Modula-2 .def and .mod input files. The script sets filetype and 29 " dialect automatically when a valid dialect tag is found in the input file. 30 " The dialect tag for the PIM dialect is (*!m2pim*). It is recommended to put 31 " the tag immediately after the module header in the Modula-2 input file. 32 " 33 " Example: 34 " DEFINITION MODULE Foolib; (*!m2pim*) 35 " 36 " Variable g:modula2_default_dialect sets the default Modula-2 dialect when the 37 " dialect cannot be determined from the contents of the Modula-2 input file: 38 " if defined and set to 'm2pim', the default dialect is PIM. 39 " 40 " Variable g:modula2_pim_allow_lowline controls support for lowline in identifiers: 41 " if defined and set to a non-zero value, they are recognised, otherwise not 42 " 43 " Variable g:modula2_pim_disallow_octals controls the rendering of octal literals: 44 " if defined and set to a non-zero value, they are rendered as errors. 45 " 46 " Variable g:modula2_pim_disallow_synonyms controls the rendering of & and ~: 47 " if defined and set to a non-zero value, they are rendered as errors. 48 " 49 " Variables may be defined in Vim startup file .vimrc 50 " 51 " Examples: 52 " let g:modula2_default_dialect = 'm2pim' 53 " let g:modula2_pim_allow_lowline = 1 54 " let g:modula2_pim_disallow_octals = 1 55 " let g:modula2_pim_disallow_synonyms = 1 56 57 58 if exists("b:current_syntax") 59 finish 60 endif 61 62 " Modula-2 is case sensitive 63 syn case match 64 65 66 " ----------------------------------------------------------------------------- 67 " Reserved Words 68 " ----------------------------------------------------------------------------- 69 syn keyword modula2Resword AND ARRAY BEGIN BY CASE CONST DEFINITION DIV DO ELSE 70 syn keyword modula2Resword ELSIF EXIT EXPORT FOR FROM IF IMPLEMENTATION IMPORT 71 syn keyword modula2Resword IN LOOP MOD NOT OF OR POINTER QUALIFIED RECORD REPEAT 72 syn keyword modula2Resword RETURN SET THEN TO TYPE UNTIL VAR WHILE WITH 73 74 75 " ----------------------------------------------------------------------------- 76 " Builtin Constant Identifiers 77 " ----------------------------------------------------------------------------- 78 syn keyword modula2ConstIdent FALSE NIL TRUE 79 80 81 " ----------------------------------------------------------------------------- 82 " Builtin Type Identifiers 83 " ----------------------------------------------------------------------------- 84 syn keyword modula2TypeIdent BITSET BOOLEAN CHAR PROC 85 syn keyword modula2TypeIdent CARDINAL INTEGER LONGINT REAL LONGREAL 86 87 88 " ----------------------------------------------------------------------------- 89 " Builtin Procedure and Function Identifiers 90 " ----------------------------------------------------------------------------- 91 syn keyword modula2ProcIdent CAP DEC EXCL HALT INC INCL 92 syn keyword modula2FuncIdent ABS CHR FLOAT HIGH MAX MIN ODD ORD SIZE TRUNC VAL 93 94 95 " ----------------------------------------------------------------------------- 96 " Wirthian Macro Identifiers 97 " ----------------------------------------------------------------------------- 98 syn keyword modula2MacroIdent NEW DISPOSE 99 100 101 " ----------------------------------------------------------------------------- 102 " Unsafe Facilities via Pseudo-Module SYSTEM 103 " ----------------------------------------------------------------------------- 104 syn keyword modula2UnsafeIdent ADDRESS PROCESS WORD 105 syn keyword modula2UnsafeIdent ADR TSIZE NEWPROCESS TRANSFER SYSTEM 106 107 108 " ----------------------------------------------------------------------------- 109 " Non-Portable Language Extensions 110 " ----------------------------------------------------------------------------- 111 syn keyword modula2NonPortableIdent BYTE LONGCARD LONGBITSET 112 113 114 " ----------------------------------------------------------------------------- 115 " User Defined Identifiers 116 " ----------------------------------------------------------------------------- 117 syn match modula2Ident "[a-zA-Z][a-zA-Z0-9]*\(_\)\@!" 118 syn match modula2LowLineIdent "[a-zA-Z][a-zA-Z0-9]*\(_[a-zA-Z0-9]\+\)\+" 119 120 121 " ----------------------------------------------------------------------------- 122 " String Literals 123 " ----------------------------------------------------------------------------- 124 syn region modula2String start=/"/ end=/"/ oneline 125 syn region modula2String start=/'/ end=/'/ oneline 126 127 128 " ----------------------------------------------------------------------------- 129 " Numeric Literals 130 " ----------------------------------------------------------------------------- 131 syn match modula2Num 132 \ "\(\([0-7]\+\)[BC]\@!\|[89]\)[0-9]*\(\.[0-9]\+\([eE][+-]\?[0-9]\+\)\?\)\?" 133 syn match modula2Num "[0-9A-F]\+H" 134 syn match modula2Octal "[0-7]\+[BC]" 135 136 137 " ----------------------------------------------------------------------------- 138 " Punctuation 139 " ----------------------------------------------------------------------------- 140 syn match modula2Punctuation 141 \ "\.\|[,:;]\|\*\|[/+-]\|\#\|[=<>]\|\^\|\[\|\]\|(\(\*\)\@!\|[){}]" 142 syn match modula2Synonym "[&~]" 143 144 145 " ----------------------------------------------------------------------------- 146 " Pragmas 147 " ----------------------------------------------------------------------------- 148 syn region modula2Pragma start="(\*\$" end="\*)" 149 syn match modula2DialectTag "(\*!m2pim\(+[a-z0-9]\+\)\?\*)" 150 151 " ----------------------------------------------------------------------------- 152 " Block Comments 153 " ----------------------------------------------------------------------------- 154 syn region modula2Comment start="(\*\(\$\|!m2pim\(+[a-z0-9]\+\)\?\*)\)\@!" end="\*)" 155 \ contains = modula2Comment, modula2CommentKey, modula2TechDebtMarker 156 syn match modula2CommentKey "[Aa]uthor[s]\?\|[Cc]opyright\|[Ll]icense\|[Ss]ynopsis" 157 syn match modula2CommentKey "\([Pp]re\|[Pp]ost\|[Ee]rror\)\-condition[s]\?:" 158 159 160 " ----------------------------------------------------------------------------- 161 " Technical Debt Markers 162 " ----------------------------------------------------------------------------- 163 syn keyword modula2TechDebtMarker contained DEPRECATED FIXME 164 syn match modula2TechDebtMarker "TODO[:]\?" contained 165 166 " ----------------------------------------------------------------------------- 167 " Disabled Code Sections 168 " ----------------------------------------------------------------------------- 169 syn region modula2DisabledCode start="^?<" end="^>?" 170 171 172 " ----------------------------------------------------------------------------- 173 " Headers 174 " ----------------------------------------------------------------------------- 175 " !!! this section must be second last !!! 176 177 " new module header 178 syn match modula2ModuleHeader 179 \ "MODULE\( [A-Z][a-zA-Z0-9]*\)\?" 180 \ contains = modula2ReswordModule, modula2ModuleIdent 181 182 syn match modula2ModuleIdent 183 \ "[A-Z][a-zA-Z0-9]*" contained 184 185 syn match modula2ModuleTail 186 \ "END [A-Z][a-zA-Z0-9]*\.$" 187 \ contains = modula2ReswordEnd, modula2ModuleIdent, modula2Punctuation 188 189 " new procedure header 190 syn match modula2ProcedureHeader 191 \ "PROCEDURE\( [a-zA-Z][a-zA-Z0-9]*\(_[a-zA-Z0-9]\+\)*\)\?" 192 \ contains = modula2ReswordProcedure, 193 \ modula2ProcedureIdent, modula2ProcedureLowlineIdent, modula2IllegalChar, modula2IllegalIdent 194 195 syn match modula2ProcedureIdent 196 \ "\([a-zA-Z]\)\([a-zA-Z0-9]*\)" contained 197 198 syn match modula2ProcedureLowlineIdent 199 \ "[a-zA-Z][a-zA-Z0-9]*\(_[a-zA-Z0-9]\+\)\+" contained 200 201 syn match modula2ProcedureTail 202 \ "END\( \([a-zA-Z][a-zA-Z0-9]*\(_[a-zA-Z0-9]\+\)*\)[.;]$\)\?" 203 \ contains = modula2ReswordEnd, 204 \ modula2ProcedureIdent, modula2ProcedureLowLineIdent, 205 \ modula2Punctuation, modula2IllegalChar, modula2IllegalIdent 206 207 syn keyword modula2ReswordModule contained MODULE 208 syn keyword modula2ReswordProcedure contained PROCEDURE 209 syn keyword modula2ReswordEnd contained END 210 211 212 " ----------------------------------------------------------------------------- 213 " Illegal Symbols 214 " ----------------------------------------------------------------------------- 215 " !!! this section must be last !!! 216 217 " any '`' '!' '@ ''$' '%' or '\' 218 syn match modula2IllegalChar "[`!@$%\\]" 219 220 " any solitary sequence of '_' 221 syn match modula2IllegalChar "\<_\+\>" 222 223 " any '?' at start of line if not followed by '<' 224 syn match modula2IllegalChar "^?\(<\)\@!" 225 226 " any '?' not following '>' at start of line 227 syn match modula2IllegalChar "\(\(^>\)\|\(^\)\)\@<!?" 228 229 " any identifiers with leading occurrences of '_' 230 syn match modula2IllegalIdent "_\+[a-zA-Z][a-zA-Z0-9]*\(_\+[a-zA-Z0-9]*\)*" 231 232 " any identifiers containing consecutive occurences of '_' 233 syn match modula2IllegalIdent 234 \ "[a-zA-Z][a-zA-Z0-9]*\(_[a-zA-Z0-9]\+\)*\(__\+[a-zA-Z0-9]\+\(_[a-zA-Z0-9]\+\)*\)\+" 235 236 " any identifiers with trailing occurrences of '_' 237 syn match modula2IllegalIdent "[a-zA-Z][a-zA-Z0-9]*\(_\+[a-zA-Z0-9]\+\)*_\+\>" 238 239 240 " ----------------------------------------------------------------------------- 241 " Define Rendering Styles 242 " ----------------------------------------------------------------------------- 243 244 " highlight default link modula2PredefIdentStyle Keyword 245 " highlight default link modula2ConstIdentStyle modula2PredefIdentStyle 246 " highlight default link modula2TypeIdentStyle modula2PredefIdentStyle 247 " highlight default link modula2ProcIdentStyle modula2PredefIdentStyle 248 " highlight default link modula2FuncIdentStyle modula2PredefIdentStyle 249 " highlight default link modula2MacroIdentStyle modula2PredefIdentStyle 250 251 highlight default link modula2ConstIdentStyle Constant 252 highlight default link modula2TypeIdentStyle Type 253 highlight default link modula2ProcIdentStyle Function 254 highlight default link modula2FuncIdentStyle Function 255 highlight default link modula2MacroIdentStyle Function 256 highlight default link modula2UnsafeIdentStyle Question 257 highlight default link modula2NonPortableIdentStyle Question 258 highlight default link modula2StringLiteralStyle String 259 highlight default link modula2CommentStyle Comment 260 highlight default link modula2PragmaStyle PreProc 261 highlight default link modula2DialectTagStyle SpecialComment 262 highlight default link modula2TechDebtMarkerStyle SpecialComment 263 highlight default link modula2ReswordStyle Keyword 264 highlight default link modula2HeaderIdentStyle Function 265 highlight default link modula2UserDefIdentStyle Normal 266 highlight default link modula2NumericLiteralStyle Number 267 highlight default link modula2PunctuationStyle Delimiter 268 highlight default link modula2CommentKeyStyle SpecialComment 269 highlight default link modula2DisabledCodeStyle NonText 270 271 " ----------------------------------------------------------------------------- 272 " Assign Rendering Styles 273 " ----------------------------------------------------------------------------- 274 275 " headers 276 highlight default link modula2ModuleIdent modula2HeaderIdentStyle 277 highlight default link modula2ProcedureIdent modula2HeaderIdentStyle 278 highlight default link modula2ModuleHeader Normal 279 highlight default link modula2ModuleTail Normal 280 highlight default link modula2ProcedureHeader Normal 281 highlight default link modula2ProcedureTail Normal 282 283 " lowline identifiers are rendered as errors if g:modula2_pim_allow_lowline is unset 284 if exists("g:modula2_pim_allow_lowline") 285 if g:modula2_pim_allow_lowline != 0 286 highlight default link modula2ProcedureLowlineIdent modula2HeaderIdentStyle 287 else 288 highlight default link modula2ProcedureLowlineIdent Error 289 endif 290 else 291 highlight default link modula2ProcedureLowlineIdent Error 292 endif 293 294 " reserved words 295 highlight default link modula2Resword modula2ReswordStyle 296 highlight default link modula2ReswordModule modula2ReswordStyle 297 highlight default link modula2ReswordProcedure modula2ReswordStyle 298 highlight default link modula2ReswordEnd modula2ReswordStyle 299 300 " predefined identifiers 301 highlight default link modula2ConstIdent modula2ConstIdentStyle 302 highlight default link modula2TypeIdent modula2TypeIdentStyle 303 highlight default link modula2ProcIdent modula2ProcIdentStyle 304 highlight default link modula2FuncIdent modula2FuncIdentStyle 305 highlight default link modula2MacroIdent modula2MacroIdentStyle 306 307 " unsafe and non-portable identifiers 308 highlight default link modula2UnsafeIdent modula2UnsafeIdentStyle 309 highlight default link modula2NonPortableIdent modula2NonPortableIdentStyle 310 311 " user defined identifiers 312 highlight default link modula2Ident modula2UserDefIdentStyle 313 314 " lowline identifiers are rendered as errors if g:modula2_pim_allow_lowline is unset 315 if exists("g:modula2_pim_allow_lowline") 316 if g:modula2_pim_allow_lowline != 0 317 highlight default link modula2LowLineIdent modula2UserDefIdentStyle 318 else 319 highlight default link modula2LowLineIdent Error 320 endif 321 else 322 highlight default link modula2LowLineIdent Error 323 endif 324 325 " literals 326 highlight default link modula2String modula2StringLiteralStyle 327 highlight default link modula2Num modula2NumericLiteralStyle 328 329 " octal literals are rendered as errors if g:modula2_pim_disallow_octals is set 330 if exists("g:modula2_pim_disallow_octals") 331 if g:modula2_pim_disallow_octals != 0 332 highlight default link modula2Octal Error 333 else 334 highlight default link modula2Octal modula2NumericLiteralStyle 335 endif 336 else 337 highlight default link modula2Octal modula2NumericLiteralStyle 338 endif 339 340 " punctuation 341 highlight default link modula2Punctuation modula2PunctuationStyle 342 343 " synonyms & and ~ are rendered as errors if g:modula2_pim_disallow_synonyms is set 344 if exists("g:modula2_pim_disallow_synonyms") 345 if g:modula2_pim_disallow_synonyms != 0 346 highlight default link modula2Synonym Error 347 else 348 highlight default link modula2Synonym modula2PunctuationStyle 349 endif 350 else 351 highlight default link modula2Synonym modula2PunctuationStyle 352 endif 353 354 " pragmas 355 highlight default link modula2Pragma modula2PragmaStyle 356 highlight default link modula2DialectTag modula2DialectTagStyle 357 358 " comments 359 highlight default link modula2Comment modula2CommentStyle 360 highlight default link modula2CommentKey modula2CommentKeyStyle 361 362 " technical debt markers 363 highlight default link modula2TechDebtMarker modula2TechDebtMarkerStyle 364 365 " disabled code 366 highlight default link modula2DisabledCode modula2DisabledCodeStyle 367 368 " illegal symbols 369 highlight default link modula2IllegalChar Error 370 highlight default link modula2IllegalIdent Error 371 372 373 let b:current_syntax = "modula2" 374 375 " vim: ts=4 376 377 " END OF FILE