Moto vim syntax file

Stefano Corsi <[email protected]> Sun, 2 Feb 2003 11:57:39 +0000
Newsgroups gmane.comp.lang.moto.devel
Organization Moto Project
Message-ID <[email protected]>
Hello everybody,

for all vim enthusiasts, I have scrambled the vim java syntax file, put in 
some cpp processor syntax and some other language definition and what I got 
now is a very messed up vim moto syntax file that works quite well (at least 
with the moto file I have tried...), even if probably it has a lot of hidden 
bugs. However...it's just a syntax colorizer, and bugs in it can't be so 
dangerous.

If you want to use it you just put it in /usr/share/vim/vim61orwhatever/syntax 
and then modify /usr/share/vim/vim61orwhatever/filetype.vim and add:

" Moto
au BufNewFile,BufRead *.moto        setf moto

somewhere.

Stefano
moto.vim (text/plain, 17.8 KB)
" Vim syntax file
" Language:     Moto
" Author:   	(Originally for java ...) Claudio Fleiner <[email protected]>
" Maintainer:   (for Moto Language) Stefano Corsi <[email protected]>
" URL:          http://www.projectmoto.org
" Last Change:  2003 Feb 01

" Please check :help moto.vim for comments on some of the options available.

" Quit when a syntax file was already loaded
if !exists("main_syntax")
  if version < 600
    syntax clear
  elseif exists("b:current_syntax")
    finish
  endif
  " we define it here so that included files can test for it
  let main_syntax='moto'
endif

" don't use standard HiLink, it will not work with included syntax files
if version < 508
  command! -nargs=+ MotoHiLink hi link <args>
else
  command! -nargs=+ MotoHiLink hi def link <args>
endif

" some characters that cannot be in a moto program (outside a string)
syn match motoError "[\\@`]"
syn match motoError "<<<\|\.\.\|=>\|<>\|||=\|&&=\|[^-]->\|\*\/"

" use separate name so that it can be deleted in motocc.vim
syn match motoError2 "\|=<"
MotoHiLink motoError2 motoError

" This matches everything that has a starting $ ... 
" poorly but effectively matches macros, inline syntax and macro arguments... 
syn match motoMacro	"$\w*"

" keyword definitions
syn keyword motoExternal        import native package
syn keyword motoError           goto const
syn keyword motoConditional     if else switch
syn keyword motoRepeat          while for do
syn keyword motoBoolean         true false
syn keyword motoConstant        null
syn keyword motoTypedef         this super
syn keyword motoOperator        new instanceof
syn keyword motoType            boolean char byte short int long float double
syn keyword motoType            void
syn keyword motoStatement       return
syn keyword motoStorageClass    static synchronized transient volatile final strictfp serializable
syn keyword motoExceptions      throw try catch finally
syn keyword motoAssert          assert
syn keyword motoMethodDecl      synchronized throws
syn keyword motoClassDecl       extends implements interface
" to differentiate the keyword class from MyClass.class we use a match here
syn match   motoTypedef         "\.\s*\<class\>"ms=s+1
syn match   motoClassDecl       "^class\>"
syn match   motoClassDecl       "[^.]\s*\<class\>"ms=s+1
syn keyword motoBranch          break continue nextgroup=motoUserLabelRef skipwhite
syn match   motoUserLabelRef    "\k\+" contained
syn keyword motoScopeDecl       public protected private abstract

if exists("moto_highlight_moto_lang_ids") || exists("moto_highlight_moto_lang") || exists("moto_highlight_all")
  " moto.lang.*
  syn match motoLangClass "\<System\>"
  syn keyword motoLangClass  Cloneable Comparable Runnable Boolean Byte Class
  syn keyword motoLangClass  Character CharSequence ClassLoader Compiler Double Float
  syn keyword motoLangClass  Integer InheritableThreadLocal Long Math Number Object Package Process
  syn keyword motoLangClass  Runtime RuntimePermission InheritableThreadLocal
  syn keyword motoLangClass  SecurityManager Short String StrictMath StackTraceElement
  syn keyword motoLangClass  StringBuffer Thread ThreadGroup
  syn keyword motoLangClass  ThreadLocal Throwable Void ArithmeticException
  syn keyword motoLangClass  ArrayIndexOutOfBoundsException AssertionError
  syn keyword motoLangClass  ArrayStoreException ClassCastException
  syn keyword motoLangClass  ClassNotFoundException
  syn keyword motoLangClass  CloneNotSupportedException Exception
  syn keyword motoLangClass  IllegalAccessException
  syn keyword motoLangClass  IllegalArgumentException
  syn keyword motoLangClass  IllegalMonitorStateException
  syn keyword motoLangClass  IllegalStateException
  syn keyword motoLangClass  IllegalThreadStateException
  syn keyword motoLangClass  IndexOutOfBoundsException
  syn keyword motoLangClass  InstantiationException InterruptedException
  syn keyword motoLangClass  NegativeArraySizeException NoSuchFieldException
  syn keyword motoLangClass  NoSuchMethodException NullPointerException
  syn keyword motoLangClass  NumberFormatException RuntimeException
  syn keyword motoLangClass  SecurityException StringIndexOutOfBoundsException
  syn keyword motoLangClass  UnsupportedOperationException
  syn keyword motoLangClass  AbstractMethodError ClassCircularityError
  syn keyword motoLangClass  ClassFormatError Error ExceptionInInitializerError
  syn keyword motoLangClass  IllegalAccessError InstantiationError
  syn keyword motoLangClass  IncompatibleClassChangeError InternalError
  syn keyword motoLangClass  LinkageError NoClassDefFoundError
  syn keyword motoLangClass  NoSuchFieldError NoSuchMethodError
  syn keyword motoLangClass  OutOfMemoryError StackOverflowError
  syn keyword motoLangClass  ThreadDeath UnknownError UnsatisfiedLinkError
  syn keyword motoLangClass  UnsupportedClassVersionError VerifyError
  syn keyword motoLangClass  VirtualMachineError
  syn keyword motoLangObject clone equals finalize getClass hashCode
  syn keyword motoLangObject notify notifyAll toString wait
  MotoHiLink motoLangClass                   motoConstant
  MotoHiLink motoLangObject                  motoConstant
  syn cluster motoTop add=motoLangObject,motoLangClass
  syn cluster motoClasses add=motoLangClass
endif

if filereadable(expand("<sfile>:p:h")."/motoid.vim")
  source <sfile>:p:h/motoid.vim
endif

if exists("moto_space_errors")
  if !exists("moto_no_trail_space_error")
    syn match   motoSpaceError  "\s\+$"
  endif
  if !exists("moto_no_tab_space_error")
    syn match   motoSpaceError  " \+\t"me=e-1
  endif
endif

syn region  motoLabelRegion     transparent matchgroup=motoLabel start="\<case\>" matchgroup=NONE end=":" contains=motoNumber,motoCharacter
syn match   motoUserLabel       "^\s*[_$a-zA-Z][_$a-zA-Z0-9_]*\s*:"he=e-1 contains=motoLabel
syn keyword motoLabel           default

if !exists("moto_allow_cpp_keywords")
  syn keyword motoError auto delete enum extern friend inline redeclared
  syn keyword motoError register signed sizeof struct template typedef union
  syn keyword motoError unsigned operator
endif

" The following cluster contains all moto groups except the contained ones
syn cluster motoTop add=motoExternal,motoError,motoError,motoBranch,motoLabelRegion,motoLabel,motoConditional,motoRepeat,motoBoolean,motoConstant,motoTypedef,motoOperator,motoType,motoType,motoStatement,motoStorageClass,motoAssert,motoExceptions,motoMethodDecl,motoClassDecl,motoClassDecl,motoClassDecl,motoScopeDecl,motoError,motoError2,motoUserLabel,motoLangObject

" Preprocessor
syn region	motoPreCondit	start="^\s*#\s*\(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" end="//"me=s-1 contains=motoComment,motoCppString,motoCharacter,motoCppParen,motoParenError,motoNumbers,motoCommentError,motoSpaceError
syn match	motoPreCondit	display "^\s*#\s*\(else\|endif\)\>"
if !exists("c_no_if0")
  syn region	motoCppOut		start="^\s*#\s*if\s\+0\+\>" end=".\|$" contains=motoCppOut2
  syn region	motoCppOut2	contained start="0" end="^\s*#\s*\(endif\>\|else\>\|elif\>\)" contains=motoSpaceError,motoCppSkip
  syn region	motoCppSkip	contained start="^\s*#\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*#\s*endif\>" contains=motoSpaceError,motoCppSkip
endif
syn region	motoIncluded	display contained start=+"+ skip=+\\\\\|\\"+ end=+"+
syn match	motoIncluded	display contained "([^)]*)" contains=motoString
syn match	motoInclude	display "^\s*#\s*include\>\s*["(]" contains=motoIncluded
"syn match motoLineSkip	"\\$"
syn match	motoReaddefs	display "^\s*#\s*readdefs\>\s*["(]" contains=motoIncluded
syn cluster	motoPrePromotoGroup	contains=motoPreCondit,motoIncluded,motoInclude,motoDefine,motoErrInParen,motoErrInBracket,motoUserLabel,motoSpecial,motoOctalZero,motoCppOut,motoCppOut2,motoCppSkip,motoFormat,motoNumber,motoFloat,motoOctal,motoOctalError,motoNumbersCom,motoString,motoCommentSkip,motoCommentString,motoComment2String,@motoCommentGroup,motoCommentStartError,motoParen,motoBracket,motoMulti
syn region	motoDefine		start="^\s*#\s*\(define\|undef\)\>" skip="\\$" end="$" end="//"me=s-1 contains=ALLBUT,@motoPrePromotoGroup
syn region	motoPreProc	start="^\s*#\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend contains=ALLBUT,@motoPrePromotoGroup

" Comments
syn keyword motoTodo             contained TODO FIXME XXX
if exists("moto_comment_strings")
  syn region  motoCommentString    contained start=+"+ end=+"+ end=+$+ end=+\*/+me=s-1,he=s-1 contains=motoSpecial,motoCommentStar,motoSpecialChar,@Spell
  syn region  motoComment2String   contained start=+"+  end=+$\|"+  contains=motoSpecial,motoSpecialChar,@Spell
  syn match   motoCommentCharacter contained "'\\[^']\{1,6\}'" contains=motoSpecialChar
  syn match   motoCommentCharacter contained "'\\''" contains=motoSpecialChar
  syn match   motoCommentCharacter contained "'[^\\]'"
  syn cluster motoCommentSpecial add=motoCommentString,motoCommentCharacter,motoNumber
  syn cluster motoCommentSpecial2 add=motoComment2String,motoCommentCharacter,motoNumber
endif
" syn region  motoComment          start="/\*"  end="\*/" contains=@motoCommentSpecial,motoTodo,@Spell
syn region  motoInlineComment          start="\$\*"  end="\*\$" contains=@motoCommentSpecial,motoTodo,@Spell
" syn match   motoCommentStar      contained "^\s*\*[^/]"me=e-1
" syn match   motoCommentStar      contained "^\s*\*$"
syn match   motoLineComment      "//.*" contains=@motoCommentSpecial2,motoTodo,@Spell
MotoHiLink motoCommentString motoString
MotoHiLink motoComment2String motoString
MotoHiLink motoCommentCharacter motoCharacter

syn cluster motoTop add=motoComment,motoLineComment

if !exists("moto_ignore_motodoc") && main_syntax != 'jsp'
  syntax case ignore
  " syntax coloring for motodoc comments (HTML)
  syntax include @motoHtml <sfile>:p:h/html.vim
  unlet b:current_syntax
  syn region  motoDocComment    start="/\*\*"  end="\*/" keepend contains=motoCommentTitle,@motoHtml,motoDocTags,motoTodo,@Spell
  syn region  motoCommentTitle  contained matchgroup=motoDocComment start="/\*\*"   matchgroup=motoCommentTitle keepend end="\.$" end="\.[ \t\r<&]"me=e-1 end="@"me=s-1,he=s-1 end="\*/"me=s-1,he=s-1 contains=@motoHtml,motoCommentStar,motoTodo,@Spell

  syn region motoDocTags  contained start="{@link" end="}"
  syn match  motoDocTags  contained "@\(see\|param\|exception\|throws\)\s\+\S\+" contains=motoDocParam
  syn match  motoDocParam contained "\s\S\+"
  syn match  motoDocTags  contained "@\(version\|author\|return\|deprecated\|since\)\>"
  syntax case match
endif

" match the special comment /**/
" syn match   motoComment          "/\*\*/"
syn match   motoInlineComment          "$\*\*$"

" Strings and constants
syn match   motoSpecialError     contained "\\."
syn match   motoSpecialCharError contained "[^']"
syn match   motoSpecialChar      contained "\\\([4-9]\d\|[0-3]\d\d\|[\"\\'ntbrf]\|u\x\{4\}\)"
syn region  motoString          start=+"+ end=+"+ end=+$+ contains=motoSpecialChar,motoSpecialError,@Spell
" next line disabled, it can cause a crash for a long line
"syn match   motoStringError      +"\([^"\\]\|\\.\)*$+
syn match   motoCharacter        "'[^']*'" contains=motoSpecialChar,motoSpecialCharError
syn match   motoCharacter        "'\\''" contains=motoSpecialChar
syn match   motoCharacter        "'[^\\]'"
syn match   motoNumber           "\<\(0[0-7]*\|0[xX]\x\+\|\d\+\)[lL]\=\>"
syn match   motoNumber           "\(\<\d\+\.\d*\|\.\d\+\)\([eE][-+]\=\d\+\)\=[fFdD]\="
syn match   motoNumber           "\<\d\+[eE][-+]\=\d\+[fFdD]\=\>"
syn match   motoNumber           "\<\d\+\([eE][-+]\=\d\+\)\=[fFdD]\>"

" unicode characters
syn match   motoSpecial "\\u\d\{4\}"

syn cluster motoTop add=motoString,motoCharacter,motoNumber,motoSpecial,motoStringError

if exists("moto_highlight_functions")
  if moto_highlight_functions == "indent"
    syn match  motoFuncDef "^\(\t\| \{8\}\)[_$a-zA-Z][_$a-zA-Z0-9_. \[\]]*([^-+*/()]*)" contains=motoScopeDecl,motoType,motoStorageClass,@motoClasses
    syn region motoFuncDef start=+^\(\t\| \{8\}\)[$_a-zA-Z][$_a-zA-Z0-9_. \[\]]*([^-+*/()]*,\s*+ end=+)+ contains=motoScopeDecl,motoType,motoStorageClass,@motoClasses
    syn match  motoFuncDef "^  [$_a-zA-Z][$_a-zA-Z0-9_. \[\]]*([^-+*/()]*)" contains=motoScopeDecl,motoType,motoStorageClass,@motoClasses
    syn region motoFuncDef start=+^  [$_a-zA-Z][$_a-zA-Z0-9_. \[\]]*([^-+*/()]*,\s*+ end=+)+ contains=motoScopeDecl,motoType,motoStorageClass,@motoClasses
  else
    " This line catches method declarations at any indentation>0, but it assumes
    " two things:
    "   1. class names are always capitalized (ie: Button)
    "   2. method names are never capitalized (except constructors, of course)
    syn region motoFuncDef start=+^\s\+\(\(public\|protected\|private\|static\|abstract\|final\|native\|synchronized\)\s\+\)*\(\(void\|boolean\|char\|byte\|short\|int\|long\|float\|double\|\([A-Za-z_][A-Za-z0-9_$]*\.\)*[A-Z][A-Za-z0-9_$]*\)\(\[\]\)*\s\+[a-z][A-Za-z0-9_$]*\|[A-Z][A-Za-z0-9_$]*\)\s*(+ end=+)+ contains=motoScopeDecl,motoType,motoStorageClass,motoComment,motoLineComment,@motoClasses
  endif
  syn match  motoBraces  "[{}]"
  syn cluster motoTop add=motoFuncDef,motoBraces
endif

if exists("moto_highlight_debug")

  " Strings and constants
  syn match   motoDebugSpecial          contained "\\\d\d\d\|\\."
  syn region  motoDebugString           contained start=+"+  end=+"+  contains=motoDebugSpecial
  syn match   motoDebugStringError      +"\([^"\\]\|\\.\)*$+
  syn match   motoDebugCharacter        contained "'[^\\]'"
  syn match   motoDebugSpecialCharacter contained "'\\.'"
  syn match   motoDebugSpecialCharacter contained "'\\''"
  syn match   motoDebugNumber           contained "\<\(0[0-7]*\|0[xX]\x\+\|\d\+\)[lL]\=\>"
  syn match   motoDebugNumber           contained "\(\<\d\+\.\d*\|\.\d\+\)\([eE][-+]\=\d\+\)\=[fFdD]\="
  syn match   motoDebugNumber           contained "\<\d\+[eE][-+]\=\d\+[fFdD]\=\>"
  syn match   motoDebugNumber           contained "\<\d\+\([eE][-+]\=\d\+\)\=[fFdD]\>"
  syn keyword motoDebugBoolean          contained true false
  syn keyword motoDebugType             contained null this super
  syn region motoDebugParen  start=+(+ end=+)+ contained contains=motoDebug.*,motoDebugParen

  " to make this work you must define the highlighting for these groups
  syn match motoDebug "System\.\(out\|err\)\.print\(ln\)*\s*("me=e-1 contains=motoDebug.* nextgroup=motoDebugParen
  syn match motoDebug "[A-Za-z][a-zA-Z0-9_]*\.printStackTrace\s*("me=e-1 contains=motoDebug.* nextgroup=motoDebugParen
  syn match motoDebug "\<trace[SL]\=\s*("me=e-1 contains=motoDebug.* nextgroup=motoDebugParen

  syn cluster motoTop add=motoDebug

  if version >= 508 || !exists("did_c_syn_inits")
    MotoHiLink motoDebug                 Debug
    MotoHiLink motoDebugString           DebugString
    MotoHiLink motoDebugStringError      motoError
    MotoHiLink motoDebugType             DebugType
    MotoHiLink motoDebugBoolean          DebugBoolean
    MotoHiLink motoDebugNumber           Debug
    MotoHiLink motoDebugSpecial          DebugSpecial
    MotoHiLink motoDebugSpecialCharacter DebugSpecial
    MotoHiLink motoDebugCharacter        DebugString
    MotoHiLink motoDebugParen            Debug

    MotoHiLink DebugString               String
    MotoHiLink DebugSpecial              Special
    MotoHiLink DebugBoolean              Boolean
    MotoHiLink DebugType                 Type
  endif
endif

if exists("moto_mark_braces_in_parens_as_errors")
  syn match motoInParen          contained "[{}]"
  MotoHiLink motoInParen        motoError
  syn cluster motoTop add=motoInParen
endif

" catch errors caused by wrong parenthesis
syn region  motoParen  matchgroup=motoParen  transparent start="(" end=")" contains=@motoTop,motoParen1
syn region  motoParen1 matchgroup=motoParen1 transparent start="(" end=")" contains=@motoTop,motoParen2 contained
syn region  motoParen2 matchgroup=motoParen2 transparent start="(" end=")" contains=@motoTop,motoParen  contained
syn match   motoParenError       ")"
MotoHiLink motoParenError       motoError

if !exists("moto_minlines")
  let moto_minlines = 10
endif
exec "syn sync ccomment motoComment minlines=" . moto_minlines

" The default highlighting.
if version >= 508 || !exists("did_moto_syn_inits")
  if version < 508
    let did_moto_syn_inits = 1
  endif
  MotoHiLink motoFuncDef		Function
  MotoHiLink motoBraces			Function
  MotoHiLink motoBranch			Conditional
  MotoHiLink motoUserLabelRef		motoUserLabel
  MotoHiLink motoLabel			Label
  MotoHiLink motoUserLabel		Label
  MotoHiLink motoConditional		Conditional
  MotoHiLink motoRepeat			Repeat
  MotoHiLink motoExceptions		Exception
  MotoHiLink motoAssert			Statement
  MotoHiLink motoStorageClass		StorageClass
  MotoHiLink motoMethodDecl		motoStorageClass
  MotoHiLink motoClassDecl		motoStorageClass
  MotoHiLink motoScopeDecl		motoStorageClass
  MotoHiLink motoBoolean		Boolean
  MotoHiLink motoSpecial		Special
  MotoHiLink motoSpecialError		Error
  MotoHiLink motoSpecialCharError	Error
  MotoHiLink motoString			String
  MotoHiLink motoCharacter		Character
  MotoHiLink motoSpecialChar		SpecialChar
  MotoHiLink motoNumber			Number
  MotoHiLink motoError			Error
  MotoHiLink motoStringError		Error
  MotoHiLink motoStatement		Statement
  MotoHiLink motoOperator		Operator
  MotoHiLink motoComment		Comment
  MotoHiLink motoInlineComment		Comment
  MotoHiLink motoDocComment		Comment
  MotoHiLink motoLineComment		Comment
  MotoHiLink motoConstant		Constant
  MotoHiLink motoTypedef		Typedef
  MotoHiLink motoTodo			Todo

  MotoHiLink motoCommentTitle		SpecialComment
  MotoHiLink motoDocTags		Special
  MotoHiLink motoDocParam		Function
  MotoHiLink motoCommentStar		motoComment

  MotoHiLink motoType			Type
  MotoHiLink motoExternal		Include


  MotoHiLink htmlComment		Special
  MotoHiLink htmlCommentPart		Special
  MotoHiLink motoSpaceError		Error

" Preprocesor and macros
  MotoHiLink motoReaddefs		Macro
  MotoHiLink motoInclude		Macro
  MotoHiLink motoMacro			Identifier
endif

delcommand MotoHiLink

let b:current_syntax = "moto"

if main_syntax == 'moto'
  unlet main_syntax
endif

let b:spell_options="contained"

" vim: ts=8